Skip to content

Commit e3d8e54

Browse files
committed
fix(plugins) Properly render inline blocks as HTML span
Signed-off-by: Jerome Simeon <[email protected]>
1 parent 50f8698 commit e3d8e54

File tree

7 files changed

+17
-15
lines changed

7 files changed

+17
-15
lines changed

packages/markdown-it-template/lib/index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ const variable_inline = function (tokens, idx /*, options, env */) {
4747
return `<span class="variable" ${attrs}>${name}</span>`;
4848
};
4949

50+
const else_inline = function (tokens, idx /*, options, env */) {
51+
return `</span><span class="else">`;
52+
};
53+
5054
const formula_inline = function (tokens, idx /*, options, env */) {
5155
const token = tokens[idx];
5256
return `<span class="formula">${token.content}</span>`;
@@ -62,6 +66,7 @@ function template_plugin(md) {
6266
md.renderer.rules['inline_block_with_close'] = template_inline_render('with');
6367
md.renderer.rules['inline_block_join_open'] = template_inline_render('join');
6468
md.renderer.rules['inline_block_join_close'] = template_inline_render('join');
69+
md.renderer.rules['inline_block_else'] = else_inline;
6570
md.renderer.rules['variable'] = variable_inline;
6671
md.renderer.rules['formula'] = formula_inline;
6772

packages/markdown-it-template/lib/template_inline.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ function template_inline(state, silent) {
5353
if (block !== 'if' && block !== 'optional' && block !== 'with' && block !== 'join') {
5454
return false;
5555
}
56-
token = state.push('inline_block_' + block + '_open', 'div', 1);
56+
token = state.push('inline_block_' + block + '_open', 'span', 1);
5757
token.content = match[0];
5858
token.attrs = attrs;
5959

@@ -71,7 +71,7 @@ function template_inline(state, silent) {
7171
return false;
7272
}
7373

74-
token = state.push('inline_block_' + block + '_close', 'div', -1);
74+
token = state.push('inline_block_' + block + '_close', 'span', -1);
7575
token.content = match[1];
7676
state.pos += match[0].length;
7777

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<h1>Title</h1>
2-
<p>Paragraph with a <span class="variable" name="seller">seller</span> and more text and<div name="forceMajeure" class="if_inline">, this is conditional,</div> with some <strong>marker</strong> <span class="formula"> 1+1 = 3 </span>. <div name="foo" separator=";" class="join_inline"><span class="variable" name="element">element</span></div></p>
3-
<p>Paragraph with a <span class="variable" name="seller">seller</span> and more text and<div name="forceMajeure" class="if_inline">, this is conditional,<else> and this is too,</div> with some <strong>marker</strong> <span class="formula"> 1+1 = 3 </span>. <div name="foo" class="join_inline"><span class="variable" name="element">element</span></div></p>
2+
<p>Paragraph with a <span class="variable" name="seller">seller</span> and more text and<span name="forceMajeure" class="if_inline">, this is conditional,</span> with some <strong>marker</strong> <span class="formula"> 1+1 = 3 </span>. <span name="foo" separator=";" class="join_inline"><span class="variable" name="element">element</span></span></p>
3+
<p>Paragraph with a <span class="variable" name="seller">seller</span> and more text and<span name="forceMajeure" class="if_inline">, this is conditional,</span><span class="else"> and this is too,</span> with some <strong>marker</strong> <span class="formula"> 1+1 = 3 </span>. <span name="foo" class="join_inline"><span class="variable" name="element">element</span></span></p>
44
<p><span class="variable" name="buyer" format="FOO">buyer</span></p>
55
<div name="payment" src="ap://[email protected]#b4c966c2081303d017d3dde359bd8039ceb4a5dbacb6e6e09618e33a00d3f566" class="clause_block">
66
<p>BLABLABLABLA</p>
@@ -16,12 +16,11 @@ <h1>Title</h1>
1616
<li>three</li>
1717
</ul>
1818
</div>
19-
<p>There is also a new <div name="name" class="optional_inline"> inline which can contain <this></div>.</p>
20-
<p>There is also a new <div name="name" class="optional_inline"> inline which can contain <this><else>something else</div>.</p>
19+
<p>There is also a new <span name="name" class="optional_inline"> inline which can contain <this></span>.</p>
20+
<p>There is also a new <span name="name" class="optional_inline"> inline which can contain <this></span><span class="else">something else</span>.</p>
2121
<p>This is a <a href="mylink">link with a <span class="variable" name="variable">variable</span> in it</a>.</p>
2222
<p>This is a <a href="mylink">link with a <this> in it</a>.</p>
23-
<p>This is a <a href="mylink">link with an <else> in it</a>.</p>
24-
<p>This is a <a href="mylink">link with an <div name="name" class="if_inline"> in it</div></a>.</p>
25-
<p>This is a <a href="mylink">link with an <div name="name" class="optional_inline"> in it</div></a>.</p>
26-
<p>This is a <a href="mylink">link with a <div name="name" class="join_inline"> in it</div></a>.</p>
23+
<p>This is a <a href="mylink">link with an <span name="name" class="if_inline"> in it</span></a>.</p>
24+
<p>This is a <a href="mylink">link with an <span name="name" class="optional_inline"> in it</span></a>.</p>
25+
<p>This is a <a href="mylink">link with a <span name="name" class="join_inline"> in it</span></a>.</p>
2726
<p>This is a <a href="mylink">link with a <span class="formula"> formula </span> in it</a>.</p>

packages/markdown-it-template/test/data/all.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

packages/markdown-it-template/test/data/all.tem.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@ This is a [link with a {{variable}} in it](mylink).
3232

3333
This is a [link with a {{this}} in it](mylink).
3434

35-
This is a [link with an {{else}} in it](mylink).
36-
3735
This is a [link with an {{#if name}} in it{{/if}}](mylink).
3836

3937
This is a [link with an {{#optional name}} in it{{/optional}}](mylink).

packages/markdown-it-template/test/data/none.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<h1>Title</h1>
2-
<p>Paragraph with a {seller}} and more text and<div name="forceMajeure" class="if_inline">, this is optional,</div> with some <strong>marker</strong> {{% % 1+1 = 3 %}}.</p>
2+
<p>Paragraph with a {seller}} and more text and<span name="forceMajeure" class="if_inline">, this is optional,</span> with some <strong>marker</strong> {{% % 1+1 = 3 %}}.</p>
33
<p><span class="variable" name="buyer" format="FOO">buyer</span></p>
44
<p>{#clause payment}}
55
BLABLABLABLA</p>

packages/markdown-it-template/test/data/none.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)