Skip to content

Commit

Permalink
Fix parsing delimiters inside links
Browse files Browse the repository at this point in the history
In markdown-it 9.1.0 and earlier, all delimiter info was stored in
StateInline.delimiters, and `level` property was used to distinguish
between delimiters nested inside other inline tags.

Now `level` property is gone. All delimiters that would have level
greater than zero are now stored in separate array located in
StateInline.tokens_meta.
  • Loading branch information
rlidwka committed Sep 4, 2019
1 parent b363ae8 commit 3101021
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
23 changes: 18 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,13 @@ module.exports = function ins_plugin(md) {
token = state.push('text', '', 0);
token.content = ch + ch;

if (!scanned.can_open && !scanned.can_close) { continue; }

state.delimiters.push({
marker: marker,
length: 0, // disable "rule of 3" length checks meant for emphasis
jump: i,
token: state.tokens.length - 1,
level: state.level,
end: -1,
open: scanned.can_open,
close: scanned.can_close
Expand All @@ -48,14 +50,13 @@ module.exports = function ins_plugin(md) {

// Walk through delimiter list and replace text tokens with tags
//
function postProcess(state) {
function postProcess(state, delimiters) {
var i, j,
startDelim,
endDelim,
token,
loneMarkers = [],
delimiters = state.delimiters,
max = state.delimiters.length;
max = delimiters.length;

for (i = 0; i < max; i++) {
startDelim = delimiters[i];
Expand Down Expand Up @@ -116,5 +117,17 @@ module.exports = function ins_plugin(md) {
}

md.inline.ruler.before('emphasis', 'mark', tokenize);
md.inline.ruler2.before('emphasis', 'mark', postProcess);
md.inline.ruler2.before('emphasis', 'mark', function (state) {
var curr,
tokens_meta = state.tokens_meta,
max = (state.tokens_meta || []).length;

postProcess(state, state.delimiters);

for (curr = 0; curr < max; curr++) {
if (tokens_meta[curr] && tokens_meta[curr].delimiters) {
postProcess(state, tokens_meta[curr].delimiters);
}
}
});
};
8 changes: 8 additions & 0 deletions test/fixtures/mark.txt
Original file line number Diff line number Diff line change
Expand Up @@ -124,3 +124,11 @@ a=="foo"==
.
<p>a==&quot;foo&quot;==</p>
.


Should parse delimiters inside links:
.
[==foo==]()
.
<p><a href=""><mark>foo</mark></a></p>
.

0 comments on commit 3101021

Please sign in to comment.