From 35653bb1151c235e57317c4dde4147f5639023e1 Mon Sep 17 00:00:00 2001 From: btzr-io Date: Thu, 17 Dec 2020 16:44:16 -0600 Subject: [PATCH] prevent front-matter render on markdown --- package.json | 1 + ui/component/common/markdown-preview.jsx | 5 ++++- yarn.lock | 19 +++++++++++++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 26a1af69d..b7dae2bbf 100644 --- a/package.json +++ b/package.json @@ -183,6 +183,7 @@ "remark": "^9.0.0", "remark-attr": "^0.8.3", "remark-emoji": "^2.0.1", + "remark-frontmatter": "^2.0.0", "remark-react": "^4.0.3", "reselect": "^3.0.0", "sass": "^1.29.0", diff --git a/ui/component/common/markdown-preview.jsx b/ui/component/common/markdown-preview.jsx index 26d41555c..329c9c3bc 100644 --- a/ui/component/common/markdown-preview.jsx +++ b/ui/component/common/markdown-preview.jsx @@ -6,6 +6,7 @@ import remarkAttr from 'remark-attr'; import remarkStrip from 'strip-markdown'; import remarkEmoji from 'remark-emoji'; import remarkBreaks from 'remark-breaks'; +import remarkFrontMatter from 'remark-frontmatter'; import reactRenderer from 'remark-react'; import MarkdownLink from 'component/markdownLink'; import defaultSchema from 'hast-util-sanitize/lib/github.json'; @@ -120,7 +121,7 @@ const MarkdownPreview = (props: MarkdownProps) => { const remarkAttrOpts = { scope: 'extended', - elements: ['link'], + elements: ['link', 'yaml'], extend: { link: ['embed'] }, defaultValue: true, }; @@ -134,6 +135,7 @@ const MarkdownPreview = (props: MarkdownProps) => { { remark() .use(remarkStrip) + .use(remarkFrontMatter, ['yaml']) .use(reactRenderer, remarkOptions) .processSync(content).contents } @@ -156,6 +158,7 @@ const MarkdownPreview = (props: MarkdownProps) => { .use(remarkEmoji) // Render new lines without needing spaces. .use(remarkBreaks) + .use(remarkFrontMatter, ['yaml']) .use(reactRenderer, remarkOptions) .processSync(strippedContent).contents } diff --git a/yarn.lock b/yarn.lock index d3bc3937b..ba0071481 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5431,6 +5431,13 @@ fast-levenshtein@^2.0.6, fast-levenshtein@~2.0.6: version "2.0.6" resolved "https://registry.yarnpkg.com/fast-levenshtein/-/fast-levenshtein-2.0.6.tgz#3d8a5c66883a16a30ca8643e851f19baa7797917" +fault@^1.0.1: + version "1.0.4" + resolved "https://registry.yarnpkg.com/fault/-/fault-1.0.4.tgz#eafcfc0a6d214fc94601e170df29954a4f842f13" + integrity sha512-CJ0HCB5tL5fYTEA7ToAq5+kTwd++Borf1/bifxd9iT70QcXr4MRrO3Llf8Ifs70q+SJcGHFtnIE/Nw6giCtECA== + dependencies: + format "^0.2.0" + faye-websocket@^0.10.0: version "0.10.0" resolved "https://registry.yarnpkg.com/faye-websocket/-/faye-websocket-0.10.0.tgz#4e492f8d04dfb6f89003507f6edbf2d501e7c6f4" @@ -5689,6 +5696,11 @@ for-in@^1.0.2: version "1.0.2" resolved "https://registry.yarnpkg.com/for-in/-/for-in-1.0.2.tgz#81068d295a8142ec0ac726c6e2200c30fb6d5e80" +format@^0.2.0: + version "0.2.2" + resolved "https://registry.yarnpkg.com/format/-/format-0.2.2.tgz#d6170107e9efdc4ed30c9dc39016df942b5cb58b" + integrity sha1-1hcBB+nv3E7TDJ3DkBbflCtctYs= + formik@^0.10.4: version "0.10.5" resolved "https://registry.yarnpkg.com/formik/-/formik-0.10.5.tgz#6984d2f22e918c6d2264a3cb86b8582f7277faca" @@ -10033,6 +10045,13 @@ remark-emoji@^2.0.1: node-emoji "^1.8.1" unist-util-visit "^1.4.0" +remark-frontmatter@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/remark-frontmatter/-/remark-frontmatter-2.0.0.tgz#c9b8539c27cd23b1672c7e0fcbd5795eeedb4dc1" + integrity sha512-uNOQt4tO14qBFWXenF0MLC4cqo3dv8qiHPGyjCl1rwOT0LomSHpcElbjjVh5CwzElInB38HD8aSRVugKQjeyHA== + dependencies: + fault "^1.0.1" + remark-parse@^5.0.0: version "5.0.0" resolved "https://registry.yarnpkg.com/remark-parse/-/remark-parse-5.0.0.tgz#4c077f9e499044d1d5c13f80d7a98cf7b9285d95"