0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2026-01-10 15:42:39 +00:00

Rework to fix 5eCleric's tests

This commit is contained in:
Trevor Buckner
2024-02-29 17:17:38 -05:00
parent 7d755fe2a3
commit 774b555a61

View File

@@ -160,25 +160,21 @@ const Editor = createClass({
} }
} }
// Subscript // 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) {
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('^')) { if(line.includes('^')) {
//const regex = /\^(?!\s)(?=([^\n\^]*[^\s\^]))\1\^/g; let startIndex = line.indexOf('^');
const regex = /\^(?!\s)(?=([^\n\^]*[^\s\^]))\1\^/g; const superRegex = /\^(?!\s)(?=([^\n\^]*[^\s\^]))\1\^/gy;
let match; const subRegex = /\^\^(?!\s)(?=([^\n\^]*[^\s\^]))\1\^\^/gy;
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' }); while (startIndex >= 0) {
superRegex.lastIndex = subRegex.lastIndex = startIndex;
let isSuper = false;
let match = subRegex.exec(line) || superRegex.exec(line);
if (match) {
isSuper = !subRegex.lastIndex;
codeMirror.markText({ line: lineNumber, ch: match.index }, { line: lineNumber, ch: match.index + match[0].length }, { className: isSuper ? 'superscript' : 'subscript' });
}
startIndex = line.indexOf('^', Math.max(startIndex + 1, subRegex.lastIndex, superRegex.lastIndex));
} }
} }