diff --git a/docs/zh-CN/components/office-viewer.md b/docs/zh-CN/components/office-viewer.md index fa6008b56..4b29218db 100644 --- a/docs/zh-CN/components/office-viewer.md +++ b/docs/zh-CN/components/office-viewer.md @@ -185,7 +185,7 @@ Word 渲染支持以下功能: 目前变量使用的写法是 `{{name}}`,其中 `name` 代表变量名,另外这里可以是 amis 表达式,比如前面示例的 `{{DATETOSTR(TODAY(), 'YYYY-MM-DD')}}` -> 为了避免 Word 自作主张添加额外标签,对于复杂的变量建议先在记事本之类的纯文本编辑器里编辑,再粘贴进 Word 里。 +**Word 经常会自作主张进行语法检查,生成无关的标签导致变量替换出错,解决办法是参考这个[文档](https://support.microsoft.com/zh-cn/office/%E5%9C%A8-word-%E4%B8%AD%E6%A3%80%E6%9F%A5%E8%AF%AD%E6%B3%95-%E6%8B%BC%E5%86%99%E7%AD%89-0f43bf32-ccde-40c5-b16a-c6a282c0d251?ui=zh-cn&rs=zh-cn&ad=cn),将所有语法检查都忽略掉,也就是文档里不再有飘红的文字** ### 表格行循环 diff --git a/packages/office-viewer/__tests__/OpenXML.test.ts b/packages/office-viewer/__tests__/OpenXML.test.ts index b49d98a95..e0ece473d 100644 --- a/packages/office-viewer/__tests__/OpenXML.test.ts +++ b/packages/office-viewer/__tests__/OpenXML.test.ts @@ -87,3 +87,276 @@ test('space', async () => { expect(xmlDoc.getElementsByTagName('w:t')[0]?.innerHTML).toBe('Custom'); }); + +test('multi_proofErr', async () => { + const xmlDoc = parseXML( + ` + + + + + + + + + + + + + + + + + + + + + + {{ + + + + + + + + + + operate_ + + + + + + + + + + applicant.label + + + + + + + + + + + }} + + + + + `.trim() + ); + + const word = createWord(); + + mergeRun(word, xmlDoc); + + expect(xmlDoc.getElementsByTagName('w:t')[0]?.innerHTML).toBe( + '{{operate_applicant.label}}' + ); +}); + +test('multi_run', async () => { + const xmlDoc = parseXML( + ` + + + + + + + + + + + + + + + + + + + + + + { + + + + + + + + + { + + + + + + + + + operate + + + + + + + + + _ + + + + + + + + + a + + + + + + + + + pplicate + + + + + + + + + _u + + + + + + + + + nit + + + + + + + + + .label + + + + + + + + + }} + + + + + `.trim() + ); + + const word = createWord(); + + mergeRun(word, xmlDoc); + + expect(xmlDoc.getElementsByTagName('w:t')[0]?.innerHTML).toBe( + '{{operate_applicate_unit.label}}' + ); +}); + +test('error_proof', async () => { + const xmlDoc = parseXML( + ` + + + + + + + + + + + + + + + + + + + + + + {{ + + + + + + + + + + operate_work_type + + + + + + + + + . + + + + + + + + + label + + + + + + + + + + }} + + + + + `.trim() + ); + + const word = createWord(); + + mergeRun(word, xmlDoc); + + expect(xmlDoc.getElementsByTagName('w:t')[0]?.innerHTML).toBe( + '{{operate_work_type.label}}' + ); +}); diff --git a/scripts/get-all-docs.js b/scripts/get-all-docs.js new file mode 100644 index 000000000..c6ec66cdb --- /dev/null +++ b/scripts/get-all-docs.js @@ -0,0 +1,36 @@ +/** + * 获取所有文档和 json 示例,生成到一个文件里,用于继续预训练 + */ + +const fs = require('fs'); +const path = require('path'); +const glob = require('glob'); + +const docs = path.resolve(__dirname, '..', 'docs'); + +const examples = path.resolve(__dirname, '..', 'examples'); + +const outputFile = 'amis_docs.txt'; + +glob(docs + '/**/*.md', {}, (err, files) => { + for (const file of files) { + const data = fs.readFileSync(file, {encoding: 'utf8', flag: 'r'}); + fs.appendFileSync(outputFile, data + '\n\n'); + } +}); + +// glob(examples + '/**/*.jsx', {}, (err, files) => { +// for (const file of files) { +// try { +// const content = fs.readFileSync(file, {encoding: 'utf8', flag: 'r'}); +// if (content.indexOf('export default') !== -1) { +// const schema = Function(content.replace('export default', 'return'))(); +// const json = JSON.stringify(schema, null, 2); +// console.log(file); +// fs.appendFileSync(outputFile, json + '\n\n'); +// } +// } catch (e) { +// // console.log(e); +// } +// } +// });