consider silent
This commit is contained in:
parent
ddbcb9d0f3
commit
a79e6bc13b
3 changed files with 21 additions and 10 deletions
21
index.js
21
index.js
|
@ -5,7 +5,7 @@
|
|||
function pluginInlineTag(md, opts={}) {
|
||||
const alias = opts.alias || {};
|
||||
const defaultTag = alias[''] || 'span';
|
||||
md.inline.ruler.before('escape', 'inline_tag', (state, a) => {
|
||||
md.inline.ruler.before('escape', 'inline_tag', (state, silent) => {
|
||||
const {src, pos, posMax} = state;
|
||||
const c0 = src.charCodeAt(pos);
|
||||
let posS;
|
||||
|
@ -41,15 +41,18 @@ function pluginInlineTag(md, opts={}) {
|
|||
const posE = i;
|
||||
// []{} without ()
|
||||
if (c0 === 0x5b && src.charCodeAt(posE+1) !== 0x7b) return false;
|
||||
// parse tag content
|
||||
state.pos = posS;
|
||||
state.posMax = posE;
|
||||
state.push('tag_open', tagName, 1);
|
||||
state.md.inline.tokenize(state);
|
||||
state.push('tag_close', tagName, -1);
|
||||
// end
|
||||
// parse tag content if not silent
|
||||
if (!silent) {
|
||||
state.pos = posS;
|
||||
state.posMax = posE;
|
||||
if (!silent) state.push('tag_open', tagName, 1);
|
||||
state.md.inline.tokenize(state, silent);
|
||||
if (!silent) state.push('tag_close', tagName, -1);
|
||||
// end
|
||||
state.posMax = posMax;
|
||||
}
|
||||
// set state.pos only if silent
|
||||
state.pos = posE+1;
|
||||
state.posMax = posMax;
|
||||
return true;
|
||||
});
|
||||
};
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@sup39/markdown-it-inline-tag",
|
||||
"version": "1.0.0",
|
||||
"version": "1.0.1",
|
||||
"description": "A markdown-it plugin to write inline tag",
|
||||
"keywords": [
|
||||
"markdown",
|
||||
|
|
|
@ -28,3 +28,11 @@ nested
|
|||
.
|
||||
<p>1 <div class="c">2 <span class="a">ab</span> c<em class="b">d</em>e 3</div> 4</p>
|
||||
.
|
||||
|
||||
|
||||
nested link
|
||||
.
|
||||
[some link like [sup39's homepage](https://sup39.ml)]{.class}
|
||||
.
|
||||
<p><span class="class">some link like <a href="https://sup39.ml">sup39's homepage</a></span></p>
|
||||
.
|
||||
|
|
Reference in a new issue