Skip to content

Commit

Permalink
fix(render) templatemark plugin render properly handles {{this}}
Browse files Browse the repository at this point in the history
Signed-off-by: Jerome Simeon <[email protected]>
  • Loading branch information
jeromesimeon committed Aug 7, 2020
1 parent 5a3578b commit 446b4dc
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
5 changes: 5 additions & 0 deletions packages/markdown-it-template/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ const variable_inline = function (tokens, idx /*, options, env */) {
return `<span class="variable" ${attrs}>${name}</span>`;
};

const this_inline = function (tokens, idx /*, options, env */) {
return `<span class="variable" name="this">this</span>`;
};

const else_inline = function (tokens, idx /*, options, env */) {
return `</span><span class="else_inline">`;
};
Expand All @@ -68,6 +72,7 @@ function template_plugin(md) {
md.renderer.rules['inline_block_join_close'] = template_inline_render('join');
md.renderer.rules['inline_block_else'] = else_inline;
md.renderer.rules['variable'] = variable_inline;
md.renderer.rules['this'] = this_inline;
md.renderer.rules['formula'] = formula_inline;

md.block.ruler.before('fence', 'template_block', template_block, {
Expand Down
6 changes: 3 additions & 3 deletions packages/markdown-it-template/test/data/all.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ <h1>Title</h1>
<li>three</li>
</ul>
</div>
<p>There is also a new <span name="name" class="optional_inline"> inline which can contain <this></span>.</p>
<p>There is also a new <span name="name" class="optional_inline"> inline which can contain <this></span><span class="else_inline">something else</span>.</p>
<p>There is also a new <span name="name" class="optional_inline"> inline which can contain <span class="variable" name="this">this</span></span>.</p>
<p>There is also a new <span name="name" class="optional_inline"> inline which can contain <span class="variable" name="this">this</span></span><span class="else_inline">something else</span>.</p>
<p>This is a <a href="mylink">link with a <span class="variable" name="variable">variable</span> in it</a>.</p>
<p>This is a <a href="mylink">link with a <this> in it</a>.</p>
<p>This is a <a href="mylink">link with a <span class="variable" name="this">this</span> in it</a>.</p>
<p>This is a <a href="mylink">link with an <span name="name" class="if_inline"> in it</span></a>.</p>
<p>This is a <a href="mylink">link with an <span name="name" class="optional_inline"> in it</span></a>.</p>
<p>This is a <a href="mylink">link with a <span name="name" class="join_inline"> in it</span></a>.</p>
Expand Down

0 comments on commit 446b4dc

Please sign in to comment.