Skip to content

Commit

Permalink
fix: resolve #901
Browse files Browse the repository at this point in the history
  • Loading branch information
decaf-dev committed Feb 22, 2024
1 parent 5c79c65 commit 24ef053
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
Binary file modified bun.lockb
Binary file not shown.
17 changes: 11 additions & 6 deletions src/shared/export/export-to-markdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,23 @@ import { LoomState } from "../loom-state/types/loom-state";
import { markdownTable } from "markdown-table";
import { loomStateToArray } from "./loom-state-to-array";
import { App } from "obsidian";
import { escapePipeCharacters } from "./export-utils";
import {
escapePipeCharacters,
replaceNewLinesWithBreaks,
} from "./export-utils";

export const exportToMarkdown = (
app: App,
loomState: LoomState,
shouldRemoveMarkdown: boolean
): string => {
const arr = loomStateToArray(app, loomState, shouldRemoveMarkdown);
let arr = loomStateToArray(app, loomState, shouldRemoveMarkdown);

//Markdown table cells can't contain new lines, so we replace them with <br> tags
arr = arr.map((row) => row.map((cell) => replaceNewLinesWithBreaks(cell)));

//Markdown table cells can't contain pipe characters, so we escape them
//Obsidian will render the escaped pipe characters as normal pipe characters
const escapedArr = arr.map((row) =>
row.map((cell) => escapePipeCharacters(cell))
);
return markdownTable(escapedArr);
arr = arr.map((row) => row.map((cell) => escapePipeCharacters(cell)));
return markdownTable(arr);
};
3 changes: 3 additions & 0 deletions src/shared/export/export-utils.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
export const escapePipeCharacters = (value: string) =>
value.replace(/\|/g, "\\|");

export const replaceNewLinesWithBreaks = (value: string) =>
value.replace(/\n/g, "<br>");

0 comments on commit 24ef053

Please sign in to comment.