diff --git a/package.json b/package.json index df7f700ef..a30a986b0 100644 --- a/package.json +++ b/package.json @@ -27,10 +27,10 @@ "test:dev": "jest --verbose --watch", "test:basic": "jest tests/markdown/basic.test.js --verbose", "test:variables": "jest tests/markdown/variables.test.js --verbose", - "test:mustache-syntax": "jest '.*(mustache-syntax).*' --verbose --noStackTrace", - "test:mustache-syntax:inline": "jest '.*(mustache-syntax).*' -t '^Inline:.*' --verbose --noStackTrace", - "test:mustache-syntax:block": "jest '.*(mustache-syntax).*' -t '^Block:.*' --verbose --noStackTrace", - "test:mustache-syntax:injection": "jest '.*(mustache-syntax).*' -t '^Injection:.*' --verbose --noStackTrace", + "test:mustache-syntax": "jest .*(mustache-syntax).* --verbose --noStackTrace", + "test:mustache-syntax:inline": "jest .*(mustache-syntax).* -t '^Inline:.*' --verbose --noStackTrace", + "test:mustache-syntax:block": "jest .*(mustache-syntax).* -t '^Block:.*' --verbose --noStackTrace", + "test:mustache-syntax:injection": "jest .*(mustache-syntax).* -t '^Injection:.*' --verbose --noStackTrace", "test:definition-lists": "jest tests/markdown/definition-lists.test.js --verbose --noStackTrace", "test:route": "jest tests/routes/static-pages.test.js --verbose", "phb": "node scripts/phb.js", diff --git a/shared/naturalcrit/markdown.js b/shared/naturalcrit/markdown.js index d93f73cea..33bae12d6 100644 --- a/shared/naturalcrit/markdown.js +++ b/shared/naturalcrit/markdown.js @@ -241,7 +241,7 @@ const mustacheInjectInline = { `${tags.classes ? ` class="${tags.classes}"` : ''}` + `${tags.id ? ` id="${tags.id}"` : ''}` + `${tags.styles ? ` style="${tags.styles}"` : ''}` + - `${tags.attributes ? ` ${Object.entries(tags.attributes).map(([key, value]) => `${key}="${value}"`).join(' ')}` : ''}` + + `${!_.isEmpty(tags.attributes) ? ` ${Object.entries(tags.attributes).map(([key, value]) => `${key}="${value}"`).join(' ')}` : ''}` + `${openingTag[2]}`; // parse to turn child tokens into HTML } return text; @@ -290,7 +290,7 @@ const mustacheInjectBlock = { `${tags.classes ? ` class="${tags.classes}"` : ''}` + `${tags.id ? ` id="${tags.id}"` : ''}` + `${tags.styles ? ` style="${tags.styles}"` : ''}` + - `${tags.attributes ? ` ${Object.entries(tags.attributes).map(([key, value]) => `${key}="${value}"`).join(' ')}` : ''}` + + `${!_.isEmpty(tags.attributes) ? ` ${Object.entries(tags.attributes).map(([key, value]) => `${key}="${value}"`).join(' ')}` : ''}` + `${openingTag[2]}`; // parse to turn child tokens into HTML } return text; diff --git a/tests/markdown/mustache-syntax.test.js b/tests/markdown/mustache-syntax.test.js index f156771cb..d1d64a9de 100644 --- a/tests/markdown/mustache-syntax.test.js +++ b/tests/markdown/mustache-syntax.test.js @@ -243,13 +243,13 @@ describe(`Block: When using the Block syntax {{tags\\ntext\\n}}`, ()=>{ describe('Injection: When an injection tag follows an element', ()=>{ // FIXME: Most of these fail because injections currently replace attributes, rather than append to. Or just minor extra whitespace issues. describe('and that element is an inline-block', ()=>{ - it.failing('Renders a span "text" with no injection', function() { + it('Renders a span "text" with no injection', function() { const source = '{{ text}}{}'; const rendered = Markdown.render(source); expect(rendered, `Input:\n${source}`, { showPrefix: false }).toBe('text'); }); - it.failing('Renders a span "text" with injected Class name', function() { + it('Renders a span "text" with injected Class name', function() { const source = '{{ text}}{ClassName}'; const rendered = Markdown.render(source); expect(rendered, `Input:\n${source}`, { showPrefix: false }).toBe('text'); @@ -261,31 +261,31 @@ describe('Injection: When an injection tag follows an element', ()=>{ expect(rendered, `Input:\n${source}`, { showPrefix: false }).toBe('text'); }); - it.failing('Renders a span "text" with injected style', function() { + it('Renders a span "text" with injected style', function() { const source = '{{ text}}{color:red}'; const rendered = Markdown.render(source); expect(rendered, `Input:\n${source}`, { showPrefix: false }).toBe('text'); }); - it.failing('Renders a span "text" with injected style using a string variable', function() { + it('Renders a span "text" with injected style using a string variable', function() { const source = `{{ text}}{--stringVariable:"'string'"}`; const rendered = Markdown.render(source); expect(rendered, `Input:\n${source}`, { showPrefix: false }).toBe(`text`); }); - it.failing('Renders a span "text" with two injected styles', function() { + it('Renders a span "text" with two injected styles', function() { const source = '{{ text}}{color:red,background:blue}'; const rendered = Markdown.render(source); expect(rendered, `Input:\n${source}`, { showPrefix: false }).toBe('text'); }); - it.failing('Renders an emphasis element with injected Class name', function() { + it('Renders an emphasis element with injected Class name', function() { const source = '*emphasis*{big}'; const rendered = Markdown.render(source).trimReturns(); expect(rendered, `Input:\n${source}`, { showPrefix: false }).toBe('

emphasis

'); }); - it.failing('Renders a code element with injected style', function() { + it('Renders a code element with injected style', function() { const source = '`code`{background:gray}'; const rendered = Markdown.render(source).trimReturns(); expect(rendered, `Input:\n${source}`, { showPrefix: false }).toBe('

code

'); @@ -311,19 +311,19 @@ describe('Injection: When an injection tag follows an element', ()=>{ }); describe('and that element is a block', ()=>{ - it.failing('renders a div "text" with no injection', function() { + it('renders a div "text" with no injection', function() { const source = '{{\ntext\n}}\n{}'; const rendered = Markdown.render(source).trimReturns(); expect(rendered, `Input:\n${source}`, { showPrefix: false }).toBe('

text

'); }); - it.failing('renders a div "text" with injected Class name', function() { + it('renders a div "text" with injected Class name', function() { const source = '{{\ntext\n}}\n{ClassName}'; const rendered = Markdown.render(source).trimReturns(); expect(rendered, `Input:\n${source}`, { showPrefix: false }).toBe('

text

'); }); - it.failing('renders a div "text" with injected style', function() { + it('renders a div "text" with injected style', function() { const source = '{{\ntext\n}}\n{color:red}'; const rendered = Markdown.render(source).trimReturns(); expect(rendered, `Input:\n${source}`, { showPrefix: false }).toBe('

text

'); @@ -354,7 +354,7 @@ describe('Injection: When an injection tag follows an element', ()=>{ expect(rendered, `Input:\n${source}`, { showPrefix: false }).toBe('

text

'); }); - it.failing('renders a table with injected class name', function() { + it('renders a table with injected class name', function() { const source = dedent`| Experience Points | Level | |:------------------|:-----:| | 0 | 1 | @@ -384,7 +384,7 @@ describe('Injection: When an injection tag follows an element', ()=>{ expect(rendered, `Input:\n${source}`, { showPrefix: false }).toBe('

text

{secondInjection}

'); }); - it.failing('renders a div nested into another div, the inner with class=innerDiv and the other class=outerDiv', function() { + it('renders a div nested into another div, the inner with class=innerDiv and the other class=outerDiv', function() { const source = dedent`{{ outer text {{