Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions autoload/typst/options.vim
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ function! typst#options#init() abort " {{{1
call s:declare_option('typst_conceal', 0)
call s:declare_option('typst_conceal_math', g:typst_conceal)
call s:declare_option('typst_conceal_emoji', g:typst_conceal)
call s:declare_option('typst_syntax_use_lsp', 0)
call s:declare_option('typst_auto_close_toc', 0)
call s:declare_option('typst_auto_open_quickfix', 1)
call s:declare_option('typst_embedded_languages', [])
Expand Down
25 changes: 25 additions & 0 deletions ftplugin/typst.vim
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,31 @@ if g:typst_conceal
setlocal conceallevel=2
endif

if g:typst_syntax_use_lsp && g:typst_conceal
lua << EOF
vim.api.nvim_create_autocmd('LspTokenUpdate', {
callback = function(args)
local token = args.data.token
if token.type == 'punct' then
local conceal = ''
local should_conceal = false
if token.modifiers.strong or token.modifiers.emph then
should_conceal = true
end
if should_conceal then
vim.api.nvim_buf_set_extmark(
args.buf, args.data.client_id, token.line, token.start_col, {
end_col = token.end_col,
conceal = '',
priority = vim.highlight.priorities.semantic_tokens + 1,
})
end
end
end
})
EOF
endif

setlocal commentstring=//\ %s
setlocal comments=s1:/*,mb:*,ex:*/,://

Expand Down
71 changes: 39 additions & 32 deletions syntax/typst.vim
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
" Vim syntax file
" Vim syntax file using LSP
" Language: Typst
" Maintainer: Kaj Munhoz Arfvidsson
" Upstream: https://github.com/kaarmu/typst.vim
" Upstream:
"

if exists("b:current_syntax") | finish | endif

Expand Down Expand Up @@ -313,38 +314,44 @@ syntax region typstMarkupTermMarker
\ contains=@typstMarkup

" Bold & Italic
syntax match typstMarkupBold
\ /\v(\w|\\)@1<!\*\S@=.{-}(\n.{-1,})*\S@1<=\\@1<!\*/
\ contains=typstMarkupBoldRegion
syntax match typstMarkupItalic
\ /\v(\w|\\)@1<!_\S@=.{-}(\n.{-1,})*\S@1<=\\@1<!_/
\ contains=typstMarkupItalicRegion
syntax match typstMarkupBoldItalic
\ contained
\ /\v(\w|\\)@1<![_\*]\S@=.{-}(\n.{-1,})*\S@1<=\\@1<!\2/
\ contains=typstMarkupBoldRegion,typstMarkupItalicRegion
if g:typst_conceal
syntax region typstMarkupBoldRegion
\ contained
\ transparent matchgroup=typstMarkupBold
\ start=/\(^\|[^0-9a-zA-Z]\)\@<=\*/ end=/\*\($\|[^0-9a-zA-Z]\)\@=/
\ concealends contains=typstMarkupBoldItalic,typstMarkupLabel,@Spell
syntax region typstMarkupItalicRegion
\ contained
\ transparent matchgroup=typstMarkupItalic
\ start=/\(^\|[^0-9a-zA-Z]\)\@<=_/ end=/_\($\|[^0-9a-zA-Z]\)\@=/
\ concealends contains=typstMarkupBoldItalic,typstMarkupLabel,@Spell
if g:typst_syntax_use_lsp
" See LSP's reference at https://github.com/nvarner/typst-lsp/blob/d76054776d50bade665b82d1f0308615f11d2580/editors/vscode/package.json#L168
highlight default link @lsp.mod.strong typstMarkupBold
highlight default link @lsp.mod.emph typstMarkupItalic
else
syntax region typstMarkupBoldRegion
\ contained
\ transparent matchgroup=typstMarkupBold
\ start=/\(^\|[^0-9a-zA-Z]\)\@<=\*/ end=/\*\($\|[^0-9a-zA-Z]\)\@=/
\ contains=typstMarkupBoldItalic,typstMarkupLabel,@Spell
syntax region typstMarkupItalicRegion
syntax match typstMarkupBold
\ /\v(\w|\\)@1<!\*\S@=.{-}(\n.{-1,})*\S@1<=\\@1<!\*/
\ contains=typstMarkupBoldRegion
syntax match typstMarkupItalic
\ /\v(\w|\\)@1<!_\S@=.{-}(\n.{-1,})*\S@1<=\\@1<!_/
\ contains=typstMarkupItalicRegion
syntax match typstMarkupBoldItalic
\ contained
\ transparent matchgroup=typstMarkupItalic
\ start=/\(^\|[^0-9a-zA-Z]\)\@<=_/ end=/_\($\|[^0-9a-zA-Z]\)\@=/
\ contains=typstMarkupBoldItalic,typstMarkupLabel,@Spell
\ /\v(\w|\\)@1<![_\*]\S@=.{-}(\n.{-1,})*\S@1<=\\@1<!\2/
\ contains=typstMarkupBoldRegion,typstMarkupItalicRegion
if g:typst_conceal
syntax region typstMarkupBoldRegion
\ contained
\ transparent matchgroup=typstMarkupBold
\ start=/\(^\|[^0-9a-zA-Z]\)\@<=\*/ end=/\*\($\|[^0-9a-zA-Z]\)\@=/
\ concealends contains=typstMarkupBoldItalic,typstMarkupLabel,@Spell
syntax region typstMarkupItalicRegion
\ contained
\ transparent matchgroup=typstMarkupItalic
\ start=/\(^\|[^0-9a-zA-Z]\)\@<=_/ end=/_\($\|[^0-9a-zA-Z]\)\@=/
\ concealends contains=typstMarkupBoldItalic,typstMarkupLabel,@Spell
else
syntax region typstMarkupBoldRegion
\ contained
\ transparent matchgroup=typstMarkupBold
\ start=/\(^\|[^0-9a-zA-Z]\)\@<=\*/ end=/\*\($\|[^0-9a-zA-Z]\)\@=/
\ contains=typstMarkupBoldItalic,typstMarkupLabel,@Spell
syntax region typstMarkupItalicRegion
\ contained
\ transparent matchgroup=typstMarkupItalic
\ start=/\(^\|[^0-9a-zA-Z]\)\@<=_/ end=/_\($\|[^0-9a-zA-Z]\)\@=/
\ contains=typstMarkupBoldItalic,typstMarkupLabel,@Spell
endif
endif

" Linebreak & Special Whitespace
Expand Down