From c6b1a78aaf336ab20df80d2da26d0ebde8220bea Mon Sep 17 00:00:00 2001 From: brianhuster Date: Thu, 17 Oct 2024 13:52:42 +0700 Subject: [PATCH 01/15] update README --- README.md | 1 + README.vi.md | 1 + static/markdown/main.js | 22 ---------------------- 3 files changed, 2 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index 1de946e..9348689 100644 --- a/README.md +++ b/README.md @@ -130,6 +130,7 @@ Since this is a young project, there should be a lot of rooms for improvements. ## TODO - [x] Support for KaTex math in Markdown and AsciiDoc - [x] Support for Mermaid diagrams in Markdown +- [x] Syntax highlighting for code blocks in Markdown and AsciiDoc - [ ] Autoscroll in the browser as you scroll in the Markdown and AsciiDoc files in Neovim - [ ] Support for diagrams in AsciiDoc diff --git a/README.vi.md b/README.vi.md index d8e04f1..cca6cc3 100644 --- a/README.vi.md +++ b/README.vi.md @@ -126,6 +126,7 @@ Vì đây là một dự án khá mới, hẳn sẽ có nhiều điều cần c - [x] Hỗ trợ công thức toán bằng Katex - [x] Hỗ trợ biểu đồ Mermaid trong Markdown +- [x] Tô sáng cú pháp code trong tệp Markdown và AsciiDoc - [ ] Tự động cuộn trang web khi bạn cuộn trong tệp Markdown và AsciiDoc trong Neovim - [ ] Hỗ trợ biểu đồ trong AsciiDoc diff --git a/static/markdown/main.js b/static/markdown/main.js index d2cf6fc..eb105b8 100644 --- a/static/markdown/main.js +++ b/static/markdown/main.js @@ -1,25 +1,3 @@ -// const renderer = { -// code({ text, lang, escaped }) { -// const langString = (lang || '').match(/^\S*/)?.[0]; -// const code = text.replace(/\n$/, '') + '\n'; -// if (!langString) { -// return '
' + code + '
'; -// } -// return `
${code}
` -// }, -// }; -// -// marked.use({ renderer }); -// -// const render = (text) => { -// const html = marked.parse(text, { lineNumbers: true }); -// console.log(html); -// document.querySelector('.markdown-body').innerHTML = html; -// } -// -// const markdownText = document.querySelector('.markdown-body').innerHTML; -// render(markdownText); - const md = window.markdownit({ highlight: function(str, lang) { if (lang && hljs.getLanguage(lang)) { From 993631fe7a4b4e953a94a530a42a69ee19ffb7b5 Mon Sep 17 00:00:00 2001 From: brianhuster Date: Thu, 17 Oct 2024 13:54:16 +0700 Subject: [PATCH 02/15] update --- README.md | 2 ++ README.vi.md | 2 ++ 2 files changed, 4 insertions(+) diff --git a/README.md b/README.md index 9348689..d590d63 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,8 @@ Support Katex for rendering math equations in markdown and AsciiDoc files Supports mermaid for rendering diagrams in markdown files +Syntax highlighting for code blocks in Markdown and AsciiDoc + ### Updates See [RELEASE.md](RELEASE.md) diff --git a/README.vi.md b/README.vi.md index cca6cc3..e3fce4b 100644 --- a/README.vi.md +++ b/README.vi.md @@ -9,6 +9,8 @@ Hỗ trợ Katex để hiển thị các phương trình toán học trong tệp Hỗ trợ mermaid để hiển thị các biểu đồ trong tệp Markdown +Tô sáng cú pháp code trong tệp Markdown và AsciiDoc + ### Cập nhật Xem [RELEASE.md](RELEASE.md) From 4a3d79a11a3b758b5c6b1af3e92c75e90d495730 Mon Sep 17 00:00:00 2001 From: brianhuster Date: Thu, 17 Oct 2024 15:00:21 +0700 Subject: [PATCH 03/15] update README --- README.md | 3 ++- README.vi.md | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index d590d63..b24fdde 100644 --- a/README.md +++ b/README.md @@ -137,8 +137,9 @@ Since this is a young project, there should be a lot of rooms for improvements. - [ ] Support for diagrams in AsciiDoc ## Acknowledgements -* [glacambre/firenvim](https://github.com/glacambre/firenvim) for the sha1 function * [Live Server](https://marketplace.visualstudio.com/items?itemName=ritwickdey.LiveServer) and [Live Preview](https://marketplace.visualstudio.com/items?itemName=ms-vscode.live-server) for the idea inspiration +* [glacambre/firenvim](https://github.com/glacambre/firenvim) for the sha1 function reference +* [iamcco/markdown-preview.nvim](https://github.com/iamcco/markdown-preview.nvim) for some JavaScript reference * [sindresorhus/github-markdown-css](https://github.com/sindresorhus/github-markdown-css) CSS style for Markdown files * [markedjs/marked](https://github.com/markedjs/marked) for parsing Markdown files * [asciidoctor/asciidoctor.js](https://github.com/asciidoctor/asciidoctor.js) for parsing AsciiDoc files diff --git a/README.vi.md b/README.vi.md index e3fce4b..53b910f 100644 --- a/README.vi.md +++ b/README.vi.md @@ -133,8 +133,9 @@ Vì đây là một dự án khá mới, hẳn sẽ có nhiều điều cần c - [ ] Hỗ trợ biểu đồ trong AsciiDoc ## Cảm ơn -* [glacambre/firenvim](https://github.com/glacambre/firenvim) vì hàm sha1 * [Live Server](https://marketplace.visualstudio.com/items?itemName=ritwickdey.LiveServer) và [Live Preview](https://marketplace.visualstudio.com/items?itemName=ms-vscode.live-máy chủ) vì ý tưởng +* [glacambre/firenvim](https://github.com/glacambre/firenvim) vì hàm sha1 +* [iamcco/markdown-preview.nvim](https://github.com/iamcco/markdown-preview.nvim) vì một số tham khảo về JavaScript * [sindresorhus/github-markdown-css](https://github.com/sindresorhus/github-markdown-css) CSS cho tệp Markdown * [markedjs/marked](https://github.com/markedjs/marked) cho việc chuyển đổi tệp Markdown thành HTML * [asciidoctor/asciidoctor.js](https://github.com/asciidoctor/asciidoctor.js) cho việc chuyển đổi tệp AsciiDoc thành HTML From 3450bdb1e775a5f0d6813d0b6f3d4dccfc61f340 Mon Sep 17 00:00:00 2001 From: brianhuster Date: Thu, 17 Oct 2024 17:57:22 +0700 Subject: [PATCH 04/15] add autoscrolling --- lua/livepreview/server/Server.lua | 4 +-- lua/livepreview/template.lua | 1 + static/markdown/line-numbers.js | 44 +++++++++++++++++++++++++++++++ static/markdown/main.js | 1 + static/scroll.js | 2 +- static/ws-client.js | 6 +++++ 6 files changed, 55 insertions(+), 3 deletions(-) create mode 100644 static/markdown/line-numbers.js diff --git a/lua/livepreview/server/Server.lua b/lua/livepreview/server/Server.lua index d9b1dbe..eeece47 100644 --- a/lua/livepreview/server/Server.lua +++ b/lua/livepreview/server/Server.lua @@ -16,7 +16,6 @@ Server.__index = Server local uv = vim.uv local need_scroll = false -local top_line = 1 local filepath = "" local ws_client @@ -36,7 +35,8 @@ local function send_scroll(client) local message = { type = "scroll", filepath = filepath or '', - line = top_line, + cursor = vim.api.nvim_win_get_cursor(0), + length = vim.api.nvim_buf_line_count(0), } websocket.send_json(client, message) need_scroll = false diff --git a/lua/livepreview/template.lua b/lua/livepreview/template.lua index 99e3949..f9b67e0 100644 --- a/lua/livepreview/template.lua +++ b/lua/livepreview/template.lua @@ -35,6 +35,7 @@ end M.md2html = function(md) local script = [[ + - ]] .. script_tag .. [[ + @@ -27,9 +27,7 @@ local html_template = function(body, stylesheet, script_tag) - - ]] end From 62668b1fb9af5747462bd51dbb8785afd6c4852e Mon Sep 17 00:00:00 2001 From: brianhuster Date: Thu, 17 Oct 2024 19:07:02 +0700 Subject: [PATCH 07/15] update --- lua/livepreview/template.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/livepreview/template.lua b/lua/livepreview/template.lua index 2f0229a..f6c564e 100644 --- a/lua/livepreview/template.lua +++ b/lua/livepreview/template.lua @@ -33,7 +33,7 @@ end M.md2html = function(md) local script = [[ - ]] From a1c996124d014495e4b078a5e24907b7307b08c3 Mon Sep 17 00:00:00 2001 From: brianhuster Date: Thu, 17 Oct 2024 19:22:49 +0700 Subject: [PATCH 08/15] fix bug --- lua/livepreview/server/Server.lua | 3 +-- static/ws-client.js | 1 + 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lua/livepreview/server/Server.lua b/lua/livepreview/server/Server.lua index eeece47..86b499f 100644 --- a/lua/livepreview/server/Server.lua +++ b/lua/livepreview/server/Server.lua @@ -46,7 +46,6 @@ end vim.api.nvim_create_autocmd("WinScrolled", { callback = function() need_scroll = true - top_line = vim.fn.line("w0") filepath = vim.api.nvim_buf_get_name(0) if ws_client then send_scroll(ws_client) @@ -117,7 +116,7 @@ function Server:start(ip, port, func) local req_info = handler.request(client, request) if req_info then local path = req_info.path - local if_none_match = req_info.if_none_match + http://localhost:5500/README.md local if_none_match = req_info.if_none_match local file_path = self:routes(path) handler.serve_file(client, file_path, if_none_match) end diff --git a/static/ws-client.js b/static/ws-client.js index 94527e7..25cd89b 100644 --- a/static/ws-client.js +++ b/static/ws-client.js @@ -23,6 +23,7 @@ async function connectWebSocket() { socket.onmessage = (event) => { const message = JSON.parse(event.data); + console.log("Message received: ", message); if (message.type === "reload") { console.log("Reload message received"); From 0f425c511a1751c2d622ba10de9fcd315e20d5af Mon Sep 17 00:00:00 2001 From: brianhuster Date: Thu, 17 Oct 2024 19:27:55 +0700 Subject: [PATCH 09/15] update --- lua/livepreview/server/Server.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/livepreview/server/Server.lua b/lua/livepreview/server/Server.lua index 86b499f..6023007 100644 --- a/lua/livepreview/server/Server.lua +++ b/lua/livepreview/server/Server.lua @@ -116,7 +116,7 @@ function Server:start(ip, port, func) local req_info = handler.request(client, request) if req_info then local path = req_info.path - http://localhost:5500/README.md local if_none_match = req_info.if_none_match + local if_none_match = req_info.if_none_match local file_path = self:routes(path) handler.serve_file(client, file_path, if_none_match) end From 5775302fec384e08eedcd2d8990690ca044c6efc Mon Sep 17 00:00:00 2001 From: brianhuster Date: Thu, 17 Oct 2024 19:34:07 +0700 Subject: [PATCH 10/15] update --- README.md | 2 ++ lua/livepreview/server/Server.lua | 1 + 2 files changed, 3 insertions(+) diff --git a/README.md b/README.md index 0291ecb..36df681 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,8 @@ Syntax highlighting for code blocks in Markdown and AsciiDoc Sync scrolling +NHuw vaayj + ### Updates See [RELEASE.md](RELEASE.md) diff --git a/lua/livepreview/server/Server.lua b/lua/livepreview/server/Server.lua index 6023007..7cf9407 100644 --- a/lua/livepreview/server/Server.lua +++ b/lua/livepreview/server/Server.lua @@ -48,6 +48,7 @@ vim.api.nvim_create_autocmd("WinScrolled", { need_scroll = true filepath = vim.api.nvim_buf_get_name(0) if ws_client then + print("need_scroll", need_scroll) send_scroll(ws_client) end end From 12d79b2754546d8a8001948c7aaeefd4a8e3fc20 Mon Sep 17 00:00:00 2001 From: brianhuster Date: Thu, 17 Oct 2024 19:35:31 +0700 Subject: [PATCH 11/15] update --- lua/livepreview/server/Server.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/livepreview/server/Server.lua b/lua/livepreview/server/Server.lua index 7cf9407..c11dafa 100644 --- a/lua/livepreview/server/Server.lua +++ b/lua/livepreview/server/Server.lua @@ -38,6 +38,7 @@ local function send_scroll(client) cursor = vim.api.nvim_win_get_cursor(0), length = vim.api.nvim_buf_line_count(0), } + vim.print(message) websocket.send_json(client, message) need_scroll = false end @@ -48,7 +49,6 @@ vim.api.nvim_create_autocmd("WinScrolled", { need_scroll = true filepath = vim.api.nvim_buf_get_name(0) if ws_client then - print("need_scroll", need_scroll) send_scroll(ws_client) end end From 83e97ae08fe35dccc652f482ab5a155b384d2c5a Mon Sep 17 00:00:00 2001 From: brianhuster Date: Thu, 17 Oct 2024 19:42:15 +0700 Subject: [PATCH 12/15] update --- README.md | 2 -- static/ws-client.js | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/README.md b/README.md index 36df681..0291ecb 100644 --- a/README.md +++ b/README.md @@ -14,8 +14,6 @@ Syntax highlighting for code blocks in Markdown and AsciiDoc Sync scrolling -NHuw vaayj - ### Updates See [RELEASE.md](RELEASE.md) diff --git a/static/ws-client.js b/static/ws-client.js index 25cd89b..45d3ab6 100644 --- a/static/ws-client.js +++ b/static/ws-client.js @@ -23,7 +23,6 @@ async function connectWebSocket() { socket.onmessage = (event) => { const message = JSON.parse(event.data); - console.log("Message received: ", message); if (message.type === "reload") { console.log("Reload message received"); @@ -37,6 +36,7 @@ async function connectWebSocket() { } } else if (message.type = "scroll") { + console.log("Scroll message received"); scrollToLine.middle({ cursor: message.cursor[1], len: message.len From 887bb63a6d06776ca6b93366a947b9f988d93b39 Mon Sep 17 00:00:00 2001 From: brianhuster Date: Thu, 17 Oct 2024 19:46:53 +0700 Subject: [PATCH 13/15] update --- lua/livepreview/server/Server.lua | 1 - static/ws-client.js | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/lua/livepreview/server/Server.lua b/lua/livepreview/server/Server.lua index c11dafa..6023007 100644 --- a/lua/livepreview/server/Server.lua +++ b/lua/livepreview/server/Server.lua @@ -38,7 +38,6 @@ local function send_scroll(client) cursor = vim.api.nvim_win_get_cursor(0), length = vim.api.nvim_buf_line_count(0), } - vim.print(message) websocket.send_json(client, message) need_scroll = false end diff --git a/static/ws-client.js b/static/ws-client.js index 45d3ab6..501a851 100644 --- a/static/ws-client.js +++ b/static/ws-client.js @@ -23,6 +23,7 @@ async function connectWebSocket() { socket.onmessage = (event) => { const message = JSON.parse(event.data); + console.log(message.type === "scroll"); if (message.type === "reload") { console.log("Reload message received"); @@ -34,8 +35,7 @@ async function connectWebSocket() { renderKatex(); renderMermaid(); } - } - else if (message.type = "scroll") { + } else if (message.type = "scroll") { console.log("Scroll message received"); scrollToLine.middle({ cursor: message.cursor[1], From 5b8e5ea2735453fca320804a796ab644a63bc4e1 Mon Sep 17 00:00:00 2001 From: brianhuster Date: Thu, 17 Oct 2024 19:49:32 +0700 Subject: [PATCH 14/15] update --- static/ws-client.js | 1 + 1 file changed, 1 insertion(+) diff --git a/static/ws-client.js b/static/ws-client.js index 501a851..ca4af3e 100644 --- a/static/ws-client.js +++ b/static/ws-client.js @@ -23,6 +23,7 @@ async function connectWebSocket() { socket.onmessage = (event) => { const message = JSON.parse(event.data); + console.log(message); console.log(message.type === "scroll"); if (message.type === "reload") { From 050b4c0bc9cf82a37282f02b6c69e153ed118e8d Mon Sep 17 00:00:00 2001 From: brianhuster Date: Thu, 17 Oct 2024 19:52:29 +0700 Subject: [PATCH 15/15] update: --- README.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/README.md b/README.md index 0291ecb..b24fdde 100644 --- a/README.md +++ b/README.md @@ -12,8 +12,6 @@ Supports mermaid for rendering diagrams in markdown files Syntax highlighting for code blocks in Markdown and AsciiDoc -Sync scrolling - ### Updates See [RELEASE.md](RELEASE.md)