Skip to content

Commit 16148b2

Browse files
authored
Desktop: Fixes laurent22#5808: Scrolling was out of sync when a Multi Markdown Table was being used (laurent22#5815)
1 parent df14ffd commit 16148b2

File tree

2 files changed

+47
-1
lines changed

2 files changed

+47
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
diff --git a/index.js b/index.js
2+
index 85d89900d5fe575dd0c19430209fb1703b03554e..5fa68cc9a4bd2b21a7188bd263262fd9b1604ac6 100644
3+
--- a/index.js
4+
+++ b/index.js
5+
@@ -145,7 +145,8 @@ module.exports = function multimd_table_plugin(md, options) {
6+
colspan, leftToken,
7+
rowspan, upTokens = [],
8+
tableLines, tgroupLines,
9+
- tag, text, range, r, c, b;
10+
+ tag, text, range, r, c, b, t,
11+
+ blockState;
12+
13+
if (startLine + 2 > endLine) { return false; }
14+
15+
@@ -315,18 +316,26 @@ module.exports = function multimd_table_plugin(md, options) {
16+
17+
/* Multiline. Join the text and feed into markdown-it blockParser. */
18+
if (options.multiline && trToken.meta.multiline && trToken.meta.mbounds) {
19+
- text = [ text.trimRight() ];
20+
+ // Pad the text with empty lines to ensure the line number mapping is correct
21+
+ text = new Array(trToken.map[0]).fill('').concat([ text.trimRight() ]);
22+
for (b = 1; b < trToken.meta.mbounds.length; b++) {
23+
/* Line with N bounds has cells indexed from 0 to N-2 */
24+
if (c > trToken.meta.mbounds[b].length - 2) { continue; }
25+
range = [ trToken.meta.mbounds[b][c] + 1, trToken.meta.mbounds[b][c + 1] ];
26+
text.push(state.src.slice.apply(state.src, range).trimRight());
27+
}
28+
- state.md.block.parse(text.join('\n'), state.md, state.env, state.tokens);
29+
+ blockState = new state.md.block.State(text.join('\n'), state.md, state.env, []);
30+
+ blockState.level = trToken.level + 1;
31+
+ // Start tokenizing from the actual content (trToken.map[0])
32+
+ state.md.block.tokenize(blockState, trToken.map[0], blockState.lineMax);
33+
+ for (t = 0; t < blockState.tokens.length; t++) {
34+
+ state.tokens.push(blockState.tokens[t]);
35+
+ }
36+
} else {
37+
token = state.push('inline', '', 0);
38+
token.content = text.trim();
39+
token.map = trToken.map;
40+
+ token.level = trToken.level + 1;
41+
token.children = [];
42+
}
43+

package.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -78,5 +78,8 @@
7878
"node-gyp": "^8.4.1",
7979
"nodemon": "^2.0.9"
8080
},
81-
"packageManager": "[email protected]"
81+
"packageManager": "[email protected]",
82+
"resolutions": {
83+
"[email protected]": "patch:markdown-it-multimd-table@npm:4.1.1#.yarn/patches/markdown-it-multimd-table-npm-4.1.1-47e334d4bd"
84+
}
8285
}

0 commit comments

Comments
 (0)