diff --git a/lua/livepreview/server/fswatch.lua b/lua/livepreview/server/fswatch.lua index 14e70a91..5b2ccb67 100644 --- a/lua/livepreview/server/fswatch.lua +++ b/lua/livepreview/server/fswatch.lua @@ -15,7 +15,7 @@ local uv = vim.uv ---@class Watcher ---@field directory string ----@field watcher uv_fs_event_t +---@field watcher uv.uv_fs_event_t ---@field children Watcher[] ---To call this class, do: ---```lua diff --git a/lua/livepreview/template.lua b/lua/livepreview/template.lua index 89c4fac7..d3556861 100644 --- a/lua/livepreview/template.lua +++ b/lua/livepreview/template.lua @@ -10,7 +10,7 @@ local html_template = function(body, stylesheet, script_tag) Live preview ]] .. stylesheet .. [[ - + diff --git a/scripts/update_readme.lua b/scripts/update_readme.lua index 6bd75b03..5d3856d5 100644 --- a/scripts/update_readme.lua +++ b/scripts/update_readme.lua @@ -1,5 +1,4 @@ #!/usr/bin/env -S nvim -l -local uv = vim.uv local read_file_sync = require("livepreview.utils").read_file local packspec = vim.json.decode(read_file_sync("pkg.json")) diff --git a/static/markdown/main.js b/static/markdown/main.js index d2aafe4a..baac7096 100644 --- a/static/markdown/main.js +++ b/static/markdown/main.js @@ -14,14 +14,9 @@ md.use(livepreview_injectLinenumbersPlugin); md.use(markdownitEmoji); -const livepreview_render = (text) => { - const html = md.render(text); - console.log(html); - document.querySelector('.markdown-body').innerHTML = html; +const livepreview_render = () => { + document.querySelector('.markdown-body').innerHTML = md.render(document.querySelector('.markdown-body').innerHTML); hljs.highlightAll(); } -const markdownText = document.querySelector('.markdown-body').innerHTML; -livepreview_render(markdownText); - - +livepreview_render(); diff --git a/static/mermaid/main.js b/static/mermaid/main.js index c14ad9e5..d1350063 100644 --- a/static/mermaid/main.js +++ b/static/mermaid/main.js @@ -10,6 +10,4 @@ mermaid.initialize({ theme: 'neutral', }); - livepreview_renderMermaid(); - diff --git a/static/ws-client.js b/static/ws-client.js index ea71ef14..b845d6ec 100644 --- a/static/ws-client.js +++ b/static/ws-client.js @@ -9,7 +9,7 @@ function getWebSocketUrl() { return `${protocol}//${hostname}${port}`; } -/** +/** * Check if browser should handle websocket message from server * @param {string} filepath - The path of the file * @returns {boolean} - True if the browser should handle the message, false otherwise @@ -50,10 +50,11 @@ async function connectWebSocket() { if (isRightPath(filepath)) { // Check if the render function is defined before calling it if (typeof livepreview_render !== "undefined") { - livepreview_render(content); + document.querySelector('.markdown-body').innerHTML = content; if (typeof livepreview_renderKatex !== "undefined") { livepreview_renderKatex(); } + livepreview_render(); if (typeof livepreview_renderMermaid !== "undefined") { livepreview_renderMermaid(); }