Skip to content

Commit

Permalink
Update ref-extractor.js
Browse files Browse the repository at this point in the history
sort on natural numbers instead of strings
  • Loading branch information
mbroedl authored Aug 26, 2024
1 parent 6727951 commit b2367dd
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions libraries/ref-extractor.js
Original file line number Diff line number Diff line change
Expand Up @@ -510,13 +510,19 @@ function convertOutput() {
}));
// format as apa and move to beginning of line
let citationRender = new Cite(edited_json);
let bibliography = citationRender.format('bibliography').split('\n').map(ref => {
let count_str = (ref.match(/\[(\d+) citations\] /) || ['', '0']);
ref = count_str[1] + '\t' + ref.replace(count_str[0], '');
return ref;
let bibliography = citationRender.format('bibliography')
.split('\n')
.map(ref => {
let count_str = (ref.match(/\[(\d+) citations\] /) || ['', '0']);
ref = [Number(count_str[1]), count_str[1] + '\t' + ref.replace(count_str[0], '')];
return ref;
});
// sort by count
return 'cite_count\treference\n' + bibliography.sort().filter(l => l != '0\t').join('\n');
return 'cite_count\treference\n' + bibliography
.sort((a, b) => { return a[0] - b[0]})
.map(r => r[1])
.filter(r => r != '0\t')
.join('\n');
} catch (ex) {
console.error(ex);
return 'Failed to count references. Did you activate the "Store cite counts" option?'
Expand Down

0 comments on commit b2367dd

Please sign in to comment.