0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2025-12-26 09:32:51 +00:00

Allow both sub and super highlighting on same line

This commit is contained in:
Trevor Buckner
2023-12-04 21:56:08 -05:00
parent ddef21cd7e
commit 6bf51cd94a

View File

@@ -161,20 +161,20 @@ const Editor = createClass({
}
// Superscript
if(line.includes('^^') && !line.includes('^^^')) {
const regex = /.*\^\^(.+)\^\^/y;
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]) - 2 }, { line: lineNumber, ch: line.indexOf(match[1]) + match[1].length + 2 }, { className: 'superscript' });
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 = /.*\^\^\^(.+)\^\^\^/y;
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]) - 3 }, { line: lineNumber, ch: line.indexOf(match[1]) + match[1].length + 3 }, { className: 'subscript' });
codeMirror.markText({ line: lineNumber, ch: line.indexOf(match[1]) - 2 }, { line: lineNumber, ch: line.indexOf(match[1]) + match[1].length + 2 }, { className: 'subscript' });
}
}