Skip to content

Commit

Permalink
removing control characters
Browse files Browse the repository at this point in the history
  • Loading branch information
TobySalusky committed Sep 6, 2021
1 parent 53043ec commit 93f386c
Show file tree
Hide file tree
Showing 2 changed files with 388 additions and 16 deletions.
9 changes: 8 additions & 1 deletion src/Layouts/TableLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -206,9 +206,16 @@ export class TableLayout extends DataLayout {
}).filter(val => val !== undefined)
);

const removeControl = (str: string) => { // temporary fix, surely there ought to be a better way of doing this
// I'm not really sure which control characters should be line breaks or not :/
return str.replace(/\u009F/g, " ").replace(/[\u000A\u000C]/g, "\n").replace(/[\u001F]/g, " ").replace(/[\u0000-\u001F\u007F-\u009F]/g, " ");
}

const headerArr = [this.headers.map(header => header.value).filter(str => str !== '')];

const matrix = headerArr.concat(contentMatrix).map((row: string[], rowNum: number) => row.map((str: string, i: number) => i === 0 ? str : `${rowNum === 0 ? ' ' : ' | '}${str}`));
const matrix = headerArr.concat(contentMatrix).map((row: string[], rowNum: number) => row.map(
(str: string, i: number) => removeControl(i === 0 ? str : `${rowNum === 0 ? ' ' : ' | '}${str}`)
));

const tableText = table(matrix, {
border: getBorderCharacters('void'),
Expand Down
Loading

0 comments on commit 93f386c

Please sign in to comment.