From 8c5df16d6753d3bda4a297795f902f5ff7859fa0 Mon Sep 17 00:00:00 2001 From: silverpill Date: Thu, 6 Oct 2022 22:22:40 +0000 Subject: [PATCH] Remove linebreaks from rendered post content --- src/utils/markdown.ts | 4 ++++ tests/unit/markdown.spec.ts | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/utils/markdown.ts b/src/utils/markdown.ts index f471cb8..37b6fc5 100644 --- a/src/utils/markdown.ts +++ b/src/utils/markdown.ts @@ -16,6 +16,10 @@ const markdownLite = new MarkdownIt({ linkify: true, breaks: true }) { attrs: { target: "_blank", rel: "noopener" } }, ) +// Remove \n from output +markdownLite.renderer.rules.hardbreak = () => "
" +markdownLite.renderer.rules.softbreak = () => "
" + export function renderMarkdown(text: string): string { return markdown.render(text) } diff --git a/tests/unit/markdown.spec.ts b/tests/unit/markdown.spec.ts index bfce0fe..4866fcd 100644 --- a/tests/unit/markdown.spec.ts +++ b/tests/unit/markdown.spec.ts @@ -5,6 +5,6 @@ describe("Render markdown", () => { it("Render markdown lite", () => { const text = "test **bold** ~~strike~~ with `code`, html and https://example.com\nand a new line" const html = renderMarkdownLite(text) - expect(html).to.equal('test bold ~~strike~~ with code, <span>html</span> and https://example.com
\nand a new line') + expect(html).to.equal('test bold ~~strike~~ with code, <span>html</span> and https://example.com
and a new line') }) })