diff --git a/plugs/markdown/assets/markdown_widget.css b/plugs/markdown/assets/markdown_widget.css index 663e175..0090b0e 100644 --- a/plugs/markdown/assets/markdown_widget.css +++ b/plugs/markdown/assets/markdown_widget.css @@ -46,7 +46,7 @@ body:active #button-bar { } .cm-editor { - padding-left: 10px; + padding-left: 10px; } #button-bar button { @@ -56,7 +56,8 @@ body:active #button-bar { color: var(--root-color); } -#edit-button { +#edit-button, +#source-button { margin-left: -10px; } @@ -68,4 +69,4 @@ li code { iframe { border: none; width: 100%; -} +} \ No newline at end of file diff --git a/plugs/markdown/assets/markdown_widget.js b/plugs/markdown/assets/markdown_widget.js index ad71706..7f885b2 100644 --- a/plugs/markdown/assets/markdown_widget.js +++ b/plugs/markdown/assets/markdown_widget.js @@ -6,6 +6,9 @@ async function init() { document.getElementById("reload-button").addEventListener("click", () => { api({ type: "reload" }); }); + document.getElementById("source-button").addEventListener("click", () => { + document.getElementById("body-content").innerText = originalMarkdown; + }); document.querySelectorAll("a[data-ref]").forEach((el) => { el.addEventListener("click", (e) => { diff --git a/plugs/markdown/markdown_content_widget.ts b/plugs/markdown/markdown_content_widget.ts index df5b834..57a625a 100644 --- a/plugs/markdown/markdown_content_widget.ts +++ b/plugs/markdown/markdown_content_widget.ts @@ -12,21 +12,23 @@ export async function markdownContentWidget( const html = renderMarkdownToHtml(mdTree, { smartHardBreak: true }); return { html: await wrapHTML(html), - script: await prepareJS(), + script: await prepareJS(markdownText), // And add back the markdown text so we can render it in a different way if desired markdown: markdownText, }; } -export async function prepareJS() { +export async function prepareJS(originalMarkdown: string) { const iframeJS = await asset.readAsset("assets/markdown_widget.js"); return ` - const panelHtml = \`${panelHtml}\`; + const panelHtml = ${JSON.stringify(panelHtml)}; + const originalMarkdown = ${JSON.stringify(originalMarkdown)}; ${iframeJS} `; } -export async function wrapHTML(html: string): Promise { +export async function wrapHTML( html: string +): Promise { const css = await asset.readAsset("assets/markdown_widget.css"); return ` @@ -39,9 +41,12 @@ export async function wrapHTML(html: string): Promise {
+
+
${html} +
`; }