Skip to content

Commit

Permalink
fix: 重构表格逆解析时,处理空格的逻辑
Browse files Browse the repository at this point in the history
  • Loading branch information
sunsonliu committed Dec 26, 2023
1 parent 9f46d5e commit 49e4907
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/utils/htmlparser.js
Original file line number Diff line number Diff line change
Expand Up @@ -809,17 +809,20 @@ const htmlParser = {
},
convertThead(str) {
const $str = `${str
.trim()
.replace(/~\|[ \t]*~\|/g, '~|')
.replace(/[ \t]+/g, '')
.replace(/~\|~\|/g, '~|')
.replace(/~\|/g, '|')}\n`;
const headsCount = $str.match(/\|/g).length - 1;
return `${$str}|${':-:|'.repeat(headsCount)}\n`;
},
convertTable(str) {
const $str = str.replace(/^\s+/gm, '').replace(/~s~/g, ' ');
let ret = `\n${$str.replace(/~\|[ \t]*~\|/g, '~|').replace(/~\|/g, '|')}\n`
let ret = `\n${str
.replace(/[ \t]+/g, '')
.replace(/~\|~\|/g, '~|')
.replace(/~\|/g, '|')}\n`
.replace(/\n{2,}/g, '\n')
.replace(/\n[ \t]+\n/g, '\n');
.replace(/\n[ \t]+\n/g, '\n')
.replace(/~s~/g, ' ');
if (!/\|:-:\|/.test(ret)) {
const headsCount = ret.match(/^\n[^\n]+\n/)[0].match(/\|/g).length - 1;
ret = `\n|${' |'.repeat(headsCount)}\n|${':-:|'.repeat(headsCount)}${ret}`;
Expand Down

0 comments on commit 49e4907

Please sign in to comment.