-
Notifications
You must be signed in to change notification settings - Fork 70
Development
Normally, the sub-commands can be triggered with,
vim.cmd("Markview <sub-command>");But they can also be triggered using pure Lua.
local sub_commands = require("markview.commands");
sub_commands.Toggle();The function name matches with the sub-command name(e.g. sub_commands.splitToggle() is the same as :Markview splitToggle).
Functions/sub-commands that start with a small letter optionally take the buffer as a parameter.
You can use markview to render markdown & other filetypes in your plugins.
This is the recommended way to use markview within external plugins.
You can use this if you,
- Don't want to manually set up
concealcursor,concealleveletc. - Would like to render with your own configuration.
- Have rendering on demand(like
fzf-lua).
if package.loaded["markview"] then
local render = require("markview").strict_render;
-- `buffer` is where you want to render in.
render:render(buffer);
endImportant
The buffer must be cleared using the API function before calling :render() again.
You can clear a buffer like so,
if package.loaded["markview"] then
local render = require("markview").strict_render;
render:clear(buffer);
endIf you don't need stuff like hybrid mode in your preview you can disable them like so,
local render = require("markview").strict_render;
render:render(buffer, {
hybrid_mode = false
});Each buffer has the following states,
---@class markview.state.buf
---
---@field enable boolean Is the `preview` enabled?
---@field hybrid_mode boolean Is `hybrid_mode` enabled?If you want the preview looking a certain way you can do so with this,
local render = require("markview").strict_render;
render:render(buffer, nil, {
markdown = {
heading = { enable = false }
},
-- ...
});Configuration table is the same as setup().
Note
This will not set concealcursor, conceallevel etc., you will need to set them yourself!
To use it add the following code to your plugin,
if package.loaded["markview"] then
-- `buffer` is where you want to render in.
require("markview").render(buffer);
endTo clear previews use,
if package.loaded["markview"] then
-- `buffer` is where you want to render in.
require("markview").clear(buffer);
endYou can use markview to parse files.
This is useful if you have extended syntax or simply don't want to build a parser yourself.
local parser = require("markview.parser");
local data, sorted = parser.init(buffer);
vim.print(data);data is a map between the language & a list of parsed nodes.
---@class markview.parsed
---
---@field html? markview.parsed.html[]
---@field latex? markview.parsed.latex[]
---@field markdown? markview.parsed.markdown[]
---@field markdown_inline? markview.parsed.markdown_inline[]
---@field typst? markview.parsed.typst[]
---@field yaml? markview.parsed.yaml[]sorted is a map between the language & another map between node names & a list of parsed nodes.
---@class markview.parsed_sorted
---
---@field html? markview.parsed.html_sorted
---@field latex? markview.parsed.latex_sorted
---@field markdown? markview.parsed.markdown_sorted
---@field markdown_inline? markview.parsed.markdown_inline_sorted
---@field typst? markview.parsed.typst_sorted
---@field yaml? markview.parsed.yaml_sorted