Skip to content

Commit

Permalink
Fix a bug that caused a crash when accessibility was enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
sonoisa committed Apr 30, 2021
1 parent b4be890 commit 58f2943
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 34 deletions.
13 changes: 3 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
# XyJax v3
-- Xy-pic extension for **MathJax version 3** --

**CAUTION**:
THE CURRENT VERSION IS IN ALPHA-QUALITY.
DEPENDING ON YOUR MathJax SETTINGS, IT MAY CRASH.
IT IS NOT YET RECOMMENDED FOR USE IN PRODUCTION.

----
XyJax is an almost Xy-pic compatible extension for **MathJax version 3**.

Expand All @@ -31,7 +26,7 @@ This software is under development.
MathJax = {
loader: {
load: ['[custom]/xypic.js'],
paths: {custom: 'https://cdn.jsdelivr.net/gh/sonoisa/XyJax-v3@0.3.0/build/'}
paths: {custom: 'https://cdn.jsdelivr.net/gh/sonoisa/XyJax-v3@3.0.0/build/'}
},
tex: {
packages: {'[+]': ['xypic']}
Expand Down Expand Up @@ -68,16 +63,14 @@ This software is under development.
```


## Present Limitation
## Supported MathJax Functions

- Supported MathJax version:
- 3.1.4+
- Supported Renderer:
- Supported Renderers:
- CHTML
- SVG

- Accessibility does not work.
**CAUTION**: If Accessibility or Collapsible Math is enabled, XyJax/MathJax will crash.


## For Developers
Expand Down
2 changes: 1 addition & 1 deletion build/xypic.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "xyjax",
"version": "3.0.0-alpha.3",
"version": "3.0.0",
"description": "XyJax for MathJax 3",
"license": "Apache-2.0",
"author": "Isao Sonobe",
Expand Down
26 changes: 18 additions & 8 deletions src/core/XypicConfiguration.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,14 @@ import {} from "../output/AugmentXyNodes.js";

function parseXypic(texParser, xyParser, mmlKind) {
const textMmls = [];
const textMmlIds = [];

const createTextNode = function (text) {
const textMml = new TexParser(text, texParser.stack.env, texParser.configuration).mml();
textMml.xypicTextObjectId = xypicGlobalContext.textObjectIdCounter;
const textObjectId = xypicGlobalContext.textObjectIdCounter;
xypicGlobalContext.textObjectIdCounter++;
textMmls.push(textMml);
textMmlIds.push(textObjectId);
return textMml;
};

Expand All @@ -59,7 +61,13 @@ function parseXypic(texParser, xyParser, mmlKind) {
texParser.i = result.next.offset;

if (result.successful) {
const mml = texParser.create(mmlKind, result.get(), textMmls);
const commandId = "" + xypicGlobalContext.xypicCommandIdCounter;
xypicGlobalContext.xypicCommandIdCounter++;
xypicGlobalContext.xypicCommandMap[commandId] = result.get();

const textMmlIdsJson = JSON.stringify(textMmlIds);

const mml = texParser.create(mmlKind, { "data-cmd-id": commandId, "data-text-mml-ids": textMmlIdsJson }, textMmls);
return mml;
} else {
const pos = parseContext.lastNoSuccess.next.pos();
Expand Down Expand Up @@ -118,6 +126,8 @@ const XypicEnvironmentMap = new EnvironmentMap("xypic-environment", ParseMethods
function initializeXypicGlobalContext() {
// xypicGlobalContext.repositories.modifierRepository = new ModifierRepository();
// xypicGlobalContext.repositories.dirRepository = new DirRepository();
xypicGlobalContext.xypicCommandIdCounter = 0;
xypicGlobalContext.xypicCommandMap = {};
xypicGlobalContext.textObjectIdCounter = 0;
xypicGlobalContext.wrapperOfTextObjectMap = {};
}
Expand All @@ -134,17 +144,17 @@ const XypicConfiguration = Configuration.create(
}
],
nodes: {
"xypic": function(nodeFactory, command, textMmls) {
"xypic": function(nodeFactory, properties, textMmls) {
const mmlFactory = nodeFactory.mmlFactory;
return new AST.xypic(mmlFactory, command, textMmls);
return new AST.xypic(mmlFactory, properties, textMmls);
},
"xypic-newdir": function(nodeFactory, command, textMmls) {
"xypic-newdir": function(nodeFactory, properties, textMmls) {
const mmlFactory = nodeFactory.mmlFactory;
return new AST.xypic.newdir(mmlFactory, command, textMmls);
return new AST.xypic.newdir(mmlFactory, properties, textMmls);
},
"xypic-includegraphics": function(nodeFactory, command, textMmls) {
"xypic-includegraphics": function(nodeFactory, properties, textMmls) {
const mmlFactory = nodeFactory.mmlFactory;
return new AST.xypic.includegraphics(mmlFactory, command, textMmls);
return new AST.xypic.includegraphics(mmlFactory, properties, textMmls);
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/core/xypicGlobalContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ export const xypicGlobalContext = {
modifierRepository: new ModifierRepository(),
dirRepository: new DirRepository()
},
xypicCommandIdCounter: 0,
xypicCommandMap: {},
textObjectIdCounter: 0,
wrapperOfTextObjectMap: {}
}
29 changes: 18 additions & 11 deletions src/input/XyNodes.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,35 @@

import {AbstractMmlNode, TEXCLASS} from "../../mathjax/js/core/MmlTree/MmlNode.js";
import {MML} from "../../mathjax/js/core/MmlTree/MML.js";
import {xypicGlobalContext} from "../core/xypicGlobalContext.js";


export class AST {};


class BaseXyMmlNode extends AbstractMmlNode {
constructor(mmlFactory, textMmls) {
super(mmlFactory, {}, textMmls);
constructor(mmlFactory, properties, textMmls) {
super(mmlFactory, properties, textMmls);
this.textMmls = textMmls;
this.texClass = TEXCLASS.ORD;

const commandId = properties["data-cmd-id"];
const command = xypicGlobalContext.xypicCommandMap[commandId];
this.cmd = command;

const textMmlIds = JSON.parse(properties["data-text-mml-ids"]);
for (let i = 0, n = textMmlIds.length; i < n; i++) {
textMmls[i].xypicTextObjectId = textMmlIds[i];
}
}
}

BaseXyMmlNode.defaults = AbstractMmlNode.defaults;


AST.xypic = class AST_xypic extends BaseXyMmlNode {
constructor(mmlFactory, command, textMmls) {
super(mmlFactory, textMmls);
this.cmd = command;
constructor(mmlFactory, properties, textMmls) {
super(mmlFactory, properties, textMmls);
}

get kind() {
Expand All @@ -52,9 +61,8 @@ MML[AST.xypic.prototype.kind] = AST.xypic;


AST.xypic.newdir = class AST_xypic_newdir extends BaseXyMmlNode {
constructor(mmlFactory, command, textMmls) {
super(mmlFactory, textMmls);
this.cmd = command;
constructor(mmlFactory, properties, textMmls) {
super(mmlFactory, properties, textMmls);
}

get kind() {
Expand All @@ -69,9 +77,8 @@ MML[AST.xypic.newdir.prototype.kind] = AST.xypic.newdir;


AST.xypic.includegraphics = class AST_xypic_includegraphics extends BaseXyMmlNode {
constructor(mmlFactory, command, textMmls) {
super(mmlFactory, textMmls);
this.cmd = command;
constructor(mmlFactory, properties, textMmls) {
super(mmlFactory, properties, textMmls);
}

get kind() {
Expand Down
2 changes: 1 addition & 1 deletion test/sample-xyjax-v3-CDN.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
MathJax = {
loader: {
load: ['[custom]/xypic.js'],
paths: {custom: 'https://cdn.jsdelivr.net/gh/sonoisa/XyJax-v3@0.3.0/build/'}
paths: {custom: 'https://cdn.jsdelivr.net/gh/sonoisa/XyJax-v3@3.0.0/build/'}
},
tex: {
packages: {'[+]': ['xypic']}
Expand Down

0 comments on commit 58f2943

Please sign in to comment.