0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2026-01-08 20:23:39 +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 // Superscript
if(line.includes('^^') && !line.includes('^^^')) { if(line.includes('\^')) {
const regex = /.*\^\^(.+)\^\^/y; const regex = /\^(?!\s)(?=([^\n\^]*[^\s\^]))\1\^/g;
let match; let match;
while ((match = regex.exec(line)) != null) { 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 // Subscript
if(line.includes('^^^')) { if(line.includes('^^')) {
const regex = /.*\^\^\^(.+)\^\^\^/y; const regex = /\^\^(?!\s)(?=([^\n\^]*[^\s\^]))\1\^\^/g;
let match; let match;
while ((match = regex.exec(line)) != null) { 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' });
} }
} }