From 7b85995b4a56ecc382219c1f6be3f1b74843bf3d Mon Sep 17 00:00:00 2001 From: David Bolack Date: Fri, 10 Nov 2023 00:28:25 -0600 Subject: [PATCH] Updated attribute assignment. Wraps with quotes ( a="b and c" ) Still does not work on Mustache Divs. UNsure where the failure is at the moment. Even regressed "a:b and c" pattern on those. --- shared/naturalcrit/markdown.js | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/shared/naturalcrit/markdown.js b/shared/naturalcrit/markdown.js index 5b2f47309..98cfa7c8c 100644 --- a/shared/naturalcrit/markdown.js +++ b/shared/naturalcrit/markdown.js @@ -34,7 +34,7 @@ const mustacheSpans = { start(src) { return src.match(/{{[^{]/)?.index; }, // Hint to Marked.js to stop and check for a match tokenizer(src, tokens) { const completeSpan = /^{{[^\n]*}}/; // Regex for the complete token - const inlineRegex = /{{(?=((?::(?:"[\w,\-()#%. ]*"|[\w\-()#%.]*)|[^"':{}\s]*)*))\1 *|}}/g; + const inlineRegex = /{{(?=((?:[:=](?:"[\w,\-()#%. ]*"|[\w\-()#%.]*)|[^"=':{}\s]*)*))\1 *|}}/g; const match = completeSpan.exec(src); if(match) { //Find closing delimiter @@ -132,13 +132,12 @@ const mustacheInjectInline = { level : 'inline', start(src) { return src.match(/ *{[^{\n]/)?.index; }, // Hint to Marked.js to stop and check for a match tokenizer(src, tokens) { - const inlineRegex = /^ *{(?=((?::(?:"[\w,\-()#%. ]*"|[\w\-()#%.]*)|[^"':{}\n\r\t\f]*)*))\1}/g; + const inlineRegex = /^ *{(?=((?:[:=](?:"[\w,\-()#%. ]*"|[\w\-()#%.]*)|[^"=':{}\s]*)*))\1}/g; const match = inlineRegex.exec(src); if(match) { const lastToken = tokens[tokens.length - 1]; if(!lastToken || lastToken.type == 'mustacheInjectInline') return false; - const tags = ` ${processStyleTags(match[1])}`; lastToken.originalType = lastToken.type; lastToken.type = 'mustacheInjectInline'; @@ -167,7 +166,7 @@ const mustacheInjectBlock = { level : 'block', start(src) { return src.match(/\n *{[^{\n]/m)?.index; }, // Hint to Marked.js to stop and check for a match tokenizer(src, tokens) { - const inlineRegex = /^ *{(?=((?::(?:"[\w,\-()#%. ]*"|[\w\-()#%.]*)|[^"':{}\n\r\t\f]*)*))\1}/ym; + const inlineRegex = /^ *{(?=((?:[:=](?:"[\w,\-()#%. ]*"|[\w\-()#%.]*)|[^"=':{}\s]*)*))\1}/ym; const match = inlineRegex.exec(src); if(match) { const lastToken = tokens[tokens.length - 1]; @@ -328,19 +327,13 @@ const voidTags = new Set([ const processStyleTags = (string)=>{ //split tags up. quotes can only occur right after colons. //TODO: can we simplify to just split on commas? - const tags = string.match(/(?:[^,":]+|:(?:"[^"]*"|))+/g); - - if(!tags) return '"'; + const tags = string.match(/(?:[^,":=]+|[:=](?:"[^"]*"|))+/g); const id = _.remove(tags, (tag)=>tag.startsWith('#')).map((tag)=>tag.slice(1))[0]; const classes = _.remove(tags, (tag)=>(!tag.includes(':')) && (!tag.includes('='))); - let attributes = _.remove(tags, (tag)=>(!tag.includes(':')) && (!tag.includes('#'))); + const attributes = _.remove(tags, (tag)=>(!tag.includes(':')) && (!tag.includes('#'))); const styles = tags.map((tag)=>tag.replace(/:"?([^"]*)"?/g, ':$1;').trim()); - if(attributes.length) { - attributes = attributes.map((attribute)=>attribute.replace(/(\w+)=(.+)/, ' $1="$2"')); - } - return `${classes.join(' ')}" ` + `${id ? `id="${id}"` : ''} ` + `${styles.length ? `style="${styles.join(' ')}"` : ''}` +