From 4aa9408358e5a5d702cf7db2fb17bbbba105c25f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Losada=20Hern=C3=A1ndez?= Date: Sun, 29 Mar 2026 01:59:21 +0100 Subject: [PATCH] proper highlights for weird def lists --- .../components/codeEditor/customHighlight.js | 86 +++++++++---------- 1 file changed, 42 insertions(+), 44 deletions(-) diff --git a/client/components/codeEditor/customHighlight.js b/client/components/codeEditor/customHighlight.js index d0522520a..596434a9c 100644 --- a/client/components/codeEditor/customHighlight.js +++ b/client/components/codeEditor/customHighlight.js @@ -79,53 +79,52 @@ export function tokenizeCustomMarkdown(text) { } } - // --- inline definition lists --- - if(/::/.test(lineText)) { - if(/^:*$/.test(lineText) == true) { - return; //if line only has colons, stops + const singleLineRegex = /^([^:\n]*\S)(\s*)(::)([^\n]*)$/dmy; + + const match = singleLineRegex.exec(lineText); + + if(match) { + const [full, term, spaces, colons, desc] = match; + + let offset = 0; + + tokens.push({ + line : lineNumber, + type : customTags.definitionList, + }); + + // Term + tokens.push({ + line : lineNumber, + type : customTags.definitionTerm, + from : offset, + to : offset + term.length, + }); + offset += term.length; + + // Spaces before :: + if(spaces) { + offset += spaces.length; } - const singleLineRegex = /^([^:\n]*\S)\s*(::)([^\n]*)$/dmy; + // :: colons + tokens.push({ + line : lineNumber, + type : customTags.definitionColon, + from : offset, + to : offset + colons.length, + }); + offset += colons.length; - const match = singleLineRegex.exec(lineText); + // Definition + tokens.push({ + line : lineNumber, + type : customTags.definitionDesc, + from : offset, + to : offset + desc.length, + }); - if(match) { - const [full, term, colons, desc] = match; - let offset = 0; - // Entire line as definitionList - tokens.push({ - line : lineNumber, - type : customTags.definitionList, - }); - - // Term - tokens.push({ - line : lineNumber, - type : customTags.definitionTerm, - from : offset, - to : offset + term.length, - }); - offset += term.length; - - // :: - tokens.push({ - line : lineNumber, - type : customTags.definitionColon, - from : offset, - to : offset + colons.length, - }); - offset += colons.length; - - // Definition - tokens.push({ - line : lineNumber, - type : customTags.definitionDesc, - from : offset, - to : offset + desc.length, - }); - - return; - } + return; } // multiline def list @@ -254,7 +253,6 @@ export function tokenizeCustomCSS(text) { return tokens; } -console.log(tags); //assign classes to tags provided by lezer, not unlike the function above export const customHighlightStyle = HighlightStyle.define([ { tag: tags.heading, class: 'cm-header' },