MCPcopy Create free account
hub / github.com/async-labs/async / markdownToHtml

Function markdownToHtml

api/server/utils/markdownToHtml.ts:5–46  ·  view source on GitHub ↗
(content: string)

Source from the content-addressed store, hash-verified

3import { marked } from 'marked';
4
5function markdownToHtml(content: string) {
6 const renderer = new marked.Renderer();
7
8 renderer.link = (href, title, text) => {
9 const t = title ? ` title="${title}"` : '';
10
11 if (text.startsWith('<code>@#')) {
12 return `${text.replace('<code>@#', '<code>@')} `;
13 }
14
15 return `
16 <a target="_blank" href="${href}" style="color: #0077ff; cursor: pointer;" rel="nofollow noopener noreferrer"${t}>
17 ${text}
18 </a>
19 `;
20 };
21
22 renderer.listitem = (text) => {
23 const regex1 = RegExp('^<input disabled="" type="checkbox">');
24 const regex2 = RegExp('^<input checked="" disabled="" type="checkbox">');
25
26 if (regex1.test(text) || regex2.test(text)) {
27 return `<li style="list-style: none; margin-left: -24px">${text}</li>`;
28 }
29
30 return `<li>${text}</li>`;
31 };
32
33 marked.setOptions({
34 renderer,
35 breaks: true,
36 highlight(code, lang) {
37 if (!lang) {
38 return hljs.highlightAuto(code).value;
39 }
40
41 return hljs.highlight(lang, code).value;
42 },
43 });
44
45 return marked(he.decode(content));
46}
47
48export { markdownToHtml };

Callers 4

addOrEditMethod · 0.90
editMethod · 0.90
addOrEditMethod · 0.90
editMethod · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected