diff --git a/source/_posts/markdown.md b/source/_posts/markdown.md index 5be5ff3..4d5655d 100644 --- a/source/_posts/markdown.md +++ b/source/_posts/markdown.md @@ -12,6 +12,7 @@ categories: intro: This is a quick reference cheat sheet to the Markdown syntax. plugins: - copyCode + - runCode --- ## Markdown Quick Reference diff --git a/themes/coo/layout/_partial/scripts.ejs b/themes/coo/layout/_partial/scripts.ejs index 7093f53..49dcbb9 100644 --- a/themes/coo/layout/_partial/scripts.ejs +++ b/themes/coo/layout/_partial/scripts.ejs @@ -91,27 +91,27 @@ parent.style = "position: relative;" parent.insertBefore(runButton, codeBlock); - let content = codeBlock.textContent; - let language = [...codeBlock.classList].filter(c => c.startsWith("language-"))[0].replace("language-", ""); - const editorId = ['javascript', 'python'].includes(language) ? 'script' : 'markup'; - const title = codeBlock.closest('.h3-wrap')?.querySelector('h3')?.textContent.replace('#', '') || ''; - - if (language === 'python') { - if (content.includes('>>> ')) { - content = content - .trim() - .split('\n') - .map(line => line.startsWith('>>> ') ? line.replace('>>> ', '') : `# ${line}`) - .join('\n'); - } - if (content.includes('from typing import')) { - language = 'python-wasm'; - } - } - // Add click event listener to run button runButton.addEventListener('click', () => { - const config = { + let content = codeBlock.textContent; + let language = [...codeBlock.classList].filter(c => c.startsWith("language-"))[0].replace("language-", ""); + const editorId = ['javascript', 'python'].includes(language) ? 'script' : 'markup'; + const title = codeBlock.closest('.h3-wrap')?.querySelector('h3')?.textContent.replace('#', '') || ''; + + if (language === 'python') { + if (content.includes('>>> ')) { + content = content + .trim() + .split('\n') + .map(line => line.startsWith('>>> ') ? line.replace('>>> ', '') : `# ${line}`) + .join('\n'); + } + if (content.includes('from typing import')) { + language = 'python-wasm'; + } + } + + let config = { title, activeEditor: editorId, [editorId]: { @@ -123,6 +123,23 @@ } } + if (language === 'markdown') { + config = { + ...config, + style: { + language: 'css', + content: '@import "github-markdown-css";\n\nbody {\n border: 1px solid #e1e4e8;\n border-radius: 4px;\n padding: 20px;\n margin: 20px !important;\n}\n', + }, + script: { + language: 'javascript', + content: 'document.body.classList.add("markdown-body");' + }, + tools: { + status: 'closed', + } + } + } + const plaugroundUrl = livecodes.getPlaygroundUrl({config}); window.open(plaugroundUrl, '_blank'); });