mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-03-27 05:58:10 +00:00
35 lines
1.1 KiB
JavaScript
35 lines
1.1 KiB
JavaScript
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' },
|
|
]);
|
|
|
|
|