|
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 */ |
2 | 2 | (function(global, factory) { |
3 | 3 | typeof exports === "object" && typeof module !== "undefined" ? module.exports = factory() : typeof define === "function" && define.amd ? define(factory) : (global = typeof globalThis !== "undefined" ? globalThis : global || self, |
4 | 4 | global.markdownit = factory()); |
5 | 5 | })(this, (function() { |
6 | 6 | "use strict"; |
7 | | - var commonjsGlobal = typeof globalThis !== "undefined" ? globalThis : typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : {}; |
8 | 7 | function createCommonjsModule(fn, basedir, module) { |
9 | 8 | return module = { |
10 | 9 | path: basedir, |
|
2893 | 2892 |
|
2894 | 2893 | return str.toLowerCase().toUpperCase(); |
2895 | 2894 | } |
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; |
2909 | 2899 | } 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; |
2920 | 2901 | } |
2921 | | - resultsMap.set(tokenIdx, lineOffset); |
2922 | | - return lineOffset; |
2923 | 2902 | } |
2924 | 2903 | function trimLeftOffset(str) { |
2925 | 2904 | return str.length - str.trimLeft().length; |
|
4805 | 4784 | state.lineMax = oldLineMax; |
4806 | 4785 | state.parentType = oldParentType; |
4807 | 4786 | lines[1] = state.line; |
| 4787 | + let totalLineOffset = 0; |
4808 | 4788 | // Restore original tShift; this might not be necessary since the parser |
4809 | 4789 | // has already been here, but just to make sure we can do that. |
4810 | 4790 | 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]; |
4815 | 4804 | } |
4816 | 4805 | state.blkIndent = oldIndent; |
4817 | 4806 | return true; |
4818 | 4807 | }; |
| 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 | + } |
4819 | 4815 | var isSpace$8 = utils.isSpace; |
4820 | 4816 | var hr = function hr(state, startLine, endLine, silent) { |
4821 | 4817 | var marker, cnt, ch, token, originalPos, pos = state.bMarks[startLine] + state.tShift[startLine], max = state.eMarks[startLine]; |
|
5485 | 5481 | } |
5486 | 5482 | if (!level) { |
5487 | 5483 | // Didn't find valid underline |
| 5484 | + state.parentType = oldParentType; |
5488 | 5485 | return false; |
5489 | 5486 | } |
5490 | 5487 | const originalContent = state.getLines(startLine, nextLine, state.blkIndent, false); |
|
5580 | 5577 | // offsets of the first non-space characters (tabs not expanded) |
5581 | 5578 | this.sCount = []; |
5582 | 5579 | // indents for each line (tabs expanded) |
| 5580 | + this.lineOffsets = []; |
5583 | 5581 | // An amount of virtual spaces (tabs expanded) between beginning |
5584 | 5582 | // of each line (bMarks) and real beginning of that line. |
5585 | 5583 |
|
|
5639 | 5637 | this.tShift.push(indent); |
5640 | 5638 | this.sCount.push(offset); |
5641 | 5639 | this.bsCount.push(0); |
| 5640 | + this.lineOffsets.push(null); |
5642 | 5641 | indent_found = false; |
5643 | 5642 | indent = 0; |
5644 | 5643 | offset = 0; |
|
5651 | 5650 | this.tShift.push(0); |
5652 | 5651 | this.sCount.push(0); |
5653 | 5652 | this.bsCount.push(0); |
| 5653 | + this.lineOffsets.push(null); |
5654 | 5654 | this.lineMax = this.bMarks.length - 1; |
5655 | 5655 | // don't count last fake line |
5656 | 5656 | } |
|
5936 | 5936 | token.position = pos; |
5937 | 5937 | } |
5938 | 5938 | } |
| 5939 | + state.currentLine += 1; |
5939 | 5940 | pos++; |
5940 | 5941 | // skip heading spaces for next line |
5941 | 5942 | while (pos < max && isSpace$3(state.src.charCodeAt(pos))) { |
|
6040 | 6041 | state.pos += openerLength; |
6041 | 6042 | return true; |
6042 | 6043 | }; |
6043 | | - var getLineOffset$2 = utils.getLineOffset; |
| 6044 | + // ~~strike through~~ |
6044 | 6045 | // Insert each marker as a separate text token, and add it to delimiter list |
6045 | 6046 |
|
6046 | 6047 | var tokenize$1 = function strikethrough(state, silent) { |
|
6098 | 6099 | token.nesting = 1; |
6099 | 6100 | token.markup = "~~"; |
6100 | 6101 | token.content = ""; |
6101 | | - token.position = startDelim.position + getLineOffset$2(state, startDelim.token); |
| 6102 | + token.position = startDelim.position; |
6102 | 6103 | token = state.tokens[endDelim.token]; |
6103 | 6104 | token.type = "s_close"; |
6104 | 6105 | token.tag = "s"; |
|
6144 | 6145 | tokenize: tokenize$1, |
6145 | 6146 | postProcess: postProcess_1$1 |
6146 | 6147 | }; |
6147 | | - var getLineOffset$1 = utils.getLineOffset; |
| 6148 | + // Process *this* and _that_ |
6148 | 6149 | // Insert each marker as a separate text token, and add it to delimiter list |
6149 | 6150 |
|
6150 | 6151 | var tokenize = function emphasis(state, silent) { |
|
6210 | 6211 | token.nesting = 1; |
6211 | 6212 | token.markup = isStrong ? ch + ch : ch; |
6212 | 6213 | token.content = ""; |
6213 | | - token.position = startDelim.position + getLineOffset$1(state, startDelim.token); |
| 6214 | + token.position = startDelim.position; |
6214 | 6215 | token = state.tokens[endDelim.token]; |
6215 | 6216 | token.type = isStrong ? "strong_close" : "em_close"; |
6216 | 6217 | token.tag = isStrong ? "strong" : "em"; |
|
6757 | 6758 | } |
6758 | 6759 | }); |
6759 | 6760 | this.pendingLevel = 0; |
| 6761 | + this.currentLine = env.parentToken.map[0]; |
6760 | 6762 | // Stores { start: end } pairs. Useful for backtrack |
6761 | 6763 | // optimization of pairs parse (emphasis, strikes). |
6762 | 6764 | this.cache = {}; |
|
0 commit comments