From 44e2fb1624442e92c2e7cc079eb2d113d87a0d6a Mon Sep 17 00:00:00 2001 From: silverpill Date: Fri, 28 Jan 2022 00:31:10 +0000 Subject: [PATCH] Allow code blocks in posts --- src/components/Post.vue | 3 ++- src/utils/markdown.ts | 2 +- tests/unit/markdown.spec.ts | 4 ++-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/components/Post.vue b/src/components/Post.vue index 72a6904..ed10c17 100644 --- a/src/components/Post.vue +++ b/src/components/Post.vue @@ -586,7 +586,8 @@ export default class PostComponent extends Vue { line-height: 1.5; padding: $block-inner-padding; - :deep(pre) { + :deep(pre), + :deep(code) { overflow-x: scroll; } diff --git a/src/utils/markdown.ts b/src/utils/markdown.ts index 1c13870..d557e4b 100644 --- a/src/utils/markdown.ts +++ b/src/utils/markdown.ts @@ -10,7 +10,7 @@ const markdown = new MarkdownIt({ linkify: true, breaks: true }) // Minimal renderer const markdownLite = new MarkdownIt({ linkify: true, breaks: true }) - .disable(["backticks", "emphasis", "strikethrough", "image"]) + .disable(["emphasis", "strikethrough", "image"]) .use( MarkdownItLinkAttrs, { attrs: { target: "_blank", rel: "noopener" } }, diff --git a/tests/unit/markdown.spec.ts b/tests/unit/markdown.spec.ts index 0f1037f..26434ba 100644 --- a/tests/unit/markdown.spec.ts +++ b/tests/unit/markdown.spec.ts @@ -3,8 +3,8 @@ import { renderMarkdownLite } from "@/utils/markdown" describe("Render markdown", () => { it("Render markdown lite", () => { - const text = "test **bold** ~~strike~~ with `code` and https://example.com\nand a new line" + 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` and https://example.com
\nand a new line') + expect(html).to.equal('test **bold** ~~strike~~ with code, <span>html</span> and https://example.com
\nand a new line') }) })