diff --git a/shared/naturalcrit/markdown.js b/shared/naturalcrit/markdown.js index 878519a4a..11756e507 100644 --- a/shared/naturalcrit/markdown.js +++ b/shared/naturalcrit/markdown.js @@ -129,7 +129,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 @@ -186,7 +186,7 @@ const mustacheDivs = { start(src) { return src.match(/\n *{{[^{]/m)?.index; }, // Hint to Marked.js to stop and check for a match tokenizer(src, tokens) { const completeBlock = /^ *{{[^\n}]* *\n.*\n *}}/s; // Regex for the complete token - const blockRegex = /^ *{{(?=((?:[:=](?:"['\w,\-()#%=?. ]*"|[\w\-()#%.]*)|[^"=':{}\s]*)*))\1 *$|^ *}}$/gm; + const blockRegex = /^ *{{(?=((?:[:=](?:"['\w,\-()#%=?.: ]*"|'[\w,\-()#%=?.: ]*'|[\w\-()#%.]*)|[^"=':{}\s]*)*))\1 *$|^ *}}$/gm; const match = completeBlock.exec(src); if(match) { //Find closing delimiter @@ -241,7 +241,7 @@ 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\-()#%.]*)|[^"=':{}\s]*)*))\1}/g; + const inlineRegex = /^ *{(?=((?:[:=](?:"['\w,\-()#%=?.: ]*"|'[\w,\-()#%=?.: ]*'|[\w\-()#%.]*)|[^"=':{}\s]*)*))\1}/g; const match = inlineRegex.exec(src); if(match) { const lastToken = tokens[tokens.length - 1]; @@ -287,7 +287,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\-()#%.]*)|[^"=':{}\s]*)*))\1}/ym; + const inlineRegex = /^ *{(?=((?:[:=](?:"['\w,\-()#%=?.: ]*"|'[\w,\-()#%=?.: ]*'|[\w\-()#%.]*)|[^"=':{}\s]*)*))\1}/ym; const match = inlineRegex.exec(src); if(match) { const lastToken = tokens[tokens.length - 1]; @@ -837,12 +837,23 @@ const processStyleTags = (string)=>{ obj[key.trim()] = value.trim(); return obj; }, {}) || null; - const styles = tags?.length ? tags.reduce((styleObj, style) => { - const index = style.indexOf(':'); - const [key, value] = [style.substring(0, index), style.substring(index + 1)]; - styleObj[key.trim()] = value.replace(/"?([^"]*)"?/g, '$1').trim(); - return styleObj; - }, {}) : null; + // Wrap CSS properties. Replace nested quotes for backwards compatibility; + for (let tag in tags) { + if(tags[tag].startsWith('--')) { + const tagName=tags[tag].split(':', 1)[0]; + const tagRegex = /(?=(?:"'(.*)*'"|'(.*)*'|"(.*)*"))/; + const tagMatch = tagRegex.exec(tags[tag].slice(tagName.length)); + if(tagMatch){ + tags[tag] = `${tagName}:'${tagMatch[1]||tagMatch[2]||tagMatch[3]}'`; + } + } + } + const styles = tags?.length ? tags.reduce((styleObj, style)=>{ + const index = style.indexOf(':'); + const [key, value] = [style.substring(0, index), style.substring(index + 1)]; + styleObj[key.trim()] = value.replace(/"?([^"]*)"?/g, '$1').trim(); + return styleObj; + }, {}) : null; return { id : id, diff --git a/tests/markdown/mustache-syntax.test.js b/tests/markdown/mustache-syntax.test.js index d17518411..8ff8210b6 100644 --- a/tests/markdown/mustache-syntax.test.js +++ b/tests/markdown/mustache-syntax.test.js @@ -106,7 +106,7 @@ describe('Inline: When using the Inline syntax {{ }}', ()=>{ it('Renders a mustache span with text with quotes and css property which contains double and simple quotes', function() { - const source = `{{--stringVariable:"'string'" text "with quotes"}}`; + const source = `{{--stringVariable:"string" text "with quotes"}}`; const rendered = Markdown.render(source); expect(rendered, `Input:\n${source}`, { showPrefix: false }).toBe(`text “with quotes”`); });