MCPcopy
hub / github.com/marktext/marktext / renderHtml

Method renderHtml

packages/muya/src/state/markdownToHtml.ts:95–133  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

93
94 // render pure html by marked
95 async renderHtml() {
96 let html = getHighlightHtml(this.markdown, {
97 superSubScript: this.muya?.options?.superSubScript ?? true,
98 footnote: this.muya?.options?.footnote ?? false,
99 isGitlabCompatibilityEnabled:
100 this.muya?.options?.isGitlabCompatibilityEnabled ?? true,
101 math: this.muya?.options?.math ?? true,
102 });
103
104 html = sanitize(html, EXPORT_DOMPURIFY_CONFIG, false) as string;
105
106 const exportContainer = (this._exportContainer
107 = document.createElement('div'));
108 exportContainer.classList.add('mu-render-container');
109 exportContainer.innerHTML = html;
110 document.body.appendChild(exportContainer);
111
112 // render only render the light theme of mermaid and diagram...
113 await this.renderMermaid();
114 await this.renderDiagram();
115 let result = exportContainer.innerHTML;
116 exportContainer.remove();
117
118 // hack to add arrow marker to output html
119 // TODO: JOCS, are these codes still needed?
120 const paths = document.querySelectorAll('path[id^=raphael-marker-]');
121 const def = '<defs style="-webkit-tap-highlight-color: rgba(0, 0, 0, 0);">';
122 result = result.replace(def, () => {
123 let str = '';
124 for (const path of paths)
125 str += path.outerHTML;
126
127 return `${def}${str}`;
128 });
129
130 this._exportContainer = null;
131
132 return `<article class="markdown-body">${result}</article>`;
133 }
134
135 /**
136 * Get HTML with style

Callers 1

generateMethod · 0.95

Calls 8

renderMermaidMethod · 0.95
renderDiagramMethod · 0.95
getHighlightHtmlFunction · 0.90
sanitizeFunction · 0.90
appendChildMethod · 0.80
addMethod · 0.45
removeMethod · 0.45
replaceMethod · 0.45

Tested by

no test coverage detected