diff options
| author | (quasar) nebula <qznebula@protonmail.com> | 2026-03-31 08:47:13 -0300 |
|---|---|---|
| committer | (quasar) nebula <qznebula@protonmail.com> | 2026-03-31 08:47:13 -0300 |
| commit | a0924d447a53511c96945873a3ec996b5800d9a9 (patch) | |
| tree | de70935b725a063581cbf2dafc7a434884092be7 /src/common-util | |
| parent | 1f94b922e7e80e958b3fcf0b9d154038a81076af (diff) | |
wiki-data: try some re sugar
Diffstat (limited to 'src/common-util')
| -rw-r--r-- | src/common-util/wiki-data.js | 77 |
1 files changed, 45 insertions, 32 deletions
diff --git a/src/common-util/wiki-data.js b/src/common-util/wiki-data.js index 4bae0125..0e447030 100644 --- a/src/common-util/wiki-data.js +++ b/src/common-util/wiki-data.js @@ -76,42 +76,55 @@ export function compareKebabCase(name1, name2) { // by slashes or dashes (only valid orders are MM/DD/YYYY and YYYY/MM/DD) // const dateRegex = groupName => - String.raw`(?<${groupName}>` + - String.raw`[a-zA-Z]+ [0-9]{1,2}, [0-9]{4,4}|` + - String.raw`[0-9]{1,2} [^,]*[0-9]{4,4}|` + - String.raw`[0-9]{1,4}[-/][0-9]{1,4}[-/][0-9]{1,4}` + - String.raw`)`; - -const contentEntryHeadingRegexRaw = - String.raw`^(?:` + - String.raw`(?:` + - String.raw`<i>(?<artists>.+?):<\/i>` + - String.raw`(?: \((?<annotation1>.*)\))?` + - String.raw`)` + - String.raw`|` + - String.raw`(?:` + - String.raw`@@ (?<annotation2>.*)` + - String.raw`)` + - String.raw`)$`; + re` + (?<${groupName}> + ${[ + /[a-zA-Z]+ [0-9]{1,2}, [0-9]{4,4}/, '|', + /[0-9]{1,2} [^,]*[0-9]{4,4}/, '|', + /[0-9]{1,4}[-/][0-9]{1,4}[-/][0-9]{1,4}/, + ]} + ) + `; const contentEntryHeadingRegex = - new RegExp(contentEntryHeadingRegexRaw, 'gm'); - -const contentEntryAnnotationTailRegexRaw = - String.raw`(?:, |^)` + - - String.raw`(?:(?<dateKind>sometime|throughout|around) )?` + - String.raw`${dateRegex('date')}` + - String.raw`(?: ?- ?${dateRegex('secondDate')})?` + - - String.raw`(?: ?(?<= )` + - String.raw`(?<accessKind>captured|accessed) ${dateRegex('accessDate')}` + - String.raw`)?` + - - String.raw`$`; + re('gm')` + ^(?: + (?:${[ + /<i>(?<artists>.+?):<\/i>/, + /(?: \((?<annotation1>.*)\))?/, + ]}) + | + (?:${[ + /@@ (?<annotation2>.*)/, + ]}) + )$ + `; const contentEntryAnnotationTailRegex = - new RegExp(contentEntryAnnotationTailRegexRaw); + re` + ${/(?:, |^)/} + + ${/(?:(?<dateKind>sometime|throughout|around) )?/} + + ${dateRegex('date')} + + ${[ + '(?:', + ' ?', + '-', + ' ?', + dateRegex('secondDate'), + ')?', + ]} + + ${[ + '(?: ?(?<= )', + /(?<accessKind>captured|accessed)/, + ' ', + dateRegex('accessDate'), + ')?', + ]} + `; export function* matchContentEntries(sourceText) { let workingEntry = null; |