-
Notifications
You must be signed in to change notification settings - Fork 54
Typst options
Shawon edited this page Jan 30, 2025
·
4 revisions
Changes how typst items are shown in preview.
-- [ Markview | Typst ] -------------------------------------------------------------------
--- Configuration for Typst.
---@class config.typst
---
---@field enable boolean
---
---@field code_blocks typst.code_blocks | fun(): typst.code_blocks
---@field code_spans typst.code_spans | fun(): typst.code_spans
---@field escapes typst.escapes | fun(): typst.escapes
---@field headings typst.headings | fun(): typst.headings
---@field labels typst.labels | fun(): typst.labels
---@field list_items typst.list_items | fun(): typst.list_items
---@field math_blocks typst.math_blocks | fun(): typst.math_blocks
---@field math_spans typst.math_spans | fun(): typst.math_spans
---@field raw_blocks typst.raw_blocks | fun(): typst.raw_blocks
---@field raw_spans typst.raw_spans | fun(): typst.raw_spans
---@field reference_links typst.reference_links | fun(): typst.reference_links
---@field subscripts typst.subscripts | fun(): typst.subscripts
---@field superscripts typst.subscripts | fun(): typst.superscripts
---@field symbols typst.symbols | fun(): typst.symbols
---@field terms typst.terms | fun(): typst.terms
---@field url_links typst.url_links | fun(): typst.url_links
M.typst = {
enable = true,
code_blocks = {},
code_spans = {},
escapes = {},
headings = {},
labels = {},
list_items = {},
math_spans = {},
math_blocks = {},
raw_spans = {},
raw_blocks = {},
reference_links = {},
subscripts = {},
superscript = {},
symbols = {},
terms = {},
url_links = {},
};
-- [ Markview | Typst • Static ] ----------------------------------------------------------
--- Static configuration for Typst.
---@class config.typst_static
---
---@field enable boolean
---
---@field code_blocks typst.code_blocks Configuration for block of typst code.
---@field code_spans typst.code_spans Configuration for inline typst code.
---@field escapes typst.escapes Configuration for escaped characters.
---@field headings typst.headings Configuration for headings.
---@field labels typst.labels Configuration for labels.
---@field list_items typst.list_items Configuration for list items
---@field math_blocks typst.math_blocks Configuration for blocks of math code.
---@field math_spans typst.math_spans Configuration for inline math code.
---@field raw_blocks typst.raw_blocks Configuration for raw blocks.
---@field raw_spans typst.raw_spans Configuration for raw spans.
---@field reference_links typst.reference_links Configuration for reference links.
---@field subscripts typst.subscripts Configuration for subscript texts.
---@field superscripts typst.subscripts Configuration for superscript texts.
---@field symbols typst.symbols Configuration for typst symbols.
---@field terms typst.terms Configuration for terms.
---@field url_links typst.url_links Configuration for URL links.
- Type:
typst.code_blocks
- Dynamic: true
Configuration for blocks of code.
Expand to see default configuration
-- [ Typst | Code blocks ] ----------------------------------------------------------------
--- Configuration for code blocks.
---@class typst.code_blocks
---
---@field enable boolean
---
---@field hl? string | fun(buffer: integer, item: __typst.code_block): string?
---@field min_width integer | fun(buffer: integer, item: __typst.code_block): integer
---@field pad_amount integer | fun(buffer: integer, item: __typst.code_block): integer
---@field pad_char? string | fun(buffer: integer, item: __typst.code_block): string?
---@field sign? string | fun(buffer: integer, item: __typst.code_block): string
---@field sign_hl? string | fun(buffer: integer, item: __typst.code_block): string?
---@field style ( "simple" | "block" ) | fun(buffer: integer, item: __typst.code_block): ( "simple" | "block" )
---@field text string | fun(buffer: integer, item: __typst.code_block): string
---@field text_direction ( "left" | "right" ) | fun(buffer: integer, item: __typst.code_block): ( "left" | "right" )
---@field text_hl? string | fun(buffer: integer, item: __typst.code_block): string?
code_blocks = {
enable = true,
style = "block",
text_direction = "right",
min_width = 60,
pad_char = " ",
pad_amount = 3,
text = " Code",
hl = "MarkviewCode",
text_hl = "MarkviewIcon5"
};
-- [ Typst | Code blocks • Static ] -------------------------------------------------------
--- Static configuration for code blocks.
---@class typst.code_blocks_static
---
---@field enable boolean
---
---@field hl? string
---@field min_width integer Minimum width of code blocks.
---@field pad_amount integer Number of paddings added around the text.
---@field pad_char? string Character to use for padding.
---@field sign? string Sign for the code block.
---@field sign_hl? string Highlight group for the sign.
---@field style
---| "simple" Only highlights the lines inside this block.
---| "block" Creates a box around the code block.
---@field text string Text to use as the label.
---@field text_direction
---| "left" Shows label on the top-left side of the block
---| "right" Shows label on the top-right side of the block
---@field text_hl? string Highlight group for the label
Expand to see type definition & advanced usage
-- [ Typst | Code blocks > Parameters ] ---------------------------------------------------
---@class __typst.code_block
---@field class "typst_code_block"
---@field text string[]
---@field range node.range
M.__typst_codes = {
class = "typst_code_block",
text = {
"#{",
" let a = [from]",
"}"
},
range = {
row_start = 0,
row_end = 2,
col_start = 0,
col_end = 1
}
};
- Type:
typst.code_spans
- Dynamic: true
Configuration for spans of code.
Expand to see default configuration
-- [ Typst | Code spans ] ----------------------------------------------------------------
--- Configuration for code spans.
---@class typst.code_spans
---
---@field enable boolean
---
---@field corner_left? string | fun(buffer: integer, item: __typst.code_spans): string?
---@field corner_left_hl? string | fun(buffer: integer, item: __typst.code_spans): string?
---@field corner_right? string | fun(buffer: integer, item: __typst.code_spans): string?
---@field corner_right_hl? string | fun(buffer: integer, item: __typst.code_spans): string?
---@field hl? string | fun(buffer: integer, item: __typst.code_spans): string?
---@field padding_left? string | fun(buffer: integer, item: __typst.code_spans): string?
---@field padding_left_hl? string | fun(buffer: integer, item: __typst.code_spans): string?
---@field padding_right? string | fun(buffer: integer, item: __typst.code_spans): string?
---@field padding_right_hl? string | fun(buffer: integer, item: __typst.code_spans): string?
code_spans = {
enable = true,
padding_left = " ",
padding_right = " ",
hl = "MarkviewCode"
};
-- [ Typst | Code spans • Static ] -------------------------------------------------------
--- Static configuration for code spans.
---@class typst.code_spans_static
---
---@field enable boolean
---
---@field corner_left? string Left corner.
---@field corner_left_hl? string Highlight group for left corner.
---@field corner_right? string Right corner.
---@field corner_right_hl? string Highlight group for right corner.
---@field hl? string Base Highlight group.
---@field padding_left? string Left padding.
---@field padding_left_hl? string Highlight group for left padding.
---@field padding_right? string Right padding.
---@field padding_right_hl? string Highlight group for right padding.
Expand to see type definition & advanced usage
-- [ Typst | Code spans > Parameters ] ----------------------------------------------------
---@class __typst.code_spans
---@field class "typst_code_span"
---@field text string[]
---@field range node.range
M.__typst_codes = {
class = "typst_code_span",
text = { "#{ let a = 1 }" },
range = {
row_start = 0,
row_end = 0,
col_start = 0,
col_end = 13
}
};
- Type:
typst.escapes
- Dynamic: false
Configuration for escaped characters.
Expand to see default configuration
-- [ Typst | Escapes ] ---------------------------------------------------------------------
---@class typst.escapes
---
---@field enable boolean
escapes = { enable = true };
Expand to see type definition & advanced usage
-- [ Typst | Escapes > Parameters ] -------------------------------------------------------
---@class __typst.escapes
---
---@field class "typst_escaped"
---@field text string[]
---@field range node.range
M.__typst_escapes = {
class = "typst_escaped",
text = { "\\|" },
range = {
row_start = 0,
row_end = 0,
col_start = 0,
col_end = 2
}
};
- Type:
typst.headings
- Dynamic: true
Configuration for headings.
Expand to see default configuration
-- [ Typst | Headings ] -------------------------------------------------------------------
--- Configuration for Typst headings.
---@class typst.headings
---
---@field enable boolean
---
---@field shift_width integer Amount of spaces to shift per heading level.
---
---@field [string] headings.typst Heading level configuration(name format: "heading_%d", %d = heading level).
headings = {
enable = true,
shift_width = 1,
heading_1 = {
style = "icon",
sign = " ", sign_hl = "MarkviewHeading1Sign",
icon = " ", hl = "MarkviewHeading1",
},
heading_2 = {
style = "icon",
sign = " ", sign_hl = "MarkviewHeading2Sign",
icon = " ", hl = "MarkviewHeading2",
},
heading_3 = {
style = "icon",
icon = " ", hl = "MarkviewHeading3",
},
heading_4 = {
style = "icon",
icon = " ", hl = "MarkviewHeading4",
},
heading_5 = {
style = "icon",
icon = " ", hl = "MarkviewHeading5",
},
heading_6 = {
style = "icon",
icon = " ", hl = "MarkviewHeading6",
}
};
Expand to see type definition & advanced usage
-- [ Typst | Headings > Type definitions ] ------------------------------------------------
--- Heading level configuration.
---@class headings.typst
---
---@field style "simple" | "icon"
---@field hl? string
---@field icon? string
---@field icon_hl? string
---@field sign? string
---@field sign_hl? string
M.headings_typst = {
style = "simple",
hl = "MarkviewHeading1"
} or {
style = "icon",
icon = "~",
hl = "MarkviewHeading1"
};
-- [ Typst | Headings > Parameters ] ------------------------------------------------------
---@class __typst.headings
---
---@field class "typst_heading"
---
---@field level integer Heading level.
---
---@field text string[]
---@field range node.range
M.__typst_headings = {
class = "typst_heading",
level = 1,
text = { "= Heading 1" },
range = {
row_start = 0,
row_end = 0,
col_start = 0,
col_end = 10
}
};
- Type:
typst.labels
- Dynamic: true
Configuration for labels.
Expand to see default configuration
-- [ Typst | Labels ] ---------------------------------------------------------------------
--- Configuration for typst labels.
---@class typst.labels
---
---@field enable boolean
---
---@field default config.inline_generic | fun(buffer: integer, item: __typst.labels): config.inline_generic
---@field [string] config.inline_generic | fun(buffer: integer, item: __typst.labels): config.inline_generic
labels = {
enable = true,
default = {
hl = "MarkviewInlineCode",
padding_left = " ",
icon = " ",
padding_right = " "
},
};
-- [ Typst | Labels • Static ] ------------------------------------------------------------
--- Static configuration for typst labels.
---@class typst.labels
---
---@field enable boolean
---
---@field default config.inline_generic Default configuration for labels.
---@field [string] config.inline_generic Configuration for labels whose text matches `string`.
Expand to see type definition & advanced usage
-- [ Typst | Labels > Parameters ] --------------------------------------------------------
---@class __typst.labels
---
---@field class "typst_labels"
---
---@field text string[]
---@field range node.range
M.__typst_labels = {
class = "typst_labels",
text = { "<label>" },
range = {
row_start = 0,
row_end = 0,
col_start = 0,
col_end = 7
}
};
- Type:
typst.list_items
- Dynamic: true
Configuration for various types of list items.
Expand to see default configuration
-- [ Typst | List items ] -----------------------------------------------------------------
--- Configuration for list items.
---@class typst.list_items
---
---@field enable boolean
---
---@field indent_size integer Indentation size for list items.
---@field shift_width integer Preview indentation size for list items.
---
---@field marker_dot list_items.ordered Configuration for `n.` list items.
---@field marker_minus list_items.typst Configuration for `-` list items.
---@field marker_plus list_items.typst Configuration for `+` list items.
list_items = {
enable = true,
indent_size = 2,
shift_width = 4,
marker_minus = {
add_padding = true,
text = "",
hl = "MarkviewListItemMinus"
},
marker_plus = {
add_padding = true,
text = "%d)",
hl = "MarkviewListItemPlus"
},
marker_dot = {
add_padding = true,
}
},
Expand to see type definition & advanced usage
-- [ Typst | List items > Type definitions ] ----------------------------------------------
---@class list_items.typst
---
---@field enable? boolean
---
---@field add_padding boolean
---@field hl? string
---@field text string
M.list_items_unordered = {
enable = true,
hl = "MarkviewListItemPlus",
text = "•",
add_padding = true,
conceal_on_checkboxes = true
};
-- [ Typst | List items > Parameters ] ----------------------------------------------------
---@class __typst.list_items
---
---@field class "typst_list_item"
---@field indent integer
---@field marker "+" | "-" | string
---@field number? integer Number to show on the list item when previewing.
---@field text string[]
---@field range node.range
M.__typst_list_items = {
class = "typst_list_item",
indent = 0,
marker = "-",
text = { "- List item" },
range = {
row_start = 0,
row_end = 0,
col_start = 0,
col_end = 11
}
};
- Type:
typst.math_blocks
- Dynamic: true
Configuration for math blocks.
Expand to see default configuration
-- [ Typst | Math blocks ] -----------------------------------------------------------------
--- Configuration for math blocks.
---@class typst.math_blocks
---
---@field enable boolean
---
---@field hl? string
---@field pad_amount integer Number of `pad_char` to add before the lines.
---@field pad_char string Text used as padding.
---@field text string
---@field text_hl? string
math_blocks = {
enable = true,
text = " Math ",
pad_amount = 3,
pad_char = " ",
hl = "MarkviewCode",
text_hl = "MarkviewCodeInfo"
};
Expand to see type definition & advanced usage
-- [ Typst | Math blocks > Parameters ] ---------------------------------------------------
---@class __typst.maths
---
---@field class "typst_math"
---
---@field inline boolean Should we render it inline?
---@field closed boolean Is the node closed(ends with `$$`)?
---
---@field text string[]
---@field range node.range
M.__typst_maths = {
class = "typst_math",
inline = true,
closed = true,
text = { "$ 1 + 2 $" },
range = {
row_start = 0,
row_end = 0,
col_start = 0,
col_end = 9
}
};
- Type:
typst.math_spans
- Dynamic: true
Configuration for math spans.
Expand to see default configuration
---@alias typst.math_spans config.inline_generic
math_spans = {
enable = true,
padding_left = " ",
padding_right = " ",
hl = "MarkviewInlineCode"
};
Expand to see type definition & advanced usage
-- [ Typst | Math spans > Parameters ] ----------------------------------------------------
---@class __typst.maths
---
---@field class "typst_math"
---
---@field inline boolean Should we render it inline?
---@field closed boolean Is the node closed(ends with `$$`)?
---
---@field text string[]
---@field range node.range
M.__typst_maths = {
class = "typst_math",
inline = true,
closed = true,
text = { "$ 1 + 2 $" },
range = {
row_start = 0,
row_end = 0,
col_start = 0,
col_end = 9
}
};
- Type:
typst.raw_blocks
- Dynamic: true
Configuration for raw blocks.
Expand to see default configuration
-- [ Typst | Raw blocks ] -----------------------------------------------------------------
---@class typst.raw_blocks
---
---@field enable boolean
---
---@field border_hl? string | fun(buffer: integer, item: __typst.raw_blocks): string?
---@field label_direction? ( "left" | "right" ) | fun(buffer: integer, item: __typst.raw_blocks): ( "left" | "right" )
---@field label_hl? string | fun(buffer: integer, item: __typst.raw_blocks): string?
---@field min_width integer | fun(buffer: integer, item: __typst.raw_blocks): integer
---@field pad_amount? integer | fun(buffer: integer, item: __typst.raw_blocks): integer
---@field pad_char? string | fun(buffer: integer, item: __typst.raw_blocks): string?
---@field sign? boolean | fun(buffer: integer, item: __typst.raw_blocks): boolean?
---@field sign_hl? string | fun(buffer: integer, item: __typst.raw_blocks): string?
---@field style ( "simple" | "block" ) | fun(buffer: integer, item: __typst.raw_blocks): ( "simple" | "block" )
---
---@field default raw_blocks.opts | fun(buffer: integer, item: __typst.raw_blocks): raw_blocks.opts
---@field [string] raw_blocks.opts | fun(buffer: integer, item: __typst.raw_blocks): raw_blocks.opts
raw_blocks = {
enable = true,
style = "block",
label_direction = "right",
sign = true,
min_width = 60,
pad_amount = 3,
pad_char = " ",
border_hl = "MarkviewCode",
default = {
block_hl = "MarkviewCode",
pad_hl = "MarkviewCode"
},
["diff"] = {
block_hl = function (_, line)
if line:match("^%+") then
return "MarkviewPalette4";
elseif line:match("^%-") then
return "MarkviewPalette1";
else
return "MarkviewCode";
end
end,
pad_hl = "MarkviewCode"
}
};
-- [ Typst | Raw blocks • Static ] --------------------------------------------------------
---@class typst.raw_blocks
---
---@field enable boolean
---
---@field border_hl? string Highlight group for top & bottom border of raw blocks.
---@field label_direction? "left" | "right" Changes where the label is shown.
---@field label_hl? string Highlight group for the label
---@field min_width? integer Minimum width of the code block.
---@field pad_amount? integer Left & right padding size.
---@field pad_char? string Character to use for the padding.
---@field sign? boolean Whether to show signs for the code blocks.
---@field sign_hl? string Highlight group for the signs.
---@field style "simple" | "block" Preview style for code blocks.
---
---@field default raw_blocks.opts_static Default line configuration for the raw block.
---@field [string] raw_blocks.opts_static Line configuration for the raw block whose `language` matches `string`
Expand to see type definition & advanced usage
-- [ Typst | Raw blocks > Type definitions ] -----------------------------------------------
--- Configuration for highlighting a line inside a raw block.
---@class raw_blocks.opts
---
---@field block_hl string | fun(buffer: integer, line: string): string?
---@field pad_hl string | fun(buffer: integer, line: string): string?
--- Static configuration for highlighting a line inside a raw block.
---@class raw_blocks.opts_static
---
---@field block_hl string? Highlight group for the background of the line.
---@field pad_hl string? Highlight group for the padding of the line.
-- [ Typst | Raw blocks > Parameters ] ----------------------------------------------------
---@class __typst.raw_blocks
---
---@field class "typst_raw_block"
---@field language? string
---@field text string[]
---@field range node.range
M.__typst_raw_blocks = {
class = "typst_raw_block",
language = "lua",
text = {
"```lua",
'vim.print("Hello, Neovim")',
"```"
},
range = {
row_start = 0,
row_end = 2,
col_start = 0,
col_end = 3
}
};
- Type:
typst.raw_spans
- Dynamic: true
Configuration for raw spans.
Expand to see default configuration
-- [ Typst | Raw spans ] ------------------------------------------------------------------
---@alias typst.raw_spans config.inline_generic
raw_spans = {
enable = true,
padding_left = " ",
padding_right = " ",
hl = "MarkviewInlineCode"
},
Expand to see type definition & advanced usage
-- [ Typst | Raw spans > Parameters ] -----------------------------------------------------
---@class __typst.raw_spans
---
---@field class "typst_raw_span"
---
---@field text string[]
---@field range node.range
M.__typst_raw_spans = {
class = "typst_raw_span",
text = { "`hi`" },
range = {
row_start = 0,
row_end = 0,
col_start = 0,
col_end = 4
}
};
- Type:
typst.reference_links
- Dynamic: true
Configuration for reference links.
Expand to see default configuration
---@class typst.reference_links
---
---@field enable boolean
---
---@field default config.inline_generic Default configuration for reference links.
---@field [string] config.inline_generic Configuration for reference links whose label matches `string`.
reference_links = {
enable = true,
default = {
icon = " ",
hl = "MarkviewHyperlink"
}
};
Expand to see type definition & advanced usage
-- [ Typst | Reference links > Parameters ] -----------------------------------------------
---@class __typst.reference_links
---
---@field class "typst_link_ref"
---
---@field label string
---
---@field text string[]
---@field range inline_link.range
M.__typst_link_ref = {
class = "typst_link_ref",
label = "label",
text = { "@label" },
range = {
row_start = 0,
row_end = 0,
col_start = 0,
col_end = 6,
label = { 0, 1, 0, 6 }
}
};
- Type:
typst.subscripts
- Dynamic: true
Configuration for subscript texts.
Expand to see default configuration
--- Configuration for subscript text.
---@class typst.subscripts
---
---@field enable boolean
---@field fake_preview? boolean When `true`, fake subscript characters.
---
---@field hl? string | string[]
---@field marker_left? string
---@field marker_right? string
subscripts = {
enable = true,
hl = "MarkviewSubscript"
};
Expand to see type definition & advanced usage
-- [ Typst | Subscripts > Parameters ] ----------------------------------------------------
---@class __typst.subscripts
---
---@field class "typst_subscript"
---@field parenthesis boolean Whether the text is surrounded by parenthesis.
---@field level integer Subscript level.
---@field text string[]
---@field range node.range
M.__typst_subscripts = {
class = "typst_subscript",
parenthesis = true,
preview = true,
level = 1,
text = { "_{12}" },
range = {
row_start = 0,
row_end = 0,
col_start = 0,
col_end = 5
}
};
- Type:
typst.superscripts
- Dynamic: true
Configuration for superscript texts.
Expand to see default configuration
--- Configuration for superscript text.
---@class typst.superscripts
---
---@field enable boolean
---@field fake_preview? boolean When `true`, fake superscript characters.
---
---@field hl? string | string[]
---@field marker_left? string
---@field marker_right? string
superscripts = {
enable = true,
hl = "MarkviewSuperscript"
};
Expand to see type definition & advanced usage
-- [ Typst | Superscripts > Parameters ] --------------------------------------------------
---@class __typst.superscripts
---
---@field class "typst_superscript"
---@field parenthesis boolean Whether the text is surrounded by parenthesis.
---@field level integer Superscript level.
---@field text string[]
---@field range node.range
M.__typst_superscripts = {
class = "typst_superscript",
parenthesis = true,
preview = true,
level = 1,
text = { "^{12}" },
range = {
row_start = 0,
row_end = 0,
col_start = 0,
col_end = 5
}
};
- Type:
typst.symbols
- Dynamic: true
Configuration for typst symbols.
Expand to see default configuration
--- Configuration for symbols in typst.
---@class typst.symbols
---
---@field enable boolean
---@field hl? string
symbols = {
enable = true,
hl = "Special"
};
Expand to see type definition & advanced usage
-- [ Typst | Symbols > Parameters ] -------------------------------------------------------
---@class __typst.symbols
---
---@field class "typst_symbol"
---@field name string
---@field text string[]
---@field range node.range
M.__typst_symbols = {
class = "typst_symbol",
name = "alpha",
text = { "alpha" },
range = {
row_start = 0,
row_end = 0,
col_start = 0,
col_end = 5
}
};
- Type:
typst.terms
- Dynamic: true
Configuration for terms.
Expand to see default configuration
---@class typst.terms
---
---@field enable boolean
---
---@field default term.opts Default configuration for terms.
---@field [string] term.opts Configuration for terms whose label matches `string`.
terms = {
enable = true,
default = {
text = " ",
hl = "MarkviewPalette6Fg"
},
}
Expand to see type definition & advanced usage
-- [ Typst | Terms > Type definitions ] ---------------------------------------------------
---@class term.opts
---
---@field text string
---@field hl? string
M.term_opts = {
text = "π",
hl = "Comment"
};
-- [ Typst | Terms > Parameters ] ---------------------------------------------------------
---@class __typst.terms
---
---@field class "typst_term"
---
---@field label string
---
---@field text string[]
---@field range inline_link.range
M.__typst_terms = {
class = "typst_term",
label = "Term",
text = { "/ Term" },
range = {
row_start = 0,
row_end = 0,
col_start = 0,
col_end = 6,
label = { 0, 2, 0, 6 }
}
};
- Type:
typst.url_links
- Dynamic: true
Configuration for URLs.
Expand to see default configuration
--- Configuration for URL links.
---@class typst.url_links
---
---@field enable boolean
---
---@field default config.inline_generic Default configuration for URL links.
---@field [string] config.inline_generic Configuration for URL links whose label matches `string`.
url_links = {
enable = true,
__emoji_link_compatibility = true,
default = {
icon = " ",
hl = "MarkviewEmail"
},
};
Expand to see type definition & advanced usage
--- Configuration for URL links.
---@class typst.url_links
---
---@field enable boolean
---
---@field default config.inline_generic Default configuration for URL links.
---@field [string] config.inline_generic Configuration for URL links whose label matches `string`.
url_links = {
enable = true,
__emoji_link_compatibility = true,
default = {
icon = " ",
hl = "MarkviewEmail"
},
};
Also available in vimdoc, :h markview.nvim-typst
.