diff --git a/.gitattributes b/.gitattributes index 4482262..251917a 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,2 +1,3 @@ +src/replacements/*/*.md -text src/replacements/*/*.json -text src/replacements/*/*.html -text diff --git a/src/replacements/gcn-circular/index.ts b/src/replacements/gcn-circular/index.ts index 07d8a5e..c723454 100644 --- a/src/replacements/gcn-circular/index.ts +++ b/src/replacements/gcn-circular/index.ts @@ -5,8 +5,8 @@ function normalize(match: string) { return parseFloat(match.replace(/a$/i, '.5')) } -const preamble = /GCN(?:s|\s+Circulars?|\s+Circs?\.)?\s*/.source -const conjunction = /(?:\s*|,|and)+/.source +const preamble = /GCN(?:s|\s+Circulars?|\s+Circs?\.?)?\s*(?:#)?/gi.source +const conjunction = /(?:\s*#?|,|and\s*#?)+/.source const circularIdRegExp = /\d+(?:a|\.5)?/gi const circularId = circularIdRegExp.source const legacyUrlOrigin = /https?:\/\/gcn\.gsfc\.nasa\.gov/.source @@ -17,7 +17,7 @@ const url = `${urlOrigin}/circulars/(${circularId})` export default { find: new RegExp( - `${url}|${legacyUrl}|(?<=^|\\s)(?:${preamble}${circularId}(?:${conjunction}${circularId})*)`, + `${url}|${legacyUrl}|(?<=^|\\s|\\()(?:${preamble}${circularId}(?:${conjunction}${circularId})*)`, 'gi' ), replace(data, value, circularIdFromUrl, circularIdFromLegacyUrl) { diff --git a/src/replacements/gcn-circular/test.html b/src/replacements/gcn-circular/test.html index 8db6ac7..41a4696 100644 --- a/src/replacements/gcn-circular/test.html +++ b/src/replacements/gcn-circular/test.html @@ -5,4 +5,46 @@

Hello, world

And even really weird legacy URLs work: https://gcn.gsfc.nasa.gov/gcn/gcn/gcn/gcn3/33567.gcn3

GCN Circ. 789 and GCN Circs. 3 and 4

And this one refers to GCNs 1, 23a, 45.5 and 42

-

This is not a Circular: http://gcn.gsfc.nasa.gov/gcn/other/971227.gcn3

\ No newline at end of file +

This is not a Circular: http://gcn.gsfc.nasa.gov/gcn/other/971227.gcn3

+

All of these minor variations with parentheses, octothorpes, character casing, and periods, and different conjunctions are also supported: +GCN 123 +GCN #123 +(GCN 123) +(GCN #123) +GCN circ. 123 +GCN circ. #123 +(GCN circ. #123) +GCN circ 123 +(GCN circ 123) +GCN Circ. 123 +GCN Circ. #123 +(GCN Circ. #123) +GCN Circ 123 +(GCN Circ 123) +GCN Circular 123 +GCN Circular #123 +(GCN Circular 123) +(GCN Circular #123) +GCN Circs 123, 456 +GCN Circs. 123, 456 +GCN Circs #123, #456 +(GCN Circs #123, #456) +(GCN Circs 123, 456) +GCN Circ 123, 456 +GCN Circ. 123, 456 +GCN Circ #123, #456 +(GCN Circ 123, 456) +GCN circs 123, 456 +GCN circs. 123, 456 +GCN circs #123, #456 +(GCN circs 123, 456) +GCN circs 123 and 456 +GCN circs. 123 and 456 +GCN circs #123 and #456 +(GCN circs 123 and 456) +GCN circs 123 456 +GCN circs. 123 456 +GCN circs #123 #456 +(GCN circs 123 456) +GCN #123 +gcn 123

\ No newline at end of file diff --git a/src/replacements/gcn-circular/test.json b/src/replacements/gcn-circular/test.json index 0e03023..ec6d2d0 100644 --- a/src/replacements/gcn-circular/test.json +++ b/src/replacements/gcn-circular/test.json @@ -209,6 +209,919 @@ "value": "This is not a Circular: http://gcn.gsfc.nasa.gov/gcn/other/971227.gcn3" } ] + }, + { + "type": "paragraph", + "children": [ + { + "type": "text", + "value": "All of these minor variations with parentheses, octothorpes, character casing, and periods, and different conjunctions are also supported:\n" + }, + { + "type": "text", + "value": "GCN " + }, + { + "type": "text", + "value": "123", + "data": { + "class": "gcn-circular", + "value": 123 + } + }, + { + "type": "text", + "value": "\n" + }, + { + "type": "text", + "value": "GCN #" + }, + { + "type": "text", + "value": "123", + "data": { + "class": "gcn-circular", + "value": 123 + } + }, + { + "type": "text", + "value": "\n(" + }, + { + "type": "text", + "value": "GCN " + }, + { + "type": "text", + "value": "123", + "data": { + "class": "gcn-circular", + "value": 123 + } + }, + { + "type": "text", + "value": ")\n(" + }, + { + "type": "text", + "value": "GCN #" + }, + { + "type": "text", + "value": "123", + "data": { + "class": "gcn-circular", + "value": 123 + } + }, + { + "type": "text", + "value": ")\n" + }, + { + "type": "text", + "value": "GCN circ. " + }, + { + "type": "text", + "value": "123", + "data": { + "class": "gcn-circular", + "value": 123 + } + }, + { + "type": "text", + "value": "\n" + }, + { + "type": "text", + "value": "GCN circ. #" + }, + { + "type": "text", + "value": "123", + "data": { + "class": "gcn-circular", + "value": 123 + } + }, + { + "type": "text", + "value": "\n(" + }, + { + "type": "text", + "value": "GCN circ. #" + }, + { + "type": "text", + "value": "123", + "data": { + "class": "gcn-circular", + "value": 123 + } + }, + { + "type": "text", + "value": ")\n" + }, + { + "type": "text", + "value": "GCN circ " + }, + { + "type": "text", + "value": "123", + "data": { + "class": "gcn-circular", + "value": 123 + } + }, + { + "type": "text", + "value": "\n(" + }, + { + "type": "text", + "value": "GCN circ " + }, + { + "type": "text", + "value": "123", + "data": { + "class": "gcn-circular", + "value": 123 + } + }, + { + "type": "text", + "value": ")\n" + }, + { + "type": "text", + "value": "GCN Circ. " + }, + { + "type": "text", + "value": "123", + "data": { + "class": "gcn-circular", + "value": 123 + } + }, + { + "type": "text", + "value": "\n" + }, + { + "type": "text", + "value": "GCN Circ. #" + }, + { + "type": "text", + "value": "123", + "data": { + "class": "gcn-circular", + "value": 123 + } + }, + { + "type": "text", + "value": "\n(" + }, + { + "type": "text", + "value": "GCN Circ. #" + }, + { + "type": "text", + "value": "123", + "data": { + "class": "gcn-circular", + "value": 123 + } + }, + { + "type": "text", + "value": ")\n" + }, + { + "type": "text", + "value": "GCN Circ " + }, + { + "type": "text", + "value": "123", + "data": { + "class": "gcn-circular", + "value": 123 + } + }, + { + "type": "text", + "value": "\n(" + }, + { + "type": "text", + "value": "GCN Circ " + }, + { + "type": "text", + "value": "123", + "data": { + "class": "gcn-circular", + "value": 123 + } + }, + { + "type": "text", + "value": ")\n" + }, + { + "type": "text", + "value": "GCN Circular " + }, + { + "type": "text", + "value": "123", + "data": { + "class": "gcn-circular", + "value": 123 + } + }, + { + "type": "text", + "value": "\n" + }, + { + "type": "text", + "value": "GCN Circular #" + }, + { + "type": "text", + "value": "123", + "data": { + "class": "gcn-circular", + "value": 123 + } + }, + { + "type": "text", + "value": "\n(" + }, + { + "type": "text", + "value": "GCN Circular " + }, + { + "type": "text", + "value": "123", + "data": { + "class": "gcn-circular", + "value": 123 + } + }, + { + "type": "text", + "value": ")\n(" + }, + { + "type": "text", + "value": "GCN Circular #" + }, + { + "type": "text", + "value": "123", + "data": { + "class": "gcn-circular", + "value": 123 + } + }, + { + "type": "text", + "value": ")\n" + }, + { + "type": "text", + "value": "GCN Circs " + }, + { + "type": "text", + "value": "123", + "data": { + "class": "gcn-circular", + "value": 123 + } + }, + { + "type": "text", + "value": ", " + }, + { + "type": "text", + "value": "456", + "data": { + "class": "gcn-circular", + "value": 456 + } + }, + { + "type": "text", + "value": "\n" + }, + { + "type": "text", + "value": "GCN Circs. " + }, + { + "type": "text", + "value": "123", + "data": { + "class": "gcn-circular", + "value": 123 + } + }, + { + "type": "text", + "value": ", " + }, + { + "type": "text", + "value": "456", + "data": { + "class": "gcn-circular", + "value": 456 + } + }, + { + "type": "text", + "value": "\n" + }, + { + "type": "text", + "value": "GCN Circs #" + }, + { + "type": "text", + "value": "123", + "data": { + "class": "gcn-circular", + "value": 123 + } + }, + { + "type": "text", + "value": ", #" + }, + { + "type": "text", + "value": "456", + "data": { + "class": "gcn-circular", + "value": 456 + } + }, + { + "type": "text", + "value": "\n(" + }, + { + "type": "text", + "value": "GCN Circs #" + }, + { + "type": "text", + "value": "123", + "data": { + "class": "gcn-circular", + "value": 123 + } + }, + { + "type": "text", + "value": ", #" + }, + { + "type": "text", + "value": "456", + "data": { + "class": "gcn-circular", + "value": 456 + } + }, + { + "type": "text", + "value": ")\n(" + }, + { + "type": "text", + "value": "GCN Circs " + }, + { + "type": "text", + "value": "123", + "data": { + "class": "gcn-circular", + "value": 123 + } + }, + { + "type": "text", + "value": ", " + }, + { + "type": "text", + "value": "456", + "data": { + "class": "gcn-circular", + "value": 456 + } + }, + { + "type": "text", + "value": ")\n" + }, + { + "type": "text", + "value": "GCN Circ " + }, + { + "type": "text", + "value": "123", + "data": { + "class": "gcn-circular", + "value": 123 + } + }, + { + "type": "text", + "value": ", " + }, + { + "type": "text", + "value": "456", + "data": { + "class": "gcn-circular", + "value": 456 + } + }, + { + "type": "text", + "value": "\n" + }, + { + "type": "text", + "value": "GCN Circ. " + }, + { + "type": "text", + "value": "123", + "data": { + "class": "gcn-circular", + "value": 123 + } + }, + { + "type": "text", + "value": ", " + }, + { + "type": "text", + "value": "456", + "data": { + "class": "gcn-circular", + "value": 456 + } + }, + { + "type": "text", + "value": "\n" + }, + { + "type": "text", + "value": "GCN Circ #" + }, + { + "type": "text", + "value": "123", + "data": { + "class": "gcn-circular", + "value": 123 + } + }, + { + "type": "text", + "value": ", #" + }, + { + "type": "text", + "value": "456", + "data": { + "class": "gcn-circular", + "value": 456 + } + }, + { + "type": "text", + "value": "\n(" + }, + { + "type": "text", + "value": "GCN Circ " + }, + { + "type": "text", + "value": "123", + "data": { + "class": "gcn-circular", + "value": 123 + } + }, + { + "type": "text", + "value": ", " + }, + { + "type": "text", + "value": "456", + "data": { + "class": "gcn-circular", + "value": 456 + } + }, + { + "type": "text", + "value": ")\n" + }, + { + "type": "text", + "value": "GCN circs " + }, + { + "type": "text", + "value": "123", + "data": { + "class": "gcn-circular", + "value": 123 + } + }, + { + "type": "text", + "value": ", " + }, + { + "type": "text", + "value": "456", + "data": { + "class": "gcn-circular", + "value": 456 + } + }, + { + "type": "text", + "value": "\n" + }, + { + "type": "text", + "value": "GCN circs. " + }, + { + "type": "text", + "value": "123", + "data": { + "class": "gcn-circular", + "value": 123 + } + }, + { + "type": "text", + "value": ", " + }, + { + "type": "text", + "value": "456", + "data": { + "class": "gcn-circular", + "value": 456 + } + }, + { + "type": "text", + "value": "\n" + }, + { + "type": "text", + "value": "GCN circs #" + }, + { + "type": "text", + "value": "123", + "data": { + "class": "gcn-circular", + "value": 123 + } + }, + { + "type": "text", + "value": ", #" + }, + { + "type": "text", + "value": "456", + "data": { + "class": "gcn-circular", + "value": 456 + } + }, + { + "type": "text", + "value": "\n(" + }, + { + "type": "text", + "value": "GCN circs " + }, + { + "type": "text", + "value": "123", + "data": { + "class": "gcn-circular", + "value": 123 + } + }, + { + "type": "text", + "value": ", " + }, + { + "type": "text", + "value": "456", + "data": { + "class": "gcn-circular", + "value": 456 + } + }, + { + "type": "text", + "value": ")\n" + }, + { + "type": "text", + "value": "GCN circs " + }, + { + "type": "text", + "value": "123", + "data": { + "class": "gcn-circular", + "value": 123 + } + }, + { + "type": "text", + "value": " and " + }, + { + "type": "text", + "value": "456", + "data": { + "class": "gcn-circular", + "value": 456 + } + }, + { + "type": "text", + "value": "\n" + }, + { + "type": "text", + "value": "GCN circs. " + }, + { + "type": "text", + "value": "123", + "data": { + "class": "gcn-circular", + "value": 123 + } + }, + { + "type": "text", + "value": " and " + }, + { + "type": "text", + "value": "456", + "data": { + "class": "gcn-circular", + "value": 456 + } + }, + { + "type": "text", + "value": "\n" + }, + { + "type": "text", + "value": "GCN circs #" + }, + { + "type": "text", + "value": "123", + "data": { + "class": "gcn-circular", + "value": 123 + } + }, + { + "type": "text", + "value": " and #" + }, + { + "type": "text", + "value": "456", + "data": { + "class": "gcn-circular", + "value": 456 + } + }, + { + "type": "text", + "value": "\n(" + }, + { + "type": "text", + "value": "GCN circs " + }, + { + "type": "text", + "value": "123", + "data": { + "class": "gcn-circular", + "value": 123 + } + }, + { + "type": "text", + "value": " and " + }, + { + "type": "text", + "value": "456", + "data": { + "class": "gcn-circular", + "value": 456 + } + }, + { + "type": "text", + "value": ")\n" + }, + { + "type": "text", + "value": "GCN circs " + }, + { + "type": "text", + "value": "123", + "data": { + "class": "gcn-circular", + "value": 123 + } + }, + { + "type": "text", + "value": " " + }, + { + "type": "text", + "value": "456", + "data": { + "class": "gcn-circular", + "value": 456 + } + }, + { + "type": "text", + "value": "\n" + }, + { + "type": "text", + "value": "GCN circs. " + }, + { + "type": "text", + "value": "123", + "data": { + "class": "gcn-circular", + "value": 123 + } + }, + { + "type": "text", + "value": " " + }, + { + "type": "text", + "value": "456", + "data": { + "class": "gcn-circular", + "value": 456 + } + }, + { + "type": "text", + "value": "\n" + }, + { + "type": "text", + "value": "GCN circs #" + }, + { + "type": "text", + "value": "123", + "data": { + "class": "gcn-circular", + "value": 123 + } + }, + { + "type": "text", + "value": " #" + }, + { + "type": "text", + "value": "456", + "data": { + "class": "gcn-circular", + "value": 456 + } + }, + { + "type": "text", + "value": "\n(" + }, + { + "type": "text", + "value": "GCN circs " + }, + { + "type": "text", + "value": "123", + "data": { + "class": "gcn-circular", + "value": 123 + } + }, + { + "type": "text", + "value": " " + }, + { + "type": "text", + "value": "456", + "data": { + "class": "gcn-circular", + "value": 456 + } + }, + { + "type": "text", + "value": ")\n" + }, + { + "type": "text", + "value": "GCN #" + }, + { + "type": "text", + "value": "123", + "data": { + "class": "gcn-circular", + "value": 123 + } + }, + { + "type": "text", + "value": "\n" + }, + { + "type": "text", + "value": "gcn " + }, + { + "type": "text", + "value": "123", + "data": { + "class": "gcn-circular", + "value": 123 + } + } + ] } ] } \ No newline at end of file diff --git a/src/replacements/gcn-circular/test.md b/src/replacements/gcn-circular/test.md index 1337cd8..5050fe7 100644 --- a/src/replacements/gcn-circular/test.md +++ b/src/replacements/gcn-circular/test.md @@ -13,3 +13,46 @@ GCN Circ. 789 and GCN Circs. 3 and 4 And this one refers to GCNs 1, 23a, 45.5 and 42 This is not a Circular: http://gcn.gsfc.nasa.gov/gcn/other/971227.gcn3 + +All of these minor variations with parentheses, octothorpes, character casing, and periods, and different conjunctions are also supported: +GCN 123 +GCN #123 +(GCN 123) +(GCN #123) +GCN circ. 123 +GCN circ. #123 +(GCN circ. #123) +GCN circ 123 +(GCN circ 123) +GCN Circ. 123 +GCN Circ. #123 +(GCN Circ. #123) +GCN Circ 123 +(GCN Circ 123) +GCN Circular 123 +GCN Circular #123 +(GCN Circular 123) +(GCN Circular #123) +GCN Circs 123, 456 +GCN Circs. 123, 456 +GCN Circs #123, #456 +(GCN Circs #123, #456) +(GCN Circs 123, 456) +GCN Circ 123, 456 +GCN Circ. 123, 456 +GCN Circ #123, #456 +(GCN Circ 123, 456) +GCN circs 123, 456 +GCN circs. 123, 456 +GCN circs #123, #456 +(GCN circs 123, 456) +GCN circs 123 and 456 +GCN circs. 123 and 456 +GCN circs #123 and #456 +(GCN circs 123 and 456) +GCN circs 123 456 +GCN circs. 123 456 +GCN circs #123 #456 +(GCN circs 123 456) +GCN #123 +gcn 123