I try to create a plugin in lua to render md as marp slides.
I want to import js modules in iframe.
See my tests.
local function getHtmlContent(content)
local content64=encoding.base64Encode(content)
local data={
[[<div style="display: flex; width: 100px; height: 100px">
<textarea id="md" style="flex: 1; resize: none"></textarea>
<div id="render" style="flex: 1; overflow-y: auto"></div>
</div>
<script>
alert(1)
</script>
<script type="module">
import { Marp } from 'https://esm.sh/@marp-team/marp-core?bundle'
import browser from 'https://esm.sh/@marp-team/marp-core/browser'
function b64DecodeUnicode(str) {
return decodeURIComponent(atob(str).split('').map(function(c) {
return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2);
}).join(''));
}
console.log(1)
const marp = new Marp({ script: false })
console.log(2)
md.addEventListener('input', () => {
]],
"const { html, css } = marp.render(b64DecodeUnicode('"..content64.."'))",
[[render.innerHTML = `${html}<style>${css}</style>`
browser(render) // Post-process for browser to apply auto scaling
})
</script>
]]
}
return table.concat(data, "\n")
end
marp={}
marp["visible"]=false
command.define {
name = "Marp - Show",
run = function()
if marp["visible"] == true then
editor.hidePanel("rhs")
else
editor.showPanel("rhs", 2, getHtmlContent(editor.getText()),"console.log(3)")
end
end
}
event.listen {
name = "editor:pageModified",
run = function(e)
editor.showPanel("rhs", 2, getHtmlContent(editor.getText()),"console.log(2)")
end
}
if you integrate js code in js parameter, code is loaded as traditional script tag (node module).
If you insert js code in html, js is not executed.
The creation of plugins is js was not easy but really in lua neither. Debugging is a big stuff.
Any feedback.