From ef6899009050d9036651162c17a8e7572552c558 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Tue, 31 Mar 2026 09:00:55 -0300 Subject: sugar, wiki-data: simplify re tool bigtime --- src/common-util/wiki-data.js | 106 ++++++++++++++++++++----------------------- 1 file changed, 50 insertions(+), 56 deletions(-) (limited to 'src/common-util/wiki-data.js') diff --git a/src/common-util/wiki-data.js b/src/common-util/wiki-data.js index 0e447030..ff325b7a 100644 --- a/src/common-util/wiki-data.js +++ b/src/common-util/wiki-data.js @@ -76,55 +76,48 @@ export function compareKebabCase(name1, name2) { // by slashes or dashes (only valid orders are MM/DD/YYYY and YYYY/MM/DD) // const dateRegex = groupName => - 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}/, - ]} - ) - `; + 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 = - re('gm')` - ^(?: - (?:${[ + re('gm', [ + '^(?:', + '(?:', /(?.+?):<\/i>/, /(?: \((?.*)\))?/, - ]}) - | - (?:${[ + ')', + '|', + '(?:', /@@ (?.*)/, - ]}) - )$ - `; + ')', + ')$', + ]); const contentEntryAnnotationTailRegex = - re` - ${/(?:, |^)/} - - ${/(?:(?sometime|throughout|around) )?/} - - ${dateRegex('date')} - - ${[ - '(?:', - ' ?', - '-', - ' ?', - dateRegex('secondDate'), - ')?', - ]} - - ${[ - '(?: ?(?<= )', - /(?captured|accessed)/, - ' ', - dateRegex('accessDate'), - ')?', - ]} - `; + re([ + /(?:, |^)/, + + /(?:(?sometime|throughout|around) )?/, + dateRegex('date'), + + '(?:', + ' ?', + '-', + ' ?', + dateRegex('secondDate'), + ')?', + + '(?: ?(?<= )', + /(?captured|accessed)/, + ' ', + dateRegex('accessDate'), + ')?', + ]); export function* matchContentEntries(sourceText) { let workingEntry = null; @@ -606,20 +599,21 @@ export function* matchMarkdownLinks(markdownSource, {marked}) { } export function* matchInlineLinks(source) { - const plausibleLinkRegexp = re('gmi')` - ${/\b[a-z]*:\/\//} - ${/.*?/} - - (?=${[ - // Ordinary in-sentence punctuation doesn't terminate the - // un-greedy URL match above, but it shouldn't be counted - // as part of the link either, if it's at the end. - /(?:[,.!?]*)/, - - // Actual terminators. - /(?:\s|$|
)/, - ]}) - `; + const plausibleLinkRegexp = + re('gmi', [ + /\b[a-z]*:\/\//, + /.*?/, + + '(?=', + // Ordinary in-sentence punctuation doesn't terminate the + // un-greedy URL match above, but it shouldn't be counted + // as part of the link either, if it's at the end. + /(?:[,.!?]*)/, + + // Actual terminators. + /(?:\s|$|
)/, + ')', + ]); let plausibleMatch = null; while (plausibleMatch = plausibleLinkRegexp.exec(source)) { -- cgit 1.3.0-6-gf8a5