Skip to content
This repository has been archived by the owner on Mar 29, 2021. It is now read-only.

Commit

Permalink
fix doi parser. #424
Browse files Browse the repository at this point in the history
  • Loading branch information
dsifford committed Jan 31, 2018
1 parent db1dcc8 commit 7cbf65c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
22 changes: 11 additions & 11 deletions src/js/utils/formatters/__tests__/formatReferenceLinks-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ describe('formatReferenceLinks()', () => {
value: PMID,
}),
).toBe(
'Colmers IN, Paterson QS, Lin M, Thoma B, Chan TM. The quality checklists for medical education blogs and podcasts. <i>The Winnower</i>. 2015. doi: <a href="https://dx.doi.org/10.15200/winn.144720.08769" target="_blank" rel="noopener noreferrer">10.15200/winn.144720.08769</a> <span class="abt-url">[<a href="https://www.ncbi.nlm.nih.gov/pubmed/12345" target="_blank" rel="noopener noreferrer">PubMed</a>]</span>',
'Colmers IN, Paterson QS, Lin M, Thoma B, Chan TM. The quality checklists for medical education blogs and podcasts. <i>The Winnower</i>. 2015. doi:<a href="https://dx.doi.org/10.15200/winn.144720.08769" target="_blank" rel="noopener noreferrer">10.15200/winn.144720.08769</a>. <span class="abt-url">[<a href="https://www.ncbi.nlm.nih.gov/pubmed/12345" target="_blank" rel="noopener noreferrer">PubMed</a>]</span>',
);
expect(
formatReferenceLinks(testRefs[3], 'always', {
Expand Down Expand Up @@ -96,7 +96,7 @@ describe('formatReferenceLinks()', () => {
value: DOI,
}),
).toBe(
'Colmers IN, Paterson QS, Lin M, Thoma B, Chan TM. The quality checklists for medical education blogs and podcasts. <i>The Winnower</i>. 2015. doi: <a href="https://dx.doi.org/10.15200/winn.144720.08769" target="_blank" rel="noopener noreferrer">10.15200/winn.144720.08769</a>',
'Colmers IN, Paterson QS, Lin M, Thoma B, Chan TM. The quality checklists for medical education blogs and podcasts. <i>The Winnower</i>. 2015. doi:<a href="https://dx.doi.org/10.15200/winn.144720.08769" target="_blank" rel="noopener noreferrer">10.15200/winn.144720.08769</a>.',
);
expect(
formatReferenceLinks(testRefs[3], 'always', {
Expand Down Expand Up @@ -146,7 +146,7 @@ describe('formatReferenceLinks()', () => {
value: PMCID,
}),
).toBe(
'Colmers IN, Paterson QS, Lin M, Thoma B, Chan TM. The quality checklists for medical education blogs and podcasts. <i>The Winnower</i>. 2015. doi: <a href="https://dx.doi.org/10.15200/winn.144720.08769" target="_blank" rel="noopener noreferrer">10.15200/winn.144720.08769</a> <span class="abt-url">[<a href="https://www.ncbi.nlm.nih.gov/pmc/articles/PMC12345" target="_blank" rel="noopener noreferrer">PMC</a>]</span>',
'Colmers IN, Paterson QS, Lin M, Thoma B, Chan TM. The quality checklists for medical education blogs and podcasts. <i>The Winnower</i>. 2015. doi:<a href="https://dx.doi.org/10.15200/winn.144720.08769" target="_blank" rel="noopener noreferrer">10.15200/winn.144720.08769</a>. <span class="abt-url">[<a href="https://www.ncbi.nlm.nih.gov/pmc/articles/PMC12345" target="_blank" rel="noopener noreferrer">PMC</a>]</span>',
);
expect(
formatReferenceLinks(testRefs[3], 'always', {
Expand Down Expand Up @@ -196,7 +196,7 @@ describe('formatReferenceLinks()', () => {
value: URL,
}),
).toBe(
'Colmers IN, Paterson QS, Lin M, Thoma B, Chan TM. The quality checklists for medical education blogs and podcasts. <i>The Winnower</i>. 2015. doi: <a href="https://dx.doi.org/10.15200/winn.144720.08769" target="_blank" rel="noopener noreferrer">10.15200/winn.144720.08769</a> <span class="abt-url">[<a href="https://www.google.com" target="_blank" rel="noopener noreferrer">Source</a>]</span>',
'Colmers IN, Paterson QS, Lin M, Thoma B, Chan TM. The quality checklists for medical education blogs and podcasts. <i>The Winnower</i>. 2015. doi:<a href="https://dx.doi.org/10.15200/winn.144720.08769" target="_blank" rel="noopener noreferrer">10.15200/winn.144720.08769</a>. <span class="abt-url">[<a href="https://www.google.com" target="_blank" rel="noopener noreferrer">Source</a>]</span>',
);
expect(
formatReferenceLinks(testRefs[3], 'always', {
Expand Down Expand Up @@ -231,7 +231,7 @@ describe('formatReferenceLinks()', () => {
'Chan T, Helman A, Davis T, Purdy E. MEdIC Series | The Case the FOAM Faux Pas – Expert Review and Curated Commentary. Academic Life in Emergency Medicine. <a href="http://aliem.com/MEdIC-Series-The-Case-the-FOAM-Faux-Pas-Expert-Review-and-Curated-Commentary" target="_blank" rel="noopener noreferrer">http://aliem.com/MEdIC-Series-The-Case-the-FOAM-Faux-Pas-Expert-Review-and-Curated-Commentary</a>. Published 2015.',
);
expect(formatReferenceLinks(testRefs[2], 'always')).toBe(
'Colmers IN, Paterson QS, Lin M, Thoma B, Chan TM. The quality checklists for medical education blogs and podcasts. <i>The Winnower</i>. 2015. doi: <a href="https://dx.doi.org/10.15200/winn.144720.08769" target="_blank" rel="noopener noreferrer">10.15200/winn.144720.08769</a>',
'Colmers IN, Paterson QS, Lin M, Thoma B, Chan TM. The quality checklists for medical education blogs and podcasts. <i>The Winnower</i>. 2015. doi:<a href="https://dx.doi.org/10.15200/winn.144720.08769" target="_blank" rel="noopener noreferrer">10.15200/winn.144720.08769</a>.',
);
expect(formatReferenceLinks(testRefs[3], 'always')).toBe(
'Mathieu S. Trial of Early, Goal-Directed Resuscitation for Septic Shock. The Bottom Line. <a href="http://www.wessexics.com/The_Bottom_Line/Review/index.php?id=3665078336903245716" target="_blank" rel="noopener noreferrer">http://www.wessexics.com/The_Bottom_Line/Review/index.php?id=3665078336903245716</a>. Published 2015.',
Expand Down Expand Up @@ -459,7 +459,7 @@ describe('formatReferenceLinks()', () => {
expect(
formatReferenceLinks(testRefs[2], 'always-full-surround'),
).toBe(
'Colmers IN, Paterson QS, Lin M, Thoma B, Chan TM. The quality checklists for medical education blogs and podcasts. <i>The Winnower</i>. 2015. doi: <a href="https://dx.doi.org/10.15200/winn.144720.08769" target="_blank" rel="noopener noreferrer">10.15200/winn.144720.08769</a>',
'Colmers IN, Paterson QS, Lin M, Thoma B, Chan TM. The quality checklists for medical education blogs and podcasts. <i>The Winnower</i>. 2015. doi:<a href="https://dx.doi.org/10.15200/winn.144720.08769" target="_blank" rel="noopener noreferrer">10.15200/winn.144720.08769</a>.',
);
expect(
formatReferenceLinks(testRefs[3], 'always-full-surround'),
Expand Down Expand Up @@ -502,7 +502,7 @@ describe('formatReferenceLinks()', () => {
value: PMID,
}),
).toBe(
'Colmers IN, Paterson QS, Lin M, Thoma B, Chan TM. The quality checklists for medical education blogs and podcasts. <i>The Winnower</i>. 2015. doi: <a href="https://dx.doi.org/10.15200/winn.144720.08769" target="_blank" rel="noopener noreferrer">10.15200/winn.144720.08769</a>',
'Colmers IN, Paterson QS, Lin M, Thoma B, Chan TM. The quality checklists for medical education blogs and podcasts. <i>The Winnower</i>. 2015. doi:<a href="https://dx.doi.org/10.15200/winn.144720.08769" target="_blank" rel="noopener noreferrer">10.15200/winn.144720.08769</a>.',
);
expect(
formatReferenceLinks(testRefs[3], 'urls', {
Expand Down Expand Up @@ -552,7 +552,7 @@ describe('formatReferenceLinks()', () => {
value: DOI,
}),
).toBe(
'Colmers IN, Paterson QS, Lin M, Thoma B, Chan TM. The quality checklists for medical education blogs and podcasts. <i>The Winnower</i>. 2015. doi: <a href="https://dx.doi.org/10.15200/winn.144720.08769" target="_blank" rel="noopener noreferrer">10.15200/winn.144720.08769</a>',
'Colmers IN, Paterson QS, Lin M, Thoma B, Chan TM. The quality checklists for medical education blogs and podcasts. <i>The Winnower</i>. 2015. doi:<a href="https://dx.doi.org/10.15200/winn.144720.08769" target="_blank" rel="noopener noreferrer">10.15200/winn.144720.08769</a>.',
);
expect(
formatReferenceLinks(testRefs[3], 'urls', {
Expand Down Expand Up @@ -602,7 +602,7 @@ describe('formatReferenceLinks()', () => {
value: PMCID,
}),
).toBe(
'Colmers IN, Paterson QS, Lin M, Thoma B, Chan TM. The quality checklists for medical education blogs and podcasts. <i>The Winnower</i>. 2015. doi: <a href="https://dx.doi.org/10.15200/winn.144720.08769" target="_blank" rel="noopener noreferrer">10.15200/winn.144720.08769</a>',
'Colmers IN, Paterson QS, Lin M, Thoma B, Chan TM. The quality checklists for medical education blogs and podcasts. <i>The Winnower</i>. 2015. doi:<a href="https://dx.doi.org/10.15200/winn.144720.08769" target="_blank" rel="noopener noreferrer">10.15200/winn.144720.08769</a>.',
);
expect(
formatReferenceLinks(testRefs[3], 'urls', {
Expand Down Expand Up @@ -652,7 +652,7 @@ describe('formatReferenceLinks()', () => {
value: URL,
}),
).toBe(
'Colmers IN, Paterson QS, Lin M, Thoma B, Chan TM. The quality checklists for medical education blogs and podcasts. <i>The Winnower</i>. 2015. doi: <a href="https://dx.doi.org/10.15200/winn.144720.08769" target="_blank" rel="noopener noreferrer">10.15200/winn.144720.08769</a>',
'Colmers IN, Paterson QS, Lin M, Thoma B, Chan TM. The quality checklists for medical education blogs and podcasts. <i>The Winnower</i>. 2015. doi:<a href="https://dx.doi.org/10.15200/winn.144720.08769" target="_blank" rel="noopener noreferrer">10.15200/winn.144720.08769</a>.',
);
expect(
formatReferenceLinks(testRefs[3], 'urls', {
Expand Down Expand Up @@ -687,7 +687,7 @@ describe('formatReferenceLinks()', () => {
'Chan T, Helman A, Davis T, Purdy E. MEdIC Series | The Case the FOAM Faux Pas – Expert Review and Curated Commentary. Academic Life in Emergency Medicine. <a href="http://aliem.com/MEdIC-Series-The-Case-the-FOAM-Faux-Pas-Expert-Review-and-Curated-Commentary" target="_blank" rel="noopener noreferrer">http://aliem.com/MEdIC-Series-The-Case-the-FOAM-Faux-Pas-Expert-Review-and-Curated-Commentary</a>. Published 2015.',
);
expect(formatReferenceLinks(testRefs[2], 'urls')).toBe(
'Colmers IN, Paterson QS, Lin M, Thoma B, Chan TM. The quality checklists for medical education blogs and podcasts. <i>The Winnower</i>. 2015. doi: <a href="https://dx.doi.org/10.15200/winn.144720.08769" target="_blank" rel="noopener noreferrer">10.15200/winn.144720.08769</a>',
'Colmers IN, Paterson QS, Lin M, Thoma B, Chan TM. The quality checklists for medical education blogs and podcasts. <i>The Winnower</i>. 2015. doi:<a href="https://dx.doi.org/10.15200/winn.144720.08769" target="_blank" rel="noopener noreferrer">10.15200/winn.144720.08769</a>.',
);
expect(formatReferenceLinks(testRefs[3], 'urls')).toBe(
'Mathieu S. Trial of Early, Goal-Directed Resuscitation for Septic Shock. The Bottom Line. <a href="http://www.wessexics.com/The_Bottom_Line/Review/index.php?id=3665078336903245716" target="_blank" rel="noopener noreferrer">http://www.wessexics.com/The_Bottom_Line/Review/index.php?id=3665078336903245716</a>. Published 2015.',
Expand Down
6 changes: 3 additions & 3 deletions src/js/utils/formatters/formatReferenceLinks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export function formatReferenceLinks(
}

const url: RegExp = /((?:https?:\/\/(?:www\.)?)|(?:www\.))([^;\s<]+[0-9a-zA-Z\/])/g;
const doi: RegExp = /doi:(\S+)\./g;
const doi: RegExp = /10\.[0-9]{4,}(?:\.[a-z0-9.]+)?\/\S+[^. ]/gi;
const matches: Set<string> = new Set();

const linkedHtml = decode(html)
Expand All @@ -34,9 +34,9 @@ export function formatReferenceLinks(
matches.add(u);
return `<a href="${u}" target="_blank" rel="noopener noreferrer">${u}</a>`;
})
.replace(doi, (_match, p1) => {
.replace(doi, match => {
matches.add('DOI');
return `doi: <a href="https://dx.doi.org/${p1}" target="_blank" rel="noopener noreferrer">${p1}</a>`;
return `<a href="https://dx.doi.org/${match}" target="_blank" rel="noopener noreferrer">${match}</a>`;
});

if (!id) {
Expand Down

0 comments on commit 7cbf65c

Please sign in to comment.