Skip to content

Commit

Permalink
✨ Adds support for custom field splitting in auto-generated selects
Browse files Browse the repository at this point in the history
Squashing: Co-Authored-by: Philip Cooksey <[email protected]>
Compressing @mhaeussermann keyword filter work into the new
attribute bibtex_split_by for auto-generated selects.

The functionality needed for the non-standard "keywords" bibtex field is
that it should be split up with commas rather than taken as a
whole. This can be accomplished by adding an attribute to the select that
splits the string as @mhaeussermann had done. Adding an array in the
else statement allows up to have both the default and extended split
functionality without adding too much in terms of if statements.

Removing extra html file and combining it with the previously made
auto generate select page. Tests will come in the next commit
  • Loading branch information
mhaeussermann authored and pcooksey committed Apr 11, 2020
1 parent 06728f8 commit 9034073
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/bibtex_js.js
Original file line number Diff line number Diff line change
Expand Up @@ -1220,11 +1220,16 @@ function generateList(object, bibtexField) {
}
} else {
$(".bibtexentry span." + bibtexField).each(function(i, obj) {
arrayString = $(this).text();
if (arrayString in map) {
map[arrayString] += 1;
} else {
map[arrayString] = 1;
arrayString = [$(this).text()];
if (object[0].hasAttribute("bibtex_split_by")) {
arrayString = arrayString[0].split(object.attr("bibtex_split_by"));
}
for (i = 0; i < arrayString.length; ++i) {
if (arrayString[i] in map) {
map[arrayString[i]] += 1;
} else {
map[arrayString[i]] = 1;
}
}
});
for (var key in map) {
Expand Down
11 changes: 11 additions & 0 deletions test/html/autogenerateselects.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,30 @@
author = "John Smith",
title = "The First Book",
year = "2000",
keywords = "Computer, Algorithm"
},
@book{book2,
author = "John Smith",
title = "The Second Book",
year = "2001",
keywords = "Religion"
},
@article{article1,
author = "Last, Jr., Bob",
title = "Another Title",
year = "2011",
keywords = "Algorithm, Supercomputer"
},
@article{article2,
author = "M. Night",
title = "Okay",
keywords = "Politics, Computer, Democracy"
},
@inproceedings{proceedings1,
author = "Steven Man and Tim Bloke",
title = "The best",
year = "1990",
keywords = "Religion, Computer, Algorithm, Chess, Society"
}
</textarea>

Expand Down Expand Up @@ -76,6 +81,11 @@ <h1> Auto-Fill Selects Test File</h1>
<option value="">Search BibTeX Type</option>
</select>

<select class="bibtex_search bibtex_generate_keywords"
search="keywords" bibtex_split_by=", ">
<option value="">Search Keyword</option>
</select>

<div id="bibtex_display">
</div>

Expand All @@ -90,6 +100,7 @@ <h1> Auto-Fill Selects Test File</h1>
<span class="title"></span>
<span class="bibtexkey" style="display:none"></span>
<span class="bibtextypekey" style="display:none"></span>
<span class="keywords" style="display:none"></span>
</div>
</div>

Expand Down

0 comments on commit 9034073

Please sign in to comment.