Skip to content

Commit

Permalink
fix #152
Browse files Browse the repository at this point in the history
  • Loading branch information
artisticat1 committed Jun 24, 2023
1 parent 5b30b06 commit aa3d4c3
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions src/editor_extensions/conceal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,22 +47,22 @@ class ConcealWidget extends WidgetType {


class TextWidget extends WidgetType {

constructor(readonly symbol: string) {
super();
}

eq(other: TextWidget) {
return (other.symbol == this.symbol);
}

toDOM() {
const span = document.createElement("span");
span.className = "cm-math";
span.textContent = this.symbol;
return span;
}

ignoreEvent() {
return false;
}
Expand Down Expand Up @@ -95,7 +95,7 @@ function escapeRegex(regex: string) {



function concealSymbols(eqn: string, prefix: string, suffix: string, symbolMap: {[key: string]: string}, className?: string):Concealment[] {
function concealSymbols(eqn: string, prefix: string, suffix: string, symbolMap: {[key: string]: string}, className?: string, allowSucceedingLetters = true):Concealment[] {
const symbolNames = Object.keys(symbolMap);

const regexStr = prefix + "(" + escapeRegex(symbolNames.join("|")) + ")" + suffix;
Expand All @@ -109,6 +109,15 @@ function concealSymbols(eqn: string, prefix: string, suffix: string, symbolMap:
for (const match of matches) {
const symbol = match[1];

if (!allowSucceedingLetters) {
// If the symbol match is succeeded by a letter (e.g. "pm" in "pmatrix" is succeeded by "a"), don't conceal

const end = match.index + match[0].length;
if (eqn.charAt(end).match(/[a-zA-Z]/)) {
continue;
}
}

concealments.push({start: match.index, end: match.index + match[0].length, replacement: symbolMap[symbol], class: className});
}

Expand Down Expand Up @@ -288,7 +297,7 @@ function concealOperators(eqn: string, symbols: string[]):Concealment[] {
const end = start + match[0].length;

concealments.push({start: start, end: end, replacement: value, class: "cm-concealed-mathrm cm-variable-2"});

}

return concealments;
Expand Down Expand Up @@ -440,7 +449,7 @@ function conceal(view: EditorView) {
...concealSymbols(eqn, "\\^", "", map_super),
...concealSymbols(eqn, "_", "", map_sub),
...concealSymbols(eqn, "\\\\frac", "", fractions),
...concealSymbols(eqn, "\\\\", "", ALL_SYMBOLS),
...concealSymbols(eqn, "\\\\", "", ALL_SYMBOLS, undefined, false),
...concealSupSub(eqn, true, ALL_SYMBOLS),
...concealSupSub(eqn, false, ALL_SYMBOLS),
...concealModifier(eqn, "hat", "\u0302"),
Expand Down

0 comments on commit aa3d4c3

Please sign in to comment.