Skip to content

Commit 2ef5961

Browse files
committed
chore: bump version to 12.0.20
1 parent d226ca6 commit 2ef5961

File tree

4 files changed

+43
-41
lines changed

4 files changed

+43
-41
lines changed

dist/markdown-it.js

Lines changed: 37 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
/*! @hackmd/markdown-it 12.0.19 https://github.com/hackmdio/markdown-it @license MIT */
1+
/*! @hackmd/markdown-it 12.0.20 https://github.com/hackmdio/markdown-it @license MIT */
22
(function(global, factory) {
33
typeof exports === "object" && typeof module !== "undefined" ? module.exports = factory() : typeof define === "function" && define.amd ? define(factory) : (global = typeof globalThis !== "undefined" ? globalThis : global || self,
44
global.markdownit = factory());
55
})(this, (function() {
66
"use strict";
7-
var commonjsGlobal = typeof globalThis !== "undefined" ? globalThis : typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : {};
87
function createCommonjsModule(fn, basedir, module) {
98
return module = {
109
path: basedir,
@@ -2893,33 +2892,13 @@
28932892

28942893
return str.toLowerCase().toUpperCase();
28952894
}
2896-
/* eslint-env browser */ var _g = typeof commonjsGlobal !== "undefined" ? commonjsGlobal : window;
2897-
var tokensRef = new _g.WeakMap;
2898-
// TODO: performance tweaks for emphasis **_* pattern which has only 1/10 performance after adding line offset
2899-
function getLineOffset(state, tokenIdx) {
2900-
var blockState = state.env.state_block;
2901-
var parentToken = state.env.parentToken;
2902-
var tokensBefore = typeof tokenIdx !== "undefined" ? state.tokens.slice(0, tokenIdx) : state.tokens;
2903-
var resultsMap = tokensRef.get(state.tokens);
2904-
if (resultsMap) {
2905-
var cachedResult = resultsMap.get(tokenIdx);
2906-
if (typeof cachedResult !== "undefined") {
2907-
return cachedResult;
2908-
}
2895+
function getLineOffset(state) {
2896+
if (state.env.parentToken.parentType === "blockquote") {
2897+
const blockState = state.env.state_block;
2898+
return blockState.lineOffsets[state.currentLine] ?? 0;
29092899
} else {
2910-
resultsMap = new _g.Map;
2911-
tokensRef.set(state.tokens, resultsMap);
2912-
}
2913-
var linesBefore = tokensBefore.filter((function(t) {
2914-
return t.type === "softbreak" || t.type === "hardbreak";
2915-
})).length;
2916-
var lineOffset = 0;
2917-
for (var i = 0; i < linesBefore; i++) {
2918-
var startLine = i + parentToken.map[0] + 1;
2919-
lineOffset += blockState.tShift[startLine];
2900+
return 0;
29202901
}
2921-
resultsMap.set(tokenIdx, lineOffset);
2922-
return lineOffset;
29232902
}
29242903
function trimLeftOffset(str) {
29252904
return str.length - str.trimLeft().length;
@@ -4805,17 +4784,34 @@
48054784
state.lineMax = oldLineMax;
48064785
state.parentType = oldParentType;
48074786
lines[1] = state.line;
4787+
let totalLineOffset = 0;
48084788
// Restore original tShift; this might not be necessary since the parser
48094789
// has already been here, but just to make sure we can do that.
48104790
for (i = 0; i < oldTShift.length; i++) {
4811-
state.bMarks[i + startLine] = oldBMarks[i];
4812-
state.tShift[i + startLine] = oldTShift[i];
4813-
state.sCount[i + startLine] = oldSCount[i];
4814-
state.bsCount[i + startLine] = oldBSCount[i];
4791+
const lineNumber = i + startLine;
4792+
if (state.lineOffsets[lineNumber] === null) {
4793+
state.lineOffsets[lineNumber] = totalLineOffset;
4794+
if (isNotEmptyLine(state, lineNumber)) {
4795+
totalLineOffset += calcLineOffset(state, lineNumber);
4796+
} else {
4797+
totalLineOffset = 0;
4798+
}
4799+
}
4800+
state.bMarks[lineNumber] = oldBMarks[i];
4801+
state.tShift[lineNumber] = oldTShift[i];
4802+
state.sCount[lineNumber] = oldSCount[i];
4803+
state.bsCount[lineNumber] = oldBSCount[i];
48154804
}
48164805
state.blkIndent = oldIndent;
48174806
return true;
48184807
};
4808+
function calcLineOffset(state, lineNumber) {
4809+
const previousLineEnd = state.eMarks[lineNumber - 1] + 1 || 0;
4810+
return state.bMarks[lineNumber] - previousLineEnd;
4811+
}
4812+
function isNotEmptyLine(state, lineNumber) {
4813+
return state.bMarks[lineNumber] + state.tShift[lineNumber] < state.eMarks[lineNumber];
4814+
}
48194815
var isSpace$8 = utils.isSpace;
48204816
var hr = function hr(state, startLine, endLine, silent) {
48214817
var marker, cnt, ch, token, originalPos, pos = state.bMarks[startLine] + state.tShift[startLine], max = state.eMarks[startLine];
@@ -5485,6 +5481,7 @@
54855481
}
54865482
if (!level) {
54875483
// Didn't find valid underline
5484+
state.parentType = oldParentType;
54885485
return false;
54895486
}
54905487
const originalContent = state.getLines(startLine, nextLine, state.blkIndent, false);
@@ -5580,6 +5577,7 @@
55805577
// offsets of the first non-space characters (tabs not expanded)
55815578
this.sCount = [];
55825579
// indents for each line (tabs expanded)
5580+
this.lineOffsets = [];
55835581
// An amount of virtual spaces (tabs expanded) between beginning
55845582
// of each line (bMarks) and real beginning of that line.
55855583

@@ -5639,6 +5637,7 @@
56395637
this.tShift.push(indent);
56405638
this.sCount.push(offset);
56415639
this.bsCount.push(0);
5640+
this.lineOffsets.push(null);
56425641
indent_found = false;
56435642
indent = 0;
56445643
offset = 0;
@@ -5651,6 +5650,7 @@
56515650
this.tShift.push(0);
56525651
this.sCount.push(0);
56535652
this.bsCount.push(0);
5653+
this.lineOffsets.push(null);
56545654
this.lineMax = this.bMarks.length - 1;
56555655
// don't count last fake line
56565656
}
@@ -5936,6 +5936,7 @@
59365936
token.position = pos;
59375937
}
59385938
}
5939+
state.currentLine += 1;
59395940
pos++;
59405941
// skip heading spaces for next line
59415942
while (pos < max && isSpace$3(state.src.charCodeAt(pos))) {
@@ -6040,7 +6041,7 @@
60406041
state.pos += openerLength;
60416042
return true;
60426043
};
6043-
var getLineOffset$2 = utils.getLineOffset;
6044+
// ~~strike through~~
60446045
// Insert each marker as a separate text token, and add it to delimiter list
60456046

60466047
var tokenize$1 = function strikethrough(state, silent) {
@@ -6098,7 +6099,7 @@
60986099
token.nesting = 1;
60996100
token.markup = "~~";
61006101
token.content = "";
6101-
token.position = startDelim.position + getLineOffset$2(state, startDelim.token);
6102+
token.position = startDelim.position;
61026103
token = state.tokens[endDelim.token];
61036104
token.type = "s_close";
61046105
token.tag = "s";
@@ -6144,7 +6145,7 @@
61446145
tokenize: tokenize$1,
61456146
postProcess: postProcess_1$1
61466147
};
6147-
var getLineOffset$1 = utils.getLineOffset;
6148+
// Process *this* and _that_
61486149
// Insert each marker as a separate text token, and add it to delimiter list
61496150

61506151
var tokenize = function emphasis(state, silent) {
@@ -6210,7 +6211,7 @@
62106211
token.nesting = 1;
62116212
token.markup = isStrong ? ch + ch : ch;
62126213
token.content = "";
6213-
token.position = startDelim.position + getLineOffset$1(state, startDelim.token);
6214+
token.position = startDelim.position;
62146215
token = state.tokens[endDelim.token];
62156216
token.type = isStrong ? "strong_close" : "em_close";
62166217
token.tag = isStrong ? "strong" : "em";
@@ -6757,6 +6758,7 @@
67576758
}
67586759
});
67596760
this.pendingLevel = 0;
6761+
this.currentLine = env.parentToken.map[0];
67606762
// Stores { start: end } pairs. Useful for backtrack
67616763
// optimization of pairs parse (emphasis, strikes).
67626764
this.cache = {};

dist/markdown-it.min.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@hackmd/markdown-it",
3-
"version": "12.0.19",
3+
"version": "12.0.20",
44
"description": "Markdown-it - modern pluggable markdown parser.",
55
"keywords": [
66
"markdown",

0 commit comments

Comments
 (0)