From aaaa499346e0345b824220a9cd38146af0e98e82 Mon Sep 17 00:00:00 2001 From: alexandre Date: Tue, 11 Jul 2023 16:40:45 +0200 Subject: [PATCH] feedback --- packages/markdown/parseMarkdown.js | 34 ++++++++++++++++-------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/packages/markdown/parseMarkdown.js b/packages/markdown/parseMarkdown.js index de7b20ca0800bb..b4c6ff3a87b3ec 100644 --- a/packages/markdown/parseMarkdown.js +++ b/packages/markdown/parseMarkdown.js @@ -3,6 +3,22 @@ const kebabCase = require('lodash/kebabCase'); const textToHash = require('./textToHash'); const prism = require('./prism'); +/** + * Option used by `marked` the library parsing markdown. + */ +const markedOptions = { + gfm: true, + tables: true, + breaks: false, + pedantic: false, + sanitize: false, + smartLists: true, + smartypants: false, + headerPrefix: false, + headerIds: false, + mangle: false, +}; + const headerRegExp = /---[\r\n]([\s\S]*)[\r\n]---/; const titleRegExp = /# (.*)[\r\n]/; const descriptionRegExp = /

(.*?)<\/p>/s; @@ -188,7 +204,7 @@ function getDescription(markdown) { * @param {string} markdown */ function renderInline(markdown) { - return marked.parseInline(markdown, { headerIds: false, mangle: false }); + return marked.parseInline(markdown, markedOptions); } // Help rank mui.com on component searches first. @@ -350,20 +366,6 @@ function createRender(context) { ].join('')}\n`; }; - const markedOptions = { - gfm: true, - tables: true, - breaks: false, - pedantic: false, - sanitize: false, - smartLists: true, - smartypants: false, - headerPrefix: false, - headerIds: false, - mangle: false, - renderer, - }; - marked.use({ extensions: [ { @@ -399,7 +401,7 @@ function createRender(context) { ], }); - return marked(markdown, markedOptions); + return marked(markdown, { ...markedOptions, renderer }); } return render;