aboutsummaryrefslogtreecommitdiff
path: root/runtime/lua/tohtml.lua
diff options
context:
space:
mode:
Diffstat (limited to 'runtime/lua/tohtml.lua')
-rw-r--r--runtime/lua/tohtml.lua60
1 files changed, 37 insertions, 23 deletions
diff --git a/runtime/lua/tohtml.lua b/runtime/lua/tohtml.lua
index e3c7fc68c0..505de720ba 100644
--- a/runtime/lua/tohtml.lua
+++ b/runtime/lua/tohtml.lua
@@ -25,13 +25,7 @@
-- Remarks:
-- - Not all visuals are supported, so it may differ.
---- @class vim.tohtml.opt
---- @field title? string|false
---- @field number_lines? boolean
---- @field font? string[]|string
---- @field width? integer
-
---- @class vim.tohtml.state.global
+--- @class (private) vim.tohtml.state.global
--- @field background string
--- @field foreground string
--- @field title string|false
@@ -39,7 +33,7 @@
--- @field highlights_name table<integer,string>
--- @field conf vim.tohtml.opt
---- @class vim.tohtml.state:vim.tohtml.state.global
+--- @class (private) vim.tohtml.state:vim.tohtml.state.global
--- @field style vim.tohtml.styletable
--- @field tabstop string|false
--- @field opt vim.wo
@@ -48,20 +42,20 @@
--- @field width integer
--- @field buflen integer
---- @class vim.tohtml.styletable
+--- @class (private) vim.tohtml.styletable
--- @field [integer] vim.tohtml.line (integer: (1-index, exclusive))
---- @class vim.tohtml.line
+--- @class (private) vim.tohtml.line
--- @field virt_lines {[integer]:{[1]:string,[2]:integer}[]}
--- @field pre_text string[][]
--- @field hide? boolean
--- @field [integer] vim.tohtml.cell? (integer: (1-index, exclusive))
---- @class vim.tohtml.cell
+--- @class (private) vim.tohtml.cell
--- @field [1] integer[] start
--- @field [2] integer[] close
---- @field [3] any[][] virt_text
---- @field [4] any[][] overlay_text
+--- @field [3] any[][] virt_text
+--- @field [4] any[][] overlay_text
local HIDE_ID = -1
-- stylua: ignore start
@@ -437,13 +431,13 @@ local function styletable_treesitter(state)
end
buf_highlighter.tree:parse(true)
buf_highlighter.tree:for_each_tree(function(tstree, tree)
- --- @cast tree LanguageTree
+ --- @cast tree vim.treesitter.LanguageTree
if not tstree then
return
end
local root = tstree:root()
local q = buf_highlighter:get_query(tree:lang())
- --- @type Query?
+ --- @type vim.treesitter.Query?
local query = q:query()
if not query then
return
@@ -581,7 +575,10 @@ local function styletable_extmarks(state)
--TODO(altermo) extmarks may have col/row which is outside of the buffer, which could cause an error
local bufnr = state.bufnr
local extmarks = vim.api.nvim_buf_get_extmarks(bufnr, -1, 0, -1, { details = true })
- local namespaces = vim.tbl_add_reverse_lookup(vim.api.nvim_get_namespaces())
+ local namespaces = {} --- @type table<integer, string>
+ for ns, ns_id in pairs(vim.api.nvim_get_namespaces()) do
+ namespaces[ns_id] = ns
+ end
for _, v in ipairs(extmarks) do
_styletable_extmarks_highlight(state, v, namespaces)
end
@@ -912,7 +909,9 @@ local function styletable_listchars(state)
if listchars.nbsp then
for _, match in
- ipairs(vim.fn.matchbufline(state.bufnr, '\xe2\x80\xaf\\|\xa0', 1, '$') --[[@as (table[])]])
+ ipairs(
+ vim.fn.matchbufline(state.bufnr, '\226\128\175\\|\194\160', 1, '$') --[[@as (table[])]]
+ )
do
style_line_insert_overlay_char(
state.style[match.lnum],
@@ -1319,14 +1318,29 @@ end
local M = {}
+--- @class vim.tohtml.opt
+--- @inlinedoc
+---
+--- Title tag to set in the generated HTML code.
+--- (default: buffer name)
+--- @field title? string|false
+---
+--- Show line numbers.
+--- (default: `false`)
+--- @field number_lines? boolean
+---
+--- Fonts to use.
+--- (default: `guifont`)
+--- @field font? string[]|string
+---
+--- Width used for items which are either right aligned or repeat a character
+--- infinitely.
+--- (default: 'textwidth' if non-zero or window width otherwise)
+--- @field width? integer
+
--- Converts the buffer shown in the window {winid} to HTML and returns the output as a list of string.
--- @param winid? integer Window to convert (defaults to current window)
---- @param opt? vim.tohtml.opt (table) Optional parameters.
---- - title (string): Title tag to set in the generated HTML code (defaults to buffer name)
---- - number_lines (boolean): Show line numbers (defaults to `false`)
---- - font (string|string[]): Fonts to use (defaults to `guifont`)
---- - width (integer) Width used for items which are either right aligned or repeat a character infinitely
---- (defaults to 'textwidth' if non-zero or window width otherwise)
+--- @param opt? vim.tohtml.opt Optional parameters.
--- @return string[]
function M.tohtml(winid, opt)
return win_to_html(winid or 0, opt)