0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2025-12-29 09:02:37 +00:00

Merge pull request #2752 from Gazook89/Injection-Blocks-Take-3

Prevent Injection if preceded by another Injection token
This commit is contained in:
Trevor Buckner
2023-04-04 12:19:13 -04:00
committed by GitHub
2 changed files with 18 additions and 2 deletions

View File

@@ -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,7 @@ const mustacheInjectBlock = {
const match = inlineRegex.exec(src);
if(match) {
const lastToken = tokens[tokens.length - 1];
if(!lastToken)
if(!lastToken || lastToken.type == 'mustacheInjectBlock')
return false;
lastToken.originalType = 'mustacheInjectBlock';

View File

@@ -105,6 +105,22 @@ test('Renders a mustache span with text, id, class and a couple of css propertie
expect(rendered).toBe('<span class="inline-block pen" id="author" style="color:orange; font-family:trebuchet ms;">text</span>');
});
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('<p><span class=" cat" class="inline-block cat" >Sample Text</span></p>\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('<div class=" cat" class="block cat" ><p>Sample Text</p>\n</div><p>{toad}</p>\n');
});
// TODO: add tests for ID with accordance to CSS spec:
//
// From https://drafts.csswg.org/selectors/#id-selectors: