0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2026-03-24 10:48:12 +00:00

subscript and superscript

This commit is contained in:
Víctor Losada Hernández
2026-03-23 23:55:35 +01:00
parent c76b174fd6
commit 02ae7176f7
2 changed files with 49 additions and 11 deletions

View File

@@ -64,18 +64,30 @@ const customHighlightPlugin = ViewPlugin.fromClass(
}
}
buildDecorations(view) {
const widgets = [];
const decos = [];
const tokens = tokenizeCustomMarkdown(view.state.doc.toString());
// sort by line number
tokens.sort((a, b) => a.line - b.line);
tokens.forEach((tok) => {
const line = view.state.doc.line(tok.line + 1); // CM lines are 1-based
widgets.push(Decoration.line({ class: `cm-${tok.type}` }).range(line.from));
const line = view.state.doc.line(tok.line + 1);
if (tok.from != null && tok.to != null) {
decos.push({
from: line.from + tok.from,
to: line.from + tok.to,
deco: Decoration.mark({ class: `cm-${tok.type}` }),
});
} else {
decos.push({
from: line.from,
to: line.from,
deco: Decoration.line({ class: `cm-${tok.type}` }),
});
}
});
return Decoration.set(widgets);
decos.sort((a, b) => a.from - b.from || a.to - b.to);
return Decoration.set(decos.map((d) => d.deco.range(d.from, d.to)));
}
},
{