Skip to content

Commit

Permalink
Match DOIs with multiple slashes
Browse files Browse the repository at this point in the history
We assumed that DOI suffixes could only have a single slash, but
they can have more than one slash. For example, in the DOI
`10.1093/mnras/stz2357`, the prefix is `10.1093` and the suffix
is `mnras/stz2357`.
  • Loading branch information
lpsinger committed Feb 22, 2024
1 parent 78dd6f2 commit ac145a6
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/replacements/doi/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { FindAndReplace } from '../index.js'

const doiMarker = /(?:doi:|https?:\/\/(?:dx\.)?doi\.org\/)/.source
const suffixChars = /[a-zA-Z0-9]/.source
const suffixCharsNonTerminal = /[-_.~%]/.source
const suffixCharsNonTerminal = /[-_.~%/]/.source
const prefix = /10\.\d{4,}/.source
const terminal = /\s|$/.source

Expand Down
3 changes: 2 additions & 1 deletion src/replacements/doi/test.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<p>Citing <data class="doi" value="10.1000/foo.bar">doi:10.1000/foo.bar</data> in a sentence.</p>
<p>Cite <data class="doi" value="10.1000/foo.bar">doi:10.1000/foo.bar</data>, cite <data class="doi" value="10.1000/bat.baz">doi:10.1000/bat.baz</data>. Another sentence.</p>
<p>You can use DOI URls like <data class="doi" value="10.1000/foo.bar">http://dx.doi.org/10.1000/foo.bar</data> or <data class="doi" value="10.1000/foo.bar">https://doi.org/10.1000/foo.bar</data></p>
<p>Cite <data class="doi" value="10.1000/foo.bar">doi:10.1000/foo.bar</data>.</p>
<p>Cite <data class="doi" value="10.1000/foo.bar">doi:10.1000/foo.bar</data>.</p>
<p>Cite <data class="doi" value="10.1000/foo.bar/bat">doi:10.1000/foo.bar/bat</data>, <data class="doi" value="10.1000/foo.bar/baf/baz">doi:10.1000/foo.bar/baf/baz</data>.</p>
33 changes: 33 additions & 0 deletions src/replacements/doi/test.json
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,39 @@
"value": "."
}
]
},
{
"type": "paragraph",
"children": [
{
"type": "text",
"value": "Cite "
},
{
"type": "text",
"value": "doi:10.1000/foo.bar/bat",
"data": {
"class": "doi",
"value": "10.1000/foo.bar/bat"
}
},
{
"type": "text",
"value": ", "
},
{
"type": "text",
"value": "doi:10.1000/foo.bar/baf/baz",
"data": {
"class": "doi",
"value": "10.1000/foo.bar/baf/baz"
}
},
{
"type": "text",
"value": "."
}
]
}
]
}
2 changes: 2 additions & 0 deletions src/replacements/doi/test.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ Cite doi:10.1000/foo.bar, cite doi:10.1000/bat.baz. Another sentence.
You can use DOI URls like http://dx.doi.org/10.1000/foo.bar or https://doi.org/10.1000/foo.bar

Cite doi:10.1000/foo.bar.

Cite doi:10.1000/foo.bar/bat, doi:10.1000/foo.bar/baf/baz.

0 comments on commit ac145a6

Please sign in to comment.