From 5ba2b240602e3bcb2403c7c25ed2e1d50af760a2 Mon Sep 17 00:00:00 2001 From: Ganni Date: Mon, 2 Dec 2024 22:20:53 -0500 Subject: [PATCH] Create tableLineBreaks.ts --- .../markdown/plugins/tableLineBreaks.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 src/components/markdown/plugins/tableLineBreaks.ts diff --git a/src/components/markdown/plugins/tableLineBreaks.ts b/src/components/markdown/plugins/tableLineBreaks.ts new file mode 100644 index 00000000..24361afe --- /dev/null +++ b/src/components/markdown/plugins/tableLineBreaks.ts @@ -0,0 +1,17 @@ +import { visit } from "unist-util-visit"; + +/** + * Remark plugin to replace \n with
in table cells + */ +export function remarkTableLineBreaks() { + return (tree: any) => { + visit(tree, "tableCell", (node) => { + node.children.forEach((child: any) => { + if (child.type === "text") { + // Replace \n with
for text within table cells + child.value = child.value.replace(/\n/g, "
"); + } + }); + }); + }; +}