From 7d755fe2a349f646db9dafa4339a8155836f3fe8 Mon Sep 17 00:00:00 2001 From: David Bolack Date: Fri, 23 Feb 2024 11:35:57 -0600 Subject: [PATCH] Fix syntax highlighting on sub and superscript I did not test this very robustly, it seems. --- client/homebrew/editor/editor.jsx | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/client/homebrew/editor/editor.jsx b/client/homebrew/editor/editor.jsx index d79d2ce4e..3fa936ab7 100644 --- a/client/homebrew/editor/editor.jsx +++ b/client/homebrew/editor/editor.jsx @@ -160,21 +160,25 @@ const Editor = createClass({ } } - // Superscript - if(line.includes('\^')) { - const regex = /\^(?!\s)(?=([^\n\^]*[^\s\^]))\1\^/g; - let match; - while ((match = regex.exec(line)) != null) { - codeMirror.markText({ line: lineNumber, ch: line.indexOf(match[1]) - 1 }, { line: lineNumber, ch: line.indexOf(match[1]) + match[1].length + 1 }, { className: 'superscript' }); - } - } - // Subscript if(line.includes('^^')) { + //const regex = /\^\^(?!\s)(?=([^\n\^]*[^\s\^]))\1\^\^/g; const regex = /\^\^(?!\s)(?=([^\n\^]*[^\s\^]))\1\^\^/g; let match; while ((match = regex.exec(line)) != null) { - codeMirror.markText({ line: lineNumber, ch: line.indexOf(match[1]) - 2 }, { line: lineNumber, ch: line.indexOf(match[1]) + match[1].length + 2 }, { className: 'subscript' }); + if(line.indexOf(match[0]) - 1 != '^') { + codeMirror.markText({ line: lineNumber, ch: line.indexOf(match[0]) }, { line: lineNumber, ch: line.indexOf(match[0]) + match[0].length }, { className: 'subscript' }); + } + } + } + + // Superscript + if(line.includes('^')) { + //const regex = /\^(?!\s)(?=([^\n\^]*[^\s\^]))\1\^/g; + const regex = /\^(?!\s)(?=([^\n\^]*[^\s\^]))\1\^/g; + let match; + while ((match = regex.exec(line)) != null) { + codeMirror.markText({ line: lineNumber, ch: line.indexOf(match[0]) }, { line: lineNumber, ch: line.indexOf(match[0]) + match[0].length }, { className: 'superscript' }); } }