Skip to content

Commit

Permalink
Fixed issue with chrome MathML
Browse files Browse the repository at this point in the history
  • Loading branch information
VolodymyrBaydalka committed Jan 29, 2023
1 parent 3f41af7 commit 6122570
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 11 deletions.
18 changes: 15 additions & 3 deletions dist/docx-preview.js

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

2 changes: 1 addition & 1 deletion dist/docx-preview.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/docx-preview.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/docx-preview.min.js.map

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@
let currentDocument = null;
const docxOptions = Object.assign(docx.defaultOptions, {
debug: true,
experimental: true,
useMathMLPolyfill: true
experimental: true
});

const container = document.querySelector("#document-container");
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "docx-preview",
"version": "0.1.14",
"version": "0.1.15",
"license": "Apache-2.0",
"keywords": [
"word",
Expand Down
6 changes: 4 additions & 2 deletions src/document-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const mmlTagMap = {
"sup": DomType.MmlSuperArgument,
"sub": DomType.MmlSubArgument,
"d": DomType.MmlDelimiter,
"nary": DomType.MmlNary
"nary": DomType.MmlNary,
}

export interface DocumentParserOptions {
Expand Down Expand Up @@ -681,7 +681,9 @@ export class DocumentParser {
if (childType) {
result.children.push(this.parseMathElement(el));
} else if (el.localName == "r") {
result.children.push(this.parseRun(el));
var run = this.parseRun(el);
run.type = DomType.MmlRun;
result.children.push(run);
} else if (el.localName == propsTag) {
result.props = this.parseMathProperies(el);
}
Expand Down
1 change: 1 addition & 0 deletions src/document/dom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export enum DomType {
MmlSuperArgument = "mmlSuperArgument",
MmlNary = "mmlNary",
MmlDelimiter = "mmlDelimiter",
MmlRun = "mmlRun",
VmlElement = "vmlElement",
Inserted = "inserted",
Deleted = "deleted",
Expand Down
13 changes: 13 additions & 0 deletions src/html-renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -741,6 +741,9 @@ section.${c}>article { margin-bottom: auto; }
case DomType.MmlDelimiter:
return this.renderMmlDelimiter(elem);

case DomType.MmlRun:
return this.renderMmlRun(elem);

case DomType.MmlNary:
return this.renderMmlNary(elem);

Expand Down Expand Up @@ -1113,6 +1116,16 @@ section.${c}>article { margin-bottom: auto; }
return createElementNS(ns.mathML, "mrow", null, children);
}

renderMmlRun(elem: OpenXmlElement) {
const result = createElementNS(ns.mathML, "ms");

this.renderClass(elem, result);
this.renderStyleValues(elem.cssStyle, result);
this.renderChildren(elem, result);

return result;
}

renderStyleValues(style: Record<string, string>, ouput: HTMLElement) {
Object.assign(ouput.style, style);
}
Expand Down

0 comments on commit 6122570

Please sign in to comment.