You've already forked joplin
mirror of
https://github.com/laurent22/joplin.git
synced 2025-07-16 00:14:34 +02:00
This commit is contained in:
committed by
GitHub
parent
725abbc167
commit
630a400181
36
packages/renderer/MdToHtml/rules/source_map.ts
Normal file
36
packages/renderer/MdToHtml/rules/source_map.ts
Normal file
@ -0,0 +1,36 @@
|
||||
export default {
|
||||
plugin: (markdownIt: any, params: any) => {
|
||||
|
||||
if (!params.mapsToLine) return;
|
||||
|
||||
const allowedLevels = {
|
||||
paragraph_open: 0,
|
||||
heading_open: 0,
|
||||
// fence: 0, // fence uses custom rendering that doesn't propogate attr so it can't be used for now
|
||||
blockquote_open: 0,
|
||||
table_open: 0,
|
||||
code_block: 0,
|
||||
hr: 0,
|
||||
html_block: 0,
|
||||
list_item_open: 99, // this will stop matching if a list goes more than 99 indents deep
|
||||
math_block: 0,
|
||||
};
|
||||
|
||||
for (const [key, allowedLevel] of Object.entries(allowedLevels)) {
|
||||
const precedentRule = markdownIt.renderer.rules[key];
|
||||
|
||||
markdownIt.renderer.rules[key] = (tokens: any[], idx: number, options: any, env: any, self: any) => {
|
||||
if (!!tokens[idx].map && tokens[idx].level <= allowedLevel) {
|
||||
const line = tokens[idx].map[0];
|
||||
tokens[idx].attrJoin('class', 'maps-to-line');
|
||||
tokens[idx].attrSet('source-line', `${line}`);
|
||||
}
|
||||
if (precedentRule) {
|
||||
return precedentRule(tokens, idx, options, env, self);
|
||||
} else {
|
||||
return self.renderToken(tokens, idx, options);
|
||||
}
|
||||
};
|
||||
}
|
||||
},
|
||||
};
|
Reference in New Issue
Block a user