Create helper for converting md to html
This commit is contained in:
parent
035dea3795
commit
e8c096108b
13
src/markdownToHtmlHelper.ts
Normal file
13
src/markdownToHtmlHelper.ts
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
import { Remarkable } from "remarkable";
|
||||||
|
|
||||||
|
const replaceNewlinesOutsideOfCodeBlocks = (html: string) => (
|
||||||
|
// Replace all \n with <br> inside the matched <p>...</p> block
|
||||||
|
html.replace(/(<p>[\s\S]*?)\n([\s\S]*?<\/p>)/g, (match) => (
|
||||||
|
match.replace(/\n(?!<\/p>)/g, '<br>')
|
||||||
|
))
|
||||||
|
);
|
||||||
|
|
||||||
|
export const convertMarkdownToHtml = (markdown: string) => {
|
||||||
|
const md = new Remarkable();
|
||||||
|
return replaceNewlinesOutsideOfCodeBlocks(md.render(markdown));
|
||||||
|
};
|
Loading…
Reference in a new issue