From 7a4e5e8969e1895d6f131d9b7a01e160f73620b1 Mon Sep 17 00:00:00 2001 From: "Davide P. Cervone" Date: Thu, 13 Feb 2020 11:43:09 -0500 Subject: [PATCH] Don't process escaped characters in a11y and menu extensions. resolves issue mathjax/MathJax#2327 --- ts/a11y/assistive-mml.ts | 2 +- ts/a11y/complexity.ts | 2 +- ts/a11y/explorer.ts | 2 +- ts/a11y/semantic-enrich.ts | 2 +- ts/core/MathItem.ts | 13 +++++++++++-- ts/ui/menu/MenuHandler.ts | 2 +- 6 files changed, 16 insertions(+), 7 deletions(-) diff --git a/ts/a11y/assistive-mml.ts b/ts/a11y/assistive-mml.ts index 4d7ed3d18..668e19c90 100644 --- a/ts/a11y/assistive-mml.ts +++ b/ts/a11y/assistive-mml.ts @@ -76,7 +76,7 @@ export function AssistiveMmlMathItemMixin) { - if (this.state() >= STATE.ASSISTIVEMML) return; + if (this.state() >= STATE.ASSISTIVEMML || this.isEscaped) return; this.state(STATE.ASSISTIVEMML); const adaptor = document.adaptor; // diff --git a/ts/a11y/complexity.ts b/ts/a11y/complexity.ts index 1781ee7a3..1b770f036 100644 --- a/ts/a11y/complexity.ts +++ b/ts/a11y/complexity.ts @@ -85,7 +85,7 @@ export function ComplexityMathItemMixin) { - if (this.state() < STATE.COMPLEXITY) { + if (this.state() < STATE.COMPLEXITY && !this.isEscaped) { this.enrich(document); computeComplexity(this.root); this.state(STATE.COMPLEXITY); diff --git a/ts/a11y/explorer.ts b/ts/a11y/explorer.ts index eb24b8e68..8b0fd23b3 100644 --- a/ts/a11y/explorer.ts +++ b/ts/a11y/explorer.ts @@ -118,7 +118,7 @@ export function ExplorerMathItemMixin>( * @param {HTMLDocument} document The MathDocument for the MathItem */ public explorable(document: ExplorerMathDocument) { - if (this.state() >= STATE.EXPLORER) return; + if (this.state() >= STATE.EXPLORER || this.isEscaped) return; const node = this.typesetRoot; const mml = toMathML(this.root); if (this.savedId) { diff --git a/ts/a11y/semantic-enrich.ts b/ts/a11y/semantic-enrich.ts index 23ca06129..f491dd050 100644 --- a/ts/a11y/semantic-enrich.ts +++ b/ts/a11y/semantic-enrich.ts @@ -132,7 +132,7 @@ export function EnrichedMathItemMixin) { - if (this.state() >= STATE.ENRICHED) return; + if (this.state() >= STATE.ENRICHED || this.isEscaped) return; if (typeof sre === 'undefined' || !sre.Engine.isReady()) { mathjax.retryAfter(sreReady); } diff --git a/ts/core/MathItem.ts b/ts/core/MathItem.ts index b90e9b4a8..4708e775b 100644 --- a/ts/core/MathItem.ts +++ b/ts/core/MathItem.ts @@ -95,6 +95,11 @@ export interface MathItem { */ display: boolean; + /** + * Whether this item is an escaped character or not + */ + isEscaped: boolean; + /** * The start and ending locations in the document of * this expression @@ -271,6 +276,10 @@ export abstract class AbstractMathItem implements MathItem { public inputData: OptionList = {}; public outputData: OptionList = {}; + public get isEscaped() { + return this.display === null; + } + /** * @param {string} math The math expression for this item * @param {Inputjax} jax The input jax to use for this item @@ -315,7 +324,7 @@ export abstract class AbstractMathItem implements MathItem { /** * @override */ - convert(document: MathDocument, end: number = STATE.LAST) { + public convert(document: MathDocument, end: number = STATE.LAST) { document.renderActions.renderConvert(this, document, end); } @@ -334,7 +343,7 @@ export abstract class AbstractMathItem implements MathItem { */ public typeset(document: MathDocument) { if (this.state() < STATE.TYPESET) { - this.typesetRoot = document.outputJax[this.display === null ? 'escaped' : 'typeset'](this, document); + this.typesetRoot = document.outputJax[this.isEscaped ? 'escaped' : 'typeset'](this, document); this.state(STATE.TYPESET); } } diff --git a/ts/ui/menu/MenuHandler.ts b/ts/ui/menu/MenuHandler.ts index df58f2dfe..f7ad09f80 100644 --- a/ts/ui/menu/MenuHandler.ts +++ b/ts/ui/menu/MenuHandler.ts @@ -121,7 +121,7 @@ export function MenuMathItemMixin( * @param {MenuMathDocument} document The document where the menu is being added */ public addMenu(document: MenuMathDocument) { - if (this.state() < STATE.CONTEXT_MENU) { + if (this.state() < STATE.CONTEXT_MENU && !this.isEscaped) { document.menu.addMenu(this); this.state(STATE.CONTEXT_MENU); }