Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
brianhuster committed Oct 17, 2024
1 parent 9202845 commit ce1e26c
Show file tree
Hide file tree
Showing 19 changed files with 18,816 additions and 2,649 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,8 @@ Since this is a young project, there should be a lot of rooms for improvements.
## Acknowledgements
* [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
* [markdown-it/markdown-it](https://github.com/markdown-it/markdown-it) for parsing Markdown files
* [asciidoctor/asciidoctor.js](https://github.com/asciidoctor/asciidoctor.js) for parsing AsciiDoc files
* [KaTeX](https://github.com/KaTeX/KaTeX) for rendering math equations
* [mermaid-js/mermaid](https://github.com/mermaid-js/mermaid) for rendering diagrams
Expand Down
3 changes: 1 addition & 2 deletions README.vi.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,8 @@ Vì đây là một dự án khá mới, hẳn sẽ có nhiều điều cần c
## Cảm ơn
* [Live Server](https://marketplace.visualstudio.com/items?itemName=ritwickdey.LiveServer)[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
* [markdown-it/markdown-it](https://github.com/markdown-it) 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
* [KaTeX](https://github.com/KaTeX/KaTeX) cho hiển thị phương trình toán học
* [mermaid-js/mermaid](https://github.com/mermaid-js/mermaid) cho hiển thị biểu đồ
Expand Down
2 changes: 2 additions & 0 deletions RELEASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@

Code block syntax highlighting in markdown and Asciidoc files

Change the markdown parser from marked.js to markdown-it

**⚠️ Important Notice:** You must clear the cache of the browser after updating to ensure the plugin works correctly.
20 changes: 5 additions & 15 deletions lua/livepreview/template.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,32 +11,23 @@ local html_template = function(body, stylesheet, script_tag)
<title>Live preview</title>
]] .. stylesheet .. [[
<link rel="stylesheet" href="/live-preview.nvim/static/katex/katex.min.css">
<script defer src="/live-preview.nvim/static/katex/katex.min.js"></script>
<script defer src="/live-preview.nvim/static/katex/auto-render.min.js" onload="renderMathInElement(document.body);"></script>
<script src="/live-preview.nvim/static/mermaid/mermaid.min.js"></script>
<link rel="stylesheet" href="/live-preview.nvim/static/highlight/default.min.css">
<script defer src="/live-preview.nvim/static/highlight/highlight.min.js"></script>
]] .. script_tag .. [[
<script defer src="/live-preview.nvim/static/scroll.js"></script>
<script defer src='/live-preview.nvim/static/ws-client.js'></script>
</head>
<body>
<div class="markdown-body">
]] .. body .. [[
</div>
<script defer src="/live-preview.nvim/static/katex/main.js"></script>
<script defer src="/live-preview.nvim/static/mermaid/main.js"></script>
]] .. script_tag .. [[
<script defer type="module" src='/live-preview.nvim/static/ws-client.js'></script>
</body>
</html>
]]
end

M.md2html = function(md)
local script = [[
<script defer src="/live-preview.nvim/static/markdown/line-numbers.js"></script>
<script defer src='/live-preview.nvim/static/markdown/markdown-it.min.js'></script>
<script defer src='/live-preview.nvim/static/markdown/main.js'></script>
<script defer type="module" src='/live-preview.nvim/static/markdown/main.js'></script>
]]
local stylesheet = [[
<link rel="stylesheet" href="/live-preview.nvim/static/markdown/github-markdown.min.css">
Expand All @@ -47,8 +38,7 @@ end

M.adoc2html = function(adoc)
local script = [[
<script defer src="/live-preview.nvim/static/asciidoc/asciidoctor.min.js"></script>
<script defer src='/live-preview.nvim/static/asciidoc/main.js'></script>
<script defer type="module" src='/live-preview.nvim/static/asciidoc/main.js'></script>
]]
local stylesheet = [[
<link rel="stylesheet" href="/live-preview.nvim/static/asciidoc/asciidoctor.min.css">
Expand All @@ -68,7 +58,7 @@ end


M.handle_body = function(data)
local ws_script = "<script src='/live-preview.nvim/static/ws-client.js'></script>"
local ws_script = [[<script type='module' src='/live-preview.nvim/static/ws-client.js'></script>]]
local body
if data:match("<head>") then
body = data:gsub("<head>", "<head>" .. ws_script)
Expand Down
37 changes: 11 additions & 26 deletions static/asciidoc/asciidoctor.min.js

Large diffs are not rendered by default.

8 changes: 6 additions & 2 deletions static/asciidoc/main.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
const asciidoctor = Asciidoctor();
import hljs from '/live-preview.nvim/highlight/highlight.min.js';

import asciidoctor from './asciidoctor.min.js';

function render(adoc) {
const html = asciidoctor.convert(adoc);
const Asciidoctor = asciidoctor();
const html = Asciidoctor.convert(adoc);
console.log(html);
document.querySelector('.markdown-body').innerHTML = html;
hljs.highlightAll();
}
window.render = render;

const adoc = document.querySelector('.markdown-body').innerHTML;
render(adoc);
Loading

0 comments on commit ce1e26c

Please sign in to comment.