Skip to content

Commit

Permalink
Parse arXiv URLs
Browse files Browse the repository at this point in the history
  • Loading branch information
lpsinger committed Sep 19, 2023
1 parent 57083a7 commit 11c6a02
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/replacements/arXiv/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import type { FindAndReplace } from '../index.js'

const marker = /(?:arXiv:|https?:\/\/(?:www\.)?arxiv\.org\/abs\/)/.source
const articleId = /(?:\d{4}\.\d{5}|[a-z-]+\/\d{7})(?:v\d+)?/.source

export default {
find: /arXiv:((?:\d{4}\.\d{5}|[a-z-]+\/\d{7})(?:v\d+)?)/g,
find: new RegExp(`${marker}(${articleId})`, 'g'),
replace(data, text, value) {
return data('arXiv', text, value)
},
Expand Down
1 change: 1 addition & 0 deletions src/replacements/arXiv/test.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<p>Old style arXiv reference: <data class="arXiv" value="astro-ph/1234567">arXiv:astro-ph/1234567</data></p>
<p>New style arXiv reference: <data class="arXiv" value="1234.56789">arXiv:1234.56789</data></p>
<p>URL references: <data class="arXiv" value="1234.56789">http://www.arxiv.org/abs/1234.56789</data>, <data class="arXiv" value="1234.56789">https://arxiv.org/abs/1234.56789</data></p>
<p>Versioned arXiv reference: <data class="arXiv" value="1234.56789v2">arXiv:1234.56789v2</data></p>
29 changes: 29 additions & 0 deletions src/replacements/arXiv/test.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,35 @@
}
]
},
{
"type": "paragraph",
"children": [
{
"type": "text",
"value": "URL references: "
},
{
"type": "text",
"value": "http://www.arxiv.org/abs/1234.56789",
"data": {
"class": "arXiv",
"value": "1234.56789"
}
},
{
"type": "text",
"value": ", "
},
{
"type": "text",
"value": "https://arxiv.org/abs/1234.56789",
"data": {
"class": "arXiv",
"value": "1234.56789"
}
}
]
},
{
"type": "paragraph",
"children": [
Expand Down
2 changes: 2 additions & 0 deletions src/replacements/arXiv/test.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@ Old style arXiv reference: arXiv:astro-ph/1234567

New style arXiv reference: arXiv:1234.56789

URL references: http://www.arxiv.org/abs/1234.56789, https://arxiv.org/abs/1234.56789

Versioned arXiv reference: arXiv:1234.56789v2

0 comments on commit 11c6a02

Please sign in to comment.