diff --git a/static/word2md/turndown-plugin-gfm.js b/static/word2md/turndown-plugin-gfm.js index 859f4ad7..e059d65e 100644 --- a/static/word2md/turndown-plugin-gfm.js +++ b/static/word2md/turndown-plugin-gfm.js @@ -120,11 +120,18 @@ function isFirstTbody (element) { ) } -function cell (content, node) { - var index = indexOf.call(node.parentNode.childNodes, node); - var prefix = ' '; - if (index === 0) prefix = '| '; - return prefix + content + ' |' +//修复,当表格中有换行时,解析不正确,修复表格为空时,增加3个空格,确保能正确解析 +function cell(content, node) { + var index = indexOf.call(node.parentNode.childNodes, node); + var prefix = ' '; + content = content.replace("\n", "
") + if (index === 0) + prefix = '| '; + let filteredContent = content.trim().replace(/\n\r/g, '
').replace(/\n/g, "
"); + filteredContent = filteredContent.replace(/\|+/g, '\\|'); + while (filteredContent.length < 3) + filteredContent += ' '; + return prefix + filteredContent + ' |' } function tables (turndownService) {