0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2026-03-27 05:58:10 +00:00

syntax highligting for legacy as well

This commit is contained in:
Víctor Losada Hernández
2026-03-26 14:22:39 +01:00
parent f50c25b906
commit b0ebeaffb9
5 changed files with 125 additions and 45 deletions

View File

@@ -0,0 +1,34 @@
import { HighlightStyle } from '@codemirror/language';
import { tags } from '@lezer/highlight';
// Making the tokens
const customTags = {
pageLine : 'pageLine', // .cm-pageLine
snippetLine : 'snippetLine', // .cm-snippetLine
};
export function legacyTokenizeCustomMarkdown(text) {
const tokens = [];
const lines = text.split('\n');
// Track multi-line blocks
const inBlock = false;
const blockStart = 0;
lines.forEach((lineText, lineNumber)=>{
// --- Page / snippet lines ---
if(/^(?=\\page(?:break)?(?: *{[^\n{}]*})?$)/m.test(lineText)) tokens.push({ line: lineNumber, type: customTags.pageLine });
if(/^\\snippet\ .*$/.test(lineText)) tokens.push({ line: lineNumber, type: customTags.snippetLine });
});
return tokens;
}
export const legacyCustomHighlightStyle = HighlightStyle.define([
{ tag: tags.heading1, color: '#000', fontWeight: '700' },
{ tag: tags.keyword, color: '#07a' }, // example for your markdown headings
{ tag: customTags.pageLine, color: '#f0a' },
{ tag: customTags.snippetLine, class: 'cm-snippetLine', color: '#0af' },
]);