-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor/rewrite to add GCN Circulars cross references
- Loading branch information
Showing
21 changed files
with
7,189 additions
and
9,034 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
node_modules | ||
/coverage | ||
/*.js | ||
/*.d.ts | ||
*.d.ts | ||
.eslintcache | ||
*.tgz |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"editor.tabSize": 2, | ||
"javascript.format.semicolons": "remove", | ||
"typescript.preferences.quoteStyle": "single", | ||
"javascript.preferences.quoteStyle": "single", | ||
"typescript.format.semicolons": "remove" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,11 @@ | ||
import type { Nodes, Text } from 'mdast' | ||
import { type Find, findAndReplace } from 'mdast-util-find-and-replace' | ||
import type { Nodes } from 'mdast' | ||
import { findAndReplace } from 'mdast-util-find-and-replace' | ||
|
||
type AstroData = { | ||
/** Astro Flavored Markdown data type */ | ||
type: string | ||
/** Normalized value */ | ||
value: string | ||
} | ||
|
||
export interface AstroText extends Text { | ||
data: { | ||
astromd: AstroData | ||
} | ||
} | ||
|
||
interface VisitorSpec { | ||
/** Name of the Astro Flavored Markdown type. */ | ||
type: string | ||
/** Regular expression to search for. */ | ||
pattern: Find | ||
/** Replacement function to generate normalized value. | ||
* The function should be suitable for passing to String.replace(). | ||
*/ | ||
replacement: (value: string, ...groups: string[]) => string | ||
} | ||
import replacements from './replacements/index.js' | ||
|
||
const visitorSpecs: VisitorSpec[] = [ | ||
{ | ||
type: 'datetime', | ||
pattern: | ||
/(\d{4}-\d{2}-\d{2})(?:[ T](\d{2}(?::\d{2}(?::\d{2}(?:\.\d+)?)?))?)?Z?/, | ||
replacement: (_, date, time) => (time ? `${date}T${time}Z` : `${date}Z`), | ||
}, | ||
] | ||
export type { AstroData, AstroText } from './nodes.js' | ||
|
||
export default function mdastAstroMd<T extends Nodes>(tree: T): T { | ||
findAndReplace( | ||
tree, | ||
visitorSpecs.map(({ type, pattern, replacement }) => [ | ||
pattern, | ||
(value: string, ...groups: string[]) => ({ | ||
type: 'text', | ||
value, | ||
data: { astromd: { type, value: replacement(value, ...groups) } }, | ||
}), | ||
]) | ||
) | ||
export default function <T extends Nodes>(tree: T): T { | ||
findAndReplace(tree, replacements) | ||
return tree | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import type { Text } from 'mdast' | ||
|
||
type AstroValue = boolean | number | string | ||
|
||
export type AstroData = { | ||
/** Astro Flavored Markdown data type */ | ||
type: string | ||
/** Normalized value */ | ||
value: AstroValue | ||
} | ||
|
||
export interface AstroText extends Text { | ||
data: { | ||
astromd: AstroData | ||
} | ||
} | ||
|
||
export function text(value: string): Text { | ||
return { type: 'text', value } | ||
} | ||
|
||
export function astroText( | ||
value: string, | ||
type: string, | ||
astroValue?: AstroValue | ||
): AstroText { | ||
return { | ||
...text(value), | ||
data: { astromd: { type, value: astroValue ?? value } }, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import type { FindAndReplaceTuple } from 'mdast-util-find-and-replace' | ||
|
||
import { astroText } from '../../nodes.js' | ||
|
||
export default [ | ||
/arXiv:(?:\d{4}\.\d{5}|[a-z-]+\/\d{7})(?:v\d+)?/g, | ||
(value: string) => astroText(value, 'arXiv'), | ||
] satisfies FindAndReplaceTuple |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
{ | ||
"type": "root", | ||
"children": [ | ||
{ | ||
"type": "paragraph", | ||
"children": [ | ||
{ | ||
"type": "text", | ||
"value": "Old style arXiv reference: " | ||
}, | ||
{ | ||
"type": "text", | ||
"value": "arXiv:astro-ph/1234567", | ||
"data": { | ||
"astromd": { | ||
"type": "arXiv", | ||
"value": "arXiv:astro-ph/1234567" | ||
} | ||
} | ||
} | ||
], | ||
"position": { | ||
"start": { | ||
"line": 1, | ||
"column": 1, | ||
"offset": 0 | ||
}, | ||
"end": { | ||
"line": 1, | ||
"column": 50, | ||
"offset": 49 | ||
} | ||
} | ||
}, | ||
{ | ||
"type": "paragraph", | ||
"children": [ | ||
{ | ||
"type": "text", | ||
"value": "New style arXiv reference: " | ||
}, | ||
{ | ||
"type": "text", | ||
"value": "arXiv:1234.56789", | ||
"data": { | ||
"astromd": { | ||
"type": "arXiv", | ||
"value": "arXiv:1234.56789" | ||
} | ||
} | ||
} | ||
], | ||
"position": { | ||
"start": { | ||
"line": 3, | ||
"column": 1, | ||
"offset": 51 | ||
}, | ||
"end": { | ||
"line": 3, | ||
"column": 44, | ||
"offset": 94 | ||
} | ||
} | ||
}, | ||
{ | ||
"type": "paragraph", | ||
"children": [ | ||
{ | ||
"type": "text", | ||
"value": "Versioned arXiv reference: " | ||
}, | ||
{ | ||
"type": "text", | ||
"value": "arXiv:1234.56789v2", | ||
"data": { | ||
"astromd": { | ||
"type": "arXiv", | ||
"value": "arXiv:1234.56789v2" | ||
} | ||
} | ||
} | ||
], | ||
"position": { | ||
"start": { | ||
"line": 5, | ||
"column": 1, | ||
"offset": 96 | ||
}, | ||
"end": { | ||
"line": 5, | ||
"column": 46, | ||
"offset": 141 | ||
} | ||
} | ||
} | ||
], | ||
"position": { | ||
"start": { | ||
"line": 1, | ||
"column": 1, | ||
"offset": 0 | ||
}, | ||
"end": { | ||
"line": 6, | ||
"column": 1, | ||
"offset": 142 | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
Old style arXiv reference: arXiv:astro-ph/1234567 | ||
|
||
New style arXiv reference: arXiv:1234.56789 | ||
|
||
Versioned arXiv reference: arXiv:1234.56789v2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import type { FindAndReplaceTuple } from 'mdast-util-find-and-replace' | ||
|
||
import { astroText } from '../../nodes.js' | ||
|
||
export default [ | ||
/(\d{4}-\d{2}-\d{2})(?:[ T](\d{2}(?::\d{2}(?::\d{2}(?:\.\d+)?)?)))?Z?/g, | ||
(value: string, date: string, time?: string) => | ||
astroText(value, 'datetime', time ? `${date}T${time}Z` : `${date}Z`), | ||
] satisfies FindAndReplaceTuple |
Oops, something went wrong.