Skip to content

Commit

Permalink
refactor: optimize mdUtil
Browse files Browse the repository at this point in the history
  • Loading branch information
yangfuhai committed Nov 13, 2024
1 parent 62e82a1 commit 8801cef
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/util/mdUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,16 @@ const turndownService = new TurndownService({


export const mdToHtml = (markdown: string) => {
return md.render(markdown);
if (!markdown) return markdown;
const html = md.render(markdown).trim();
if (html.startsWith("<p>") && html.endsWith("</p>")) {
return html.substring(3, html.length - 4);
}
return html;
}


export const htmlToMd = (html: string) => {
if (!html) return html;
return turndownService.turndown(html)
}

0 comments on commit 8801cef

Please sign in to comment.