typst.kak (1880B)
1 # Detection 2 # ‾‾‾‾‾‾‾‾‾ 3 4 hook global BufCreate .*[.](typ) %{ 5 set-option buffer filetype typst 6 } 7 8 # Initialization 9 # ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ 10 11 hook -group typst-highlight global WinSetOption filetype=typst %{ 12 require-module typst 13 14 add-highlighter window/typst ref typst 15 hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/typst } 16 hook window InsertChar \n -group typst typst-on-new-line 17 } 18 19 provide-module typst %§ 20 21 # Highlighters 22 # ‾‾‾‾‾‾‾‾‾‾‾‾ 23 24 add-highlighter shared/typst group 25 26 # Comments 27 add-highlighter shared/typst/ regex ^\s+//(?:[^\n/]\N*|)$ 0:comment 28 add-highlighter shared/typst/ regex /\*[^\*]*\*/ 0:comment 29 30 # Strings 31 add-highlighter shared/typst/ regex '"[^"]*"' 0:string 32 33 # Headings 34 add-highlighter shared/typst/ regex ^=+\h+\N+$ 0:header 35 36 # Code blocks 37 # Raw with optional syntax highlighting 38 add-highlighter shared/typst/ regex '^```[^(```)]*```' 0:mono 39 # Multiline monospace 40 add-highlighter shared/typst/ regex '^`[^(`)]*`' 0:mono 41 42 # Monospace text 43 add-highlighter shared/typst/ regex \B(`\N+?`)\B 0:mono 44 add-highlighter shared/typst/ regex \B(```\N+?```)\B 0:mono 45 46 # Bold text 47 add-highlighter shared/typst/ regex (?!/)\*(?!/)(?!\n)[^\*]+(?!/)\*(?!/) 0:+b 48 49 # Italic text 50 add-highlighter shared/typst/ regex \b_.*?_\b 0:+i 51 52 # Code expressions: functions, variables 53 add-highlighter shared/typst/ regex (^|\h)#(\w|\.|-)+ 0:meta 54 55 # Bold terms in term lists 56 add-highlighter shared/typst/ regex ^/\h[^:]*: 0:+b 57 58 § 59 60 # Commands 61 # ‾‾‾‾‾‾‾‾ 62 63 define-command -hidden typst-on-new-line %< 64 evaluate-commands -draft -itersel %< 65 # Preserve previous line indent 66 try %{ execute-keys -draft <semicolon> K <a-&> } 67 # Cleanup trailing whitespaces from previous line 68 try %{ execute-keys -draft k x s \h+$ <ret> d } 69 > 70 >