From 0825fd1ea65253a49a0030a30ba5fcc7e7954f56 Mon Sep 17 00:00:00 2001 From: Sahatsawat Kanpai Date: Tue, 14 Jan 2025 09:57:49 +0700 Subject: [PATCH] =?UTF-8?q?=F0=9F=93=96=20=20examples=20and=20the=20consol?= =?UTF-8?q?e.log=20for=20it,=20about=20handling=20mathlive=20script=20math?= =?UTF-8?q?/tex=20to=20MathML?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package-lock.json | 19 ++++++------------- package.json | 3 ++- src/export.ts | 15 ++++++++++++++- 3 files changed, 22 insertions(+), 15 deletions(-) diff --git a/package-lock.json b/package-lock.json index 633a229..b5db6e9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,8 @@ "version": "0.0.1", "license": "MIT", "dependencies": { - "@esi_package/ckeditor5-mathlive": "^0.0.14" + "@esi_package/ckeditor5-mathlive": "^0.0.15", + "temml": "^0.10.32" }, "devDependencies": { "@ckeditor/ckeditor5-dev-build-tools": "43.0.1", @@ -3553,15 +3554,13 @@ } }, "node_modules/@esi_package/ckeditor5-mathlive": { - "version": "0.0.14", - "resolved": "http://158.108.215.151:8081/api/packages/esirepository/npm/%40esi_package%2Fckeditor5-mathlive/-/0.0.14/ckeditor5-mathlive-0.0.14.tgz", - "integrity": "sha512-WOc2Hlc/OOurxDy4ZDh7qGHQ1HvLl+jUEFd/9odHg1a8MTJW9Epplpd71GjZBDssHJxsMD7vG4iK0SAnupf/1Q==", + "version": "0.0.15", + "resolved": "http://158.108.215.151:8081/api/packages/esirepository/npm/%40esi_package%2Fckeditor5-mathlive/-/0.0.15/ckeditor5-mathlive-0.0.15.tgz", + "integrity": "sha512-I/5yZfZeOU7jnlodXHolIerh1N3s83q50M1dGlVavD85hKPvby/vic4+WuzdhvjxqiGhO1eoCbRonPQ+Mvu0zA==", "license": "MIT", "dependencies": { "@ckeditor/ckeditor5-dev-webpack-plugin": "^31.1.13", - "mathjax": "^3.2.2", - "mathlive": "^0.101.2", - "temml": "^0.10.32" + "mathlive": "^0.101.2" }, "peerDependencies": { "ckeditor5": ">=42.0.0 || ^0.0.0-nightly" @@ -13407,12 +13406,6 @@ "node": ">= 0.4" } }, - "node_modules/mathjax": { - "version": "3.2.2", - "resolved": "https://registry.npmjs.org/mathjax/-/mathjax-3.2.2.tgz", - "integrity": "sha512-Bt+SSVU8eBG27zChVewOicYs7Xsdt40qm4+UpHyX7k0/O9NliPc+x77k1/FEsPsjKPZGJvtRZM1vO+geW0OhGw==", - "license": "Apache-2.0" - }, "node_modules/mathlive": { "version": "0.101.2", "resolved": "https://registry.npmjs.org/mathlive/-/mathlive-0.101.2.tgz", diff --git a/package.json b/package.json index c7e4385..46057c9 100644 --- a/package.json +++ b/package.json @@ -93,6 +93,7 @@ } }, "dependencies": { - "@esi_package/ckeditor5-mathlive": "^0.0.14" + "@esi_package/ckeditor5-mathlive": "^0.0.15", + "temml": "^0.10.32" } } diff --git a/src/export.ts b/src/export.ts index ad0693c..09d5d49 100644 --- a/src/export.ts +++ b/src/export.ts @@ -2,9 +2,11 @@ import { Plugin, ButtonView } from 'ckeditor5'; import ckeditor5Icon from '../theme/icons/ckeditor.svg'; -import { asBlob } from 'html-docx-js-typescript' +import { asBlob } from 'html-docx-js-typescript'; import { saveAs } from 'file-saver'; +import Temml from 'temml'; + export default class Export extends Plugin { public static get pluginName() { return 'Export' as const; @@ -47,6 +49,17 @@ export default class Export extends Plugin { // POST fetch docx and download this.listenTo( view, 'execute', async () => { + const parser = new DOMParser(); + const doc = parser.parseFromString(this.editor.getData(), "text/html"); + + for (const mathliveElement of doc.querySelectorAll('script[type="math/tex"]')) { + const temmlWrapperElement = document.createElement('span'); + const temmlMathMLString = Temml.render(mathliveElement.textContent ?? "", temmlWrapperElement); + mathliveElement.replaceWith(temmlWrapperElement); + } + + console.log(doc.body.innerHTML); + fetch('http://localhost:3000/docx', { method: 'POST', body: JSON.stringify({ htmlData: this.editor.getData() }),