From 6a95ed57ca0f7782a0ef889463a79e826c51721d Mon Sep 17 00:00:00 2001 From: Gazook89 <58999374+Gazook89@users.noreply.github.com> Date: Fri, 24 Mar 2023 15:15:08 -0500 Subject: [PATCH 1/3] escape tokenization of injection if preceded by another injection. --- shared/naturalcrit/markdown.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/shared/naturalcrit/markdown.js b/shared/naturalcrit/markdown.js index 16623b8a5..50bbfe827 100644 --- a/shared/naturalcrit/markdown.js +++ b/shared/naturalcrit/markdown.js @@ -134,7 +134,7 @@ const mustacheInjectInline = { const match = inlineRegex.exec(src); if(match) { const lastToken = tokens[tokens.length - 1]; - if(!lastToken) + if(!lastToken || lastToken.type == 'mustacheInjectInline') return false; const tags = ` ${processStyleTags(match[1])}`; @@ -169,7 +169,8 @@ const mustacheInjectBlock = { const match = inlineRegex.exec(src); if(match) { const lastToken = tokens[tokens.length - 1]; - if(!lastToken) + console.log(lastToken); + if(!lastToken || lastToken.type == 'mustacheInjectBlock') return false; lastToken.originalType = 'mustacheInjectBlock'; From 7353e6c7ac54b4228f8cc0863ed7c6f201f86031 Mon Sep 17 00:00:00 2001 From: Gazook89 <58999374+Gazook89@users.noreply.github.com> Date: Mon, 3 Apr 2023 16:57:29 -0500 Subject: [PATCH 2/3] Add unit tests for double injection into block and inline --- tests/markdown/mustache-span.test.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tests/markdown/mustache-span.test.js b/tests/markdown/mustache-span.test.js index 6d249ebcb..e7c65ea77 100644 --- a/tests/markdown/mustache-span.test.js +++ b/tests/markdown/mustache-span.test.js @@ -105,6 +105,22 @@ test('Renders a mustache span with text, id, class and a couple of css propertie expect(rendered).toBe('text'); }); +test('Two consecutive injections into Inline', function() { + const source = '{{dog Sample Text}}{cat}{toad}'; + const rendered = Markdown.render(source); + // FIXME: Drops original attributes in favor of injection, rather than adding. + // FIXME: Doesn't keep the raw text of second injection. + // FIXME: Renders the extra class attribute (which is dropped by the browser). + expect(rendered).toBe('

Sample Text

\n'); +}); + +test('Two consecutive injections into Block', function() { + const source = '{{dog\nSample Text\n}}\n{cat}\n{toad}'; + const rendered = Markdown.render(source); + // FIXME: Renders the extra class attribute (which is dropped by the browser). + expect(rendered).toBe('

Sample Text

\n

{toad}

\n'); +}); + // TODO: add tests for ID with accordance to CSS spec: // // From https://drafts.csswg.org/selectors/#id-selectors: From 48227eaf7188031c13fbbbd8178d38b8806e85b0 Mon Sep 17 00:00:00 2001 From: Trevor Buckner Date: Tue, 4 Apr 2023 12:18:57 -0400 Subject: [PATCH 3/3] Remove Console.log and lint --- shared/naturalcrit/markdown.js | 1 - themes/V3/Blank/snippets/imageMask.gen.js | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/shared/naturalcrit/markdown.js b/shared/naturalcrit/markdown.js index 50bbfe827..1960776d3 100644 --- a/shared/naturalcrit/markdown.js +++ b/shared/naturalcrit/markdown.js @@ -169,7 +169,6 @@ const mustacheInjectBlock = { const match = inlineRegex.exec(src); if(match) { const lastToken = tokens[tokens.length - 1]; - console.log(lastToken); if(!lastToken || lastToken.type == 'mustacheInjectBlock') return false; diff --git a/themes/V3/Blank/snippets/imageMask.gen.js b/themes/V3/Blank/snippets/imageMask.gen.js index 5ddef7a2a..cae4bf69a 100644 --- a/themes/V3/Blank/snippets/imageMask.gen.js +++ b/themes/V3/Blank/snippets/imageMask.gen.js @@ -2,7 +2,7 @@ const _ = require('lodash'); const dedent = require('dedent-tabs').default; module.exports = { - center :()=>{ + center : ()=>{ return dedent` {{imageMaskCenter${_.random(1, 16)},--offsetX:0%,--offsetY:0%,--rotation:0; ![](https://i.imgur.com/GZfjDWV.png){height:100%}