From 9c4de58161879b4c4d26fc6cc513f7aabf2892e5 Mon Sep 17 00:00:00 2001 From: "G.Ambatte" Date: Sat, 6 Jul 2024 13:22:47 +1200 Subject: [PATCH 1/4] Limit htmlString to the first element ONLY --- shared/naturalcrit/markdown.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/shared/naturalcrit/markdown.js b/shared/naturalcrit/markdown.js index 529129833..cabb73c89 100644 --- a/shared/naturalcrit/markdown.js +++ b/shared/naturalcrit/markdown.js @@ -788,10 +788,11 @@ const processStyleTags = (string)=>{ }; const extractHTMLStyleTags = (htmlString)=>{ - const id = htmlString.match(/id="([^"]*)"/)?.[1] || null; - const classes = htmlString.match(/class="([^"]*)"/)?.[1] || null; - const styles = htmlString.match(/style="([^"]*)"/)?.[1] || null; - const attributes = htmlString.match(/[a-zA-Z]+="[^"]*"/g) + const firstElementOnly = htmlString.indexOf('>') > 0 ? htmlString.substring(0, htmlString.indexOf('>')) : htmlString; + const id = firstElementOnly.match(/id="([^"]*)"/)?.[1] || null; + const classes = firstElementOnly.match(/class="([^"]*)"/)?.[1] || null; + const styles = firstElementOnly.match(/style="([^"]*)"/)?.[1] || null; + const attributes = firstElementOnly.match(/[a-zA-Z]+="[^"]*"/g) ?.filter((attr)=>!attr.startsWith('class="') && !attr.startsWith('style="') && !attr.startsWith('id="')) .reduce((obj, attr)=>{ const index = attr.indexOf('='); From 5433cda52fb1493ea25139a363e5714d4dca8a4c Mon Sep 17 00:00:00 2001 From: Trevor Buckner Date: Sat, 6 Jul 2024 17:05:23 -0400 Subject: [PATCH 2/4] Add test case --- tests/markdown/mustache-syntax.test.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/markdown/mustache-syntax.test.js b/tests/markdown/mustache-syntax.test.js index 7b0115cae..3f7f2529b 100644 --- a/tests/markdown/mustache-syntax.test.js +++ b/tests/markdown/mustache-syntax.test.js @@ -333,6 +333,13 @@ describe('Injection: When an injection tag follows an element', ()=>{ expect(rendered, `Input:\n${source}`, { showPrefix: false }).toBe('

text{background:blue}

'); }); + it('Renders an parent and child element, each modified by an injector', function() { + const source = dedent`**bolded text**{color:red} + {color:blue}`; + const rendered = Markdown.render(source).trimReturns(); + expect(rendered, `Input:\n${source}`, { showPrefix: false }).toBe('

bolded text

'); + }); + it('Renders an image with added attributes', function() { const source = `![homebrew mug](https://i.imgur.com/hMna6G0.png) {position:absolute,bottom:20px,left:130px,width:220px,a="b and c",d=e}`; const rendered = Markdown.render(source).trimReturns(); From 0a199e750fa6c445e126f00ed491d6fa6e75febe Mon Sep 17 00:00:00 2001 From: Trevor Buckner Date: Sat, 6 Jul 2024 18:00:18 -0400 Subject: [PATCH 3/4] Simplify string splitting code String.split will return the substring before > or the whole string if no > exists. --- shared/naturalcrit/markdown.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/shared/naturalcrit/markdown.js b/shared/naturalcrit/markdown.js index cabb73c89..39939f306 100644 --- a/shared/naturalcrit/markdown.js +++ b/shared/naturalcrit/markdown.js @@ -787,8 +787,9 @@ const processStyleTags = (string)=>{ }; }; +//Given a string representing an HTML element, extract all of its properties (id, class, style, and other attributes) const extractHTMLStyleTags = (htmlString)=>{ - const firstElementOnly = htmlString.indexOf('>') > 0 ? htmlString.substring(0, htmlString.indexOf('>')) : htmlString; + const firstElementOnly = htmlString.split('>')[0]; const id = firstElementOnly.match(/id="([^"]*)"/)?.[1] || null; const classes = firstElementOnly.match(/class="([^"]*)"/)?.[1] || null; const styles = firstElementOnly.match(/style="([^"]*)"/)?.[1] || null; From f8841c068f4971a44b0f943505ad331c12d1d3b9 Mon Sep 17 00:00:00 2001 From: Trevor Buckner Date: Sat, 6 Jul 2024 18:20:11 -0400 Subject: [PATCH 4/4] Up Version to 3.13.1 --- changelog.md | 10 ++++++++++ package-lock.json | 4 ++-- package.json | 2 +- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/changelog.md b/changelog.md index 0a9e509f2..b331fc4f0 100644 --- a/changelog.md +++ b/changelog.md @@ -84,6 +84,16 @@ pre { ## changelog For a full record of development, visit our [Github Page](https://github.com/naturalcrit/homebrewery). +### Saturday 6/7/2024 - v3.13.1 +{{taskList + +##### calculuschild, G-Ambatte + +* [x] Hotfixes for issues with v3.13.0 + +Fixes issues [#3559](https://github.com/naturalcrit/homebrewery/issues/3559), [#3552](https://github.com/naturalcrit/homebrewery/issues/3552), [#3554](https://github.com/naturalcrit/homebrewery/issues/3554) +}} + ### Friday 28/6/2024 - v3.13.0 {{taskList diff --git a/package-lock.json b/package-lock.json index e3a3f355d..cce4d5577 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "homebrewery", - "version": "3.13.0", + "version": "3.13.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "homebrewery", - "version": "3.13.0", + "version": "3.13.1", "hasInstallScript": true, "license": "MIT", "dependencies": { diff --git a/package.json b/package.json index 4a42c528c..321f9afbe 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "homebrewery", "description": "Create authentic looking D&D homebrews using only markdown", - "version": "3.13.0", + "version": "3.13.1", "engines": { "npm": "^10.2.x", "node": "^20.8.x"