Skip to content

Commit 87e4832

Browse files
n-osborneshymMaelan
committed
Add syntax highlighting for *.mld
Co-authored-by: Samuel Hym <[email protected]> Co-authored-by: Maëlan <[email protected]>
1 parent 81be9d0 commit 87e4832

File tree

3 files changed

+103
-0
lines changed

3 files changed

+103
-0
lines changed

doc/ocaml.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@ highlighted. You can turn on highlighting of operators by defining:
99

1010
let g:ocaml_highlight_operators = 1
1111

12+
*g:odoc_html_support*
13+
14+
By default HTML code inlined in OCamldoc/Odoc syntax is not highlighted to
15+
avoid loading the HTML syntax. You can turn on HTML highlighting by defining:
16+
17+
let g:odoc_html_support = 1
18+
1219
*g:ocaml_compiler_compact_messages*
1320

1421
By default the output of the OCaml compiler is filtered to keep only the

ftdetect/odoc.vim

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
au BufNewFile,BufRead *.mld setf odoc

syntax/odoc.vim

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
" Vim syntax file
2+
" Language: Odoc/OCamldoc
3+
" Filenames: *.mld
4+
" Maintainers: Samuel Hym
5+
" Nicolas Osborne
6+
" URL: https://github.com/ocaml/vim-ocaml
7+
" Last Change:
8+
" 2024 Jan 26 - initial version
9+
10+
" Quit when a syntax file was already loaded
11+
if !exists("odoc_syntax_loading")
12+
if exists("b:current_syntax")
13+
finish
14+
endif
15+
let odoc_syntax_loading = 1
16+
endif
17+
18+
let s:keepcpo = &cpo
19+
set cpo&vim
20+
21+
syn spell toplevel
22+
23+
syn case match
24+
25+
syn include @odocSyntaxOCaml syntax/ocaml.vim
26+
unlet b:current_syntax
27+
28+
syn cluster odocInline contains=odocBold,odocItalic,odocEmphasis,odocMiscInline,odocList,odocLinkText,odocUrl,odocBraceError,odocCode,odocCrossref,odocCodeBlock,odocVerbatim,odocTargetSpecific,odocTag
29+
30+
syn match odocBraceError "[{}]"
31+
32+
syn region odocLinkText matchgroup=odocMarker start="{\%({[!:]\)\@=" end="}" contains=odocUrl,odocCrossref,@Spell,@odocInline
33+
syn region odocUrl matchgroup=odocUrlMarker start="{:\_s*" end="\_s*}"
34+
35+
syn region odocBold matchgroup=odocMarker start="{b\>" end="}" contains=@Spell,@odocInline
36+
syn region odocEmphasis matchgroup=odocMarker start="{e\>" end="}" contains=@Spell,@odocInline
37+
syn region odocItalic matchgroup=odocMarker start="{i\>" end="}" contains=@Spell,@odocInline
38+
syn region odocMiscInline matchgroup=odocMarker start="{[CLR^_]" end="}" contains=@Spell,@odocInline
39+
syn region odocVerbatim matchgroup=odocMarker start="{v\>" end="\<v}"
40+
41+
syn region odocTargetSpecific matchgroup=odocUnknownTarget start="{%.\{-}:\|{%" end="%}"
42+
43+
if get(g:,'odoc_html_support',0)
44+
syn include @odocHtml syntax/html.vim
45+
unlet b:current_syntax
46+
syn region odocTargetSpecific matchgroup=odocMarker start="{%html:" end="%}" contains=@odocHtml
47+
else
48+
syn region odocTargetSpecific matchgroup=odocMarker start="{%html:" end="%}" contains=@Spell
49+
endif
50+
51+
syn region odocDyckWord contained start="{" end="}" contains=odocDyckWord
52+
syn region odocTargetSpecific matchgroup=odocMarker start="{m\%(ath\)\?\>" end="}" contains=odocDyckWord
53+
syn region odocTargetSpecific matchgroup=odocMarker start="{%\%(latex\|texi\|man\):" end="%}" contains=@Spell
54+
syn region odocHeading start="{[0-5]\%(\s\|$\|:\)\@=" end="}" contains=@Spell,odocHeadingLabel
55+
syn match odocHeadingLabel contained "\%({[0-5]\)\@<=:[^ \t:]*"
56+
syn region odocTable matchgroup=odocMarker start="{t\>" end="}" contains=@Spell,@odocInline
57+
syn region odocTable matchgroup=odocMarker start="{table\>" end="}" contains=odocTableRow
58+
syn region odocTableRow matchgroup=odocMarker start="{tr\>" end="}" contains=odocTableEntry
59+
syn region odocTableEntry matchgroup=odocMarker start="{t[dh]\>" end="}" contains=@Spell,@odocInline
60+
syn region odocCode matchgroup=odocMarker start="\[" end="\]"
61+
syn region odocCodeBlock matchgroup=odocMarker start="{@[^\[]\+\[" end="\]}"
62+
syn region odocCodeBlock matchgroup=odocMarker start="{\%(@ocaml\%(\s[^\[]*\)\?\)\?\[" end="\]}" contains=@odocSyntaxOCaml
63+
syn match odocListMarker "^\s*[-+]\s"
64+
syn region odocListItem contained matchgroup=odocListMarker start="{\%(-\|li\>\)" end="}" contains=@Spell,@odocInline
65+
syn region odocList matchgroup=odocListMarker start="{[ou]l\>" end="}" contains=odocListItem
66+
" a bit leniant with ":"
67+
syn match odocCrossrefKw contained "\<\%(module\%(-type\)\?\|class\%(-type\)\?\|val\|type\|exception\|method\|constructor\|extension\|field\|instance-variable\|section\|page\)[-:]"
68+
syn region odocCrossref start="{!" end="}" contains=odocCrossrefKw
69+
syn match odocTag "@\%(author\|deprecated\|param\|raise\|return\|see\|since\|before\|version\)"
70+
71+
" Shamelessly borrowed from HTML syntax
72+
hi def odocBold term=bold cterm=bold gui=bold
73+
hi def odocEmphasis term=underline cterm=underline gui=underline
74+
hi def odocItalic term=italic cterm=italic gui=italic
75+
76+
hi def link odocCrossref Float
77+
hi def link odocCrossrefKw Keyword
78+
hi def link odocHeading Title
79+
hi def link odocHeadingLabel Label
80+
hi def link odocListMarker Operator
81+
hi def link odocMarker Delimiter
82+
hi def link odocTag Keyword
83+
hi def link odocBraceError Error
84+
hi def link odocUrlMarker odocMarker
85+
hi def link odocUrl Underlined
86+
hi def link odocUnknownTarget Error
87+
88+
let b:current_syntax = "odoc"
89+
90+
unlet odoc_syntax_loading
91+
92+
let &cpo = s:keepcpo
93+
unlet s:keepcpo
94+
95+
" vim: ts=8

0 commit comments

Comments
 (0)