mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-01-04 03:52:40 +00:00
Merge pull request #3323 from dbolack-ab/fix_subsuper_Highlighting
Fix syntax highlighting on sub and superscript
This commit is contained in:
@@ -160,21 +160,21 @@ const Editor = createClass({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Superscript
|
// Subscript & Superscript
|
||||||
if(line.includes('\^')) {
|
if(line.includes('^')) {
|
||||||
const regex = /\^(?!\s)(?=([^\n\^]*[^\s\^]))\1\^/g;
|
let startIndex = line.indexOf('^');
|
||||||
let match;
|
const superRegex = /\^(?!\s)(?=([^\n\^]*[^\s\^]))\1\^/gy;
|
||||||
while ((match = regex.exec(line)) != null) {
|
const subRegex = /\^\^(?!\s)(?=([^\n\^]*[^\s\^]))\1\^\^/gy;
|
||||||
codeMirror.markText({ line: lineNumber, ch: line.indexOf(match[1]) - 1 }, { line: lineNumber, ch: line.indexOf(match[1]) + match[1].length + 1 }, { className: 'superscript' });
|
|
||||||
}
|
while (startIndex >= 0) {
|
||||||
}
|
superRegex.lastIndex = subRegex.lastIndex = startIndex;
|
||||||
|
let isSuper = false;
|
||||||
// Subscript
|
let match = subRegex.exec(line) || superRegex.exec(line);
|
||||||
if(line.includes('^^')) {
|
if (match) {
|
||||||
const regex = /\^\^(?!\s)(?=([^\n\^]*[^\s\^]))\1\^\^/g;
|
isSuper = !subRegex.lastIndex;
|
||||||
let match;
|
codeMirror.markText({ line: lineNumber, ch: match.index }, { line: lineNumber, ch: match.index + match[0].length }, { className: isSuper ? 'superscript' : 'subscript' });
|
||||||
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' });
|
startIndex = line.indexOf('^', Math.max(startIndex + 1, subRegex.lastIndex, superRegex.lastIndex));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user