Skip to content

Commit

Permalink
πŸ› fix #24 wrong formatting when table contains |
Browse files Browse the repository at this point in the history
  • Loading branch information
Yu committed Jul 30, 2017
1 parent be6f60b commit 6195516
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/tableFormatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,13 @@ class MarkdownDocumentFormatter implements DocumentFormattingEditProvider {
private formatTable(text: string) {
let rows = text.split(/\r?\n/g);
let content = rows.map(row => {
return row.trim().replace(/^\|/g, '').replace(/\|$/g, '').trim().split(/\s*\|\s*/g);
// Escape `|` in code span
while (/`([^`]*?)\|([^`]*?)`/.test(row)) {
row = row.replace(/`([^`]*?)\|([^`]*?)`/, '`$1%7c$2`');
}
return row.trim().replace(/^\|/g, '').replace(/\|$/g, '').trim().split(/\s*\|\s*/g).map(cell => {
return cell.replace(/%7c/g, '|')
});
});
// Normalize the num of hyphen
content[1] = content[1].map(cell => {
Expand Down

0 comments on commit 6195516

Please sign in to comment.