From a0924d447a53511c96945873a3ec996b5800d9a9 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Tue, 31 Mar 2026 08:47:13 -0300 Subject: wiki-data: try some re sugar --- src/common-util/wiki-data.js | 77 ++++++++++++++++++++++++++------------------ 1 file 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>` + - String.raw`(?: \((?.*)\))?` + - String.raw`)` + - String.raw`|` + - String.raw`(?:` + - String.raw`@@ (?.*)` + - 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`(?:(?sometime|throughout|around) )?` + - String.raw`${dateRegex('date')}` + - String.raw`(?: ?- ?${dateRegex('secondDate')})?` + - - String.raw`(?: ?(?<= )` + - String.raw`(?captured|accessed) ${dateRegex('accessDate')}` + - String.raw`)?` + - - String.raw`$`; + re('gm')` + ^(?: + (?:${[ + /(?.+?):<\/i>/, + /(?: \((?.*)\))?/, + ]}) + | + (?:${[ + /@@ (?.*)/, + ]}) + )$ + `; const contentEntryAnnotationTailRegex = - new RegExp(contentEntryAnnotationTailRegexRaw); + re` + ${/(?:, |^)/} + + ${/(?:(?sometime|throughout|around) )?/} + + ${dateRegex('date')} + + ${[ + '(?:', + ' ?', + '-', + ' ?', + dateRegex('secondDate'), + ')?', + ]} + + ${[ + '(?: ?(?<= )', + /(?captured|accessed)/, + ' ', + dateRegex('accessDate'), + ')?', + ]} + `; export function* matchContentEntries(sourceText) { let workingEntry = null; -- cgit 1.3.0-6-gf8a5