-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: fix pasting not working for invalid tables and fix pasting table…
… when there is a trailing newline (#20)
- Loading branch information
1 parent
458d5d7
commit 6d1d398
Showing
3 changed files
with
19 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
export function parseTableFromTabbedText(text: string | undefined): string | undefined { | ||
if (!text) return undefined | ||
|
||
const lines = text.split('\n') | ||
const tabCountPerLine = lines.map(line => line.match(/\t/g)?.length || 0) | ||
const lines = text.trim().split('\n') | ||
const tabCountPerLine = lines.map(line => line.match(/\t+/g)?.length || 0) | ||
const allLinesHaveEqualTabCount = tabCountPerLine.every(tabCount => tabCount === tabCountPerLine[0] && tabCount > 0) | ||
|
||
if (!allLinesHaveEqualTabCount) return undefined | ||
return lines.map(line => `|${line.replace(/\|/g, '\\|').replace(/\t/g, '|')}|`).join('\n') | ||
return lines.map(line => `|${line.replace(/\|/g, '\\|').replace(/\t+/g, '|')}|`).join('\n') | ||
} |