一、下载
官方地址 html-doc-js - npm
复制
二、使用方法
| |
| import exportWord from 'html-doc-js' |
| |
| |
| |
| const wrap = document.getElementById('test')const config = { |
| document:document, |
| addStyle:true, |
| fileName:'测试', |
| toImg: ["canvas", "mjx-math"], |
| success(blob,dom){} |
| exportWord(wrap,config) |
复制
三、解决公式转为图片后单行公式可能会出现图片和原本的字符串重复的问题
在 exportWord 方法执行时,将页面中mjx-assistive-mml 节点清除即可,如下图所示

| |
| const clearMathTags = (targetInstance, tagName) => { |
| let targetElement = document.querySelectorAll(tagName); |
| if (targetElement && targetElement.length) { |
| targetElement.forEach((element) => { |
| element.remove(); |
| }); |
| } |
| }; |
复制
四、解决下载后共识可能显示有误的问题
