Compare commits

..

No commits in common. "6f53159d7bd5c0ca26b076b5ba25432f3b44acdb" and "f600bc74d1377756d1f58ac5a86049cd9bb2e714" have entirely different histories.

5 changed files with 30 additions and 54 deletions

View file

@ -183,8 +183,8 @@ override individual fields by passing a table instead: >lua
`latex` latexmk -pdf → PDF (with clean support) `latex` latexmk -pdf → PDF (with clean support)
`pdflatex` pdflatex → PDF (single pass, no latexmk) `pdflatex` pdflatex → PDF (single pass, no latexmk)
`tectonic` tectonic → PDF (Rust-based LaTeX engine) `tectonic` tectonic → PDF (Rust-based LaTeX engine)
`markdown` pandoc → HTML (standalone, KaTeX math) `markdown` pandoc → HTML (standalone, embedded)
`github` pandoc → HTML (GitHub-styled, `-f gfm`, KaTeX math) `github` pandoc → HTML (GitHub-styled, `-f gfm` input)
`asciidoctor` asciidoctor → HTML (AsciiDoc with SSE reload) `asciidoctor` asciidoctor → HTML (AsciiDoc with SSE reload)
`plantuml` plantuml → SVG (UML diagrams, `.puml`) `plantuml` plantuml → SVG (UML diagrams, `.puml`)
`mermaid` mmdc → SVG (Mermaid diagrams, `.mmd`) `mermaid` mmdc → SVG (Mermaid diagrams, `.mmd`)
@ -193,36 +193,27 @@ override individual fields by passing a table instead: >lua
Math rendering (pandoc presets): ~ Math rendering (pandoc presets): ~
*preview-math* *preview-math*
The `markdown` and `github` presets use `--katex` by default, which inserts a The `markdown` and `github` presets use `--mathml` by default, which converts
`<script>` tag that loads KaTeX from a CDN at view time. The browser fetches TeX math to native MathML markup rendered by the browser. This is the only
the assets once and caches them, so math renders instantly on subsequent loads. math option compatible with `--embed-resources` (self-contained HTML).
Requires internet on first view.
For offline use, swap in `--mathml` via `extra_args`. MathML is rendered `--mathjax` and `--katex` insert `<script>` tags that load JavaScript and
natively by the browser with no external dependencies: >lua fonts from a CDN at runtime. Pandoc's `--embed-resources` cannot inline these
dynamic dependencies, so math fails to render in the output.
To use KaTeX or MathJax instead, override `args` to drop `--embed-resources`
(the output will require internet access): >lua
vim.g.preview = { vim.g.preview = {
github = { extra_args = { '--mathml' } }, github = {
} args = function(ctx)
< return {
'-f', 'gfm', ctx.file, '-s', '--katex',
Note: pandoc's math flags (`--katex`, `--mathml`, `--mathjax`) are mutually '--css', 'https://cdn.jsdelivr.net/gh/pixelbrackets/gfm-stylesheet@master/dist/gfm.css',
exclusive — last flag wins. Adding `--mathml` via `extra_args` (which is '-o', ctx.output,
appended after `args`) overrides `--katex`. }
end,
Self-contained output with `--embed-resources`: >lua },
vim.g.preview = {
github = { extra_args = { '--embed-resources' } },
}
<
This inlines all external resources into the HTML. With `--katex` this adds
~15s of compile time per save (pandoc fetches KaTeX from the CDN during
compilation). Pair with `--mathml` to avoid the penalty: >lua
vim.g.preview = {
github = { extra_args = { '--embed-resources', '--mathml' } },
} }
< <

View file

@ -329,9 +329,6 @@ function M.compile(bufnr, name, provider, ctx, opts)
s.provider = name s.provider = name
s.is_reload = true s.is_reload = true
if not opts.silent then
vim.notify('[preview.nvim]: compiling...', vim.log.levels.INFO)
end
vim.api.nvim_exec_autocmds('User', { vim.api.nvim_exec_autocmds('User', {
pattern = 'PreviewCompileStarted', pattern = 'PreviewCompileStarted',
data = { bufnr = bufnr, provider = name }, data = { bufnr = bufnr, provider = name },
@ -363,7 +360,6 @@ function M.compile(bufnr, name, provider, ctx, opts)
end end
if result.code == 0 then if result.code == 0 then
log.dbg('compilation succeeded for buffer %d', bufnr) log.dbg('compilation succeeded for buffer %d', bufnr)
vim.notify('[preview.nvim]: compilation complete', vim.log.levels.INFO)
clear_errors(bufnr, provider) clear_errors(bufnr, provider)
vim.api.nvim_exec_autocmds('User', { vim.api.nvim_exec_autocmds('User', {
pattern = 'PreviewCompileSuccess', pattern = 'PreviewCompileSuccess',
@ -407,9 +403,6 @@ function M.compile(bufnr, name, provider, ctx, opts)
s.provider = name s.provider = name
s.is_reload = false s.is_reload = false
if not opts.silent then
vim.notify('[preview.nvim]: compiling...', vim.log.levels.INFO)
end
vim.api.nvim_exec_autocmds('User', { vim.api.nvim_exec_autocmds('User', {
pattern = 'PreviewCompileStarted', pattern = 'PreviewCompileStarted',
data = { bufnr = bufnr, provider = name }, data = { bufnr = bufnr, provider = name },
@ -519,8 +512,8 @@ function M.toggle(bufnr, name, provider, ctx_builder)
log.dbg('watching buffer %d with provider "%s"', bufnr, name) log.dbg('watching buffer %d with provider "%s"', bufnr, name)
end end
vim.notify('[preview.nvim]: compiling with "' .. name .. '"...', vim.log.levels.INFO) vim.notify('[preview.nvim]: watching with "' .. name .. '"', vim.log.levels.INFO)
M.compile(bufnr, name, provider, ctx_builder(bufnr), { silent = true }) M.compile(bufnr, name, provider, ctx_builder(bufnr))
end end
---@param bufnr integer ---@param bufnr integer

View file

@ -224,7 +224,7 @@ M.markdown = {
ft = 'markdown', ft = 'markdown',
cmd = { 'pandoc' }, cmd = { 'pandoc' },
args = function(ctx) args = function(ctx)
return { ctx.file, '-s', '--katex', '-o', ctx.output } return { ctx.file, '-s', '--embed-resources', '--mathml', '-o', ctx.output }
end, end,
output = function(ctx) output = function(ctx)
return (ctx.file:gsub('%.md$', '.html')) return (ctx.file:gsub('%.md$', '.html'))
@ -249,7 +249,8 @@ M.github = {
'gfm', 'gfm',
ctx.file, ctx.file,
'-s', '-s',
'--katex', '--embed-resources',
'--mathml',
'--css', '--css',
'https://cdn.jsdelivr.net/gh/pixelbrackets/gfm-stylesheet@master/dist/gfm.css', 'https://cdn.jsdelivr.net/gh/pixelbrackets/gfm-stylesheet@master/dist/gfm.css',
'-o', '-o',

View file

@ -55,14 +55,6 @@ describe('compiler', function()
end, end,
}) })
local notified = false
local orig = vim.notify
vim.notify = function(msg)
if msg:find('compiling') then
notified = true
end
end
local provider = { cmd = { 'echo', 'ok' } } local provider = { cmd = { 'echo', 'ok' } }
local ctx = { local ctx = {
bufnr = bufnr, bufnr = bufnr,
@ -72,9 +64,7 @@ describe('compiler', function()
} }
compiler.compile(bufnr, 'echo', provider, ctx) compiler.compile(bufnr, 'echo', provider, ctx)
vim.notify = orig
assert.is_true(fired) assert.is_true(fired)
assert.is_true(notified)
vim.wait(2000, function() vim.wait(2000, function()
return process_done(bufnr) return process_done(bufnr)

View file

@ -294,11 +294,11 @@ describe('presets', function()
assert.are.same({ 'pandoc' }, presets.markdown.cmd) assert.are.same({ 'pandoc' }, presets.markdown.cmd)
end) end)
it('returns args with standalone and katex flags', function() it('returns args with standalone, embed-resources, and mathml flags', function()
local args = presets.markdown.args(md_ctx) local args = presets.markdown.args(md_ctx)
assert.is_table(args) assert.is_table(args)
assert.are.same( assert.are.same(
{ '/tmp/document.md', '-s', '--katex', '-o', '/tmp/document.html' }, { '/tmp/document.md', '-s', '--embed-resources', '--mathml', '-o', '/tmp/document.html' },
args args
) )
end) end)
@ -382,7 +382,7 @@ describe('presets', function()
assert.are.same({ 'pandoc' }, presets.github.cmd) assert.are.same({ 'pandoc' }, presets.github.cmd)
end) end)
it('returns args with standalone, katex, and css flags', function() it('returns args with standalone, embed-resources, mathml, and css flags', function()
local args = presets.github.args(md_ctx) local args = presets.github.args(md_ctx)
assert.is_table(args) assert.is_table(args)
assert.are.same({ assert.are.same({
@ -390,7 +390,8 @@ describe('presets', function()
'gfm', 'gfm',
'/tmp/document.md', '/tmp/document.md',
'-s', '-s',
'--katex', '--embed-resources',
'--mathml',
'--css', '--css',
'https://cdn.jsdelivr.net/gh/pixelbrackets/gfm-stylesheet@master/dist/gfm.css', 'https://cdn.jsdelivr.net/gh/pixelbrackets/gfm-stylesheet@master/dist/gfm.css',
'-o', '-o',