From a79e6bc13ba6711e9ded30996b87d3eb5b4ded98 Mon Sep 17 00:00:00 2001
From: sup39
Date: Thu, 14 Jan 2021 19:45:25 +0900
Subject: [PATCH] consider silent
---
index.js | 21 ++++++++++++---------
package.json | 2 +-
test/cases/attrs.txt | 8 ++++++++
3 files changed, 21 insertions(+), 10 deletions(-)
diff --git a/index.js b/index.js
index 71eaf81..c48a8f5 100644
--- a/index.js
+++ b/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;
});
};
diff --git a/package.json b/package.json
index 46781a4..bed0763 100644
--- a/package.json
+++ b/package.json
@@ -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",
diff --git a/test/cases/attrs.txt b/test/cases/attrs.txt
index d75c40e..5a40da7 100644
--- a/test/cases/attrs.txt
+++ b/test/cases/attrs.txt
@@ -28,3 +28,11 @@ nested
.
1
2 ab cde 3
4
.
+
+
+nested link
+.
+[some link like [sup39's homepage](https://sup39.ml)]{.class}
+.
+some link like sup39's homepage
+.