Skip to content

Commit 1a0b6c7

Browse files
n-osborneshym
andcommitted
Add syntax highlighting for *.mld
Co-authored-by: Samuel Hym <[email protected]>
1 parent c11dfa3 commit 1a0b6c7

File tree

3 files changed

+90
-0
lines changed

3 files changed

+90
-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: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
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 case match
22+
23+
syn include @odocSyntaxOCaml syntax/ocaml.vim
24+
unlet b:current_syntax
25+
26+
syn cluster odocInline contains=odocBold,odocItalic,odocEmphasis,odocMiscInline,odocList,odocLink,odocCode,odocCrossref,odocCodeBlock,odocVerbatim,odocTargetSpecific,odocTag
27+
28+
syn region odocLink matchgroup=odocLinkMarker start="{" end="}" contains=odocCrossref
29+
syn region odocBold matchgroup=odocMarker start="{b\>" end="}" contains=@Spell,@odocInline
30+
syn region odocEmphasis matchgroup=odocMarker start="{e\>" end="}" contains=@Spell,@odocInline
31+
syn region odocItalic matchgroup=odocMarker start="{i\>" end="}" contains=@Spell,@odocInline
32+
syn region odocMiscInline matchgroup=odocMarker start="{[CLR^_]" end="}" contains=@Spell,@odocInline
33+
syn region odocVerbatim matchgroup=odocMarker start="{v\>" end="\<v}"
34+
35+
if get(g:,'odoc_html_support',0)
36+
syn include @odocHtml syntax/html.vim
37+
unlet b:current_syntax
38+
syn region odocTargetSpecific matchgroup=odocMarker start="{%html:" end="%}" contains=@odocHtml
39+
else
40+
syn region odocTargetSpecific matchgroup=odocMarker start="{%html:" end="%}" contains=@Spell
41+
endif
42+
43+
syn region odocDyckWord contained start="{" end="}" contains=odocDyckWord
44+
syn region odocTargetSpecific matchgroup=odocMarker start="{m\%(ath\)\?\>" end="}" contains=odocDyckWord
45+
syn region odocTargetSpecific matchgroup=odocMarker start="{%\%(latex\|texi\|man\):" end="%}" contains=@Spell
46+
syn region odocHeading start="{[0-5]" end="}" contains=@Spell
47+
syn region odocTable matchgroup=odocMarker start="{t\>" end="}" contains=@Spell,@odocInline
48+
syn region odocTable matchgroup=odocMarker start="{table\>" end="}" contains=odocTableRow
49+
syn region odocTableRow matchgroup=odocMarker start="{tr\>" end="}" contains=odocTableEntry
50+
syn region odocTableEntry matchgroup=odocMarker start="{t[dh]\>" end="}" contains=@Spell,@odocInline
51+
syn region odocCode matchgroup=odocMarker start="\[" end="\]"
52+
syn region odocCodeBlock matchgroup=odocMarker start="{@[^\[]\+\[" end="\]}"
53+
syn region odocCodeBlock matchgroup=odocMarker start="{\%(@ocaml\%(\s[^\[]*\)\?\)\?\[" end="\]}" contains=@odocSyntaxOCaml
54+
syn match odocListMarker "^\s*[-+]\s"
55+
syn region odocListItem contained matchgroup=odocListMarker start="{\%(-\|li\>\)" end="}" contains=@Spell,@odocInline
56+
syn region odocList matchgroup=odocListMarker start="{[ou]l\>" end="}" contains=odocListItem
57+
" a bit leniant with ":"
58+
syn match odocCrossrefKw contained "\<\%(module\%(-type\)\?\|class\%(-type\)\?\|val\|type\|exception\|method\|constructor\|extension\|field\|instance-variable\|section\|page\)[-:]"
59+
syn region odocCrossref start="{!" end="}" contains=odocCrossrefKw
60+
syn match odocTag "@\%(author\|deprecated\|param\|raise\|return\|see\|since\|before\|version\)"
61+
62+
" Shamelessly borrowed from HTML syntax
63+
hi def odocBold term=bold cterm=bold gui=bold
64+
hi def odocEmphasis term=bold,underline cterm=bold,underline gui=bold,underline
65+
hi def odocItalic term=italic cterm=italic gui=italic
66+
67+
hi def link odocCrossref Float
68+
hi def link odocCrossrefKw Keyword
69+
hi def link odocHeading Title
70+
hi def link odocLink Underlined
71+
hi def link odocListMarker Operator
72+
hi def link odocMarker Delimiter
73+
hi def link odocTag Keyword
74+
75+
let b:current_syntax = "odoc"
76+
77+
unlet odoc_syntax_loading
78+
79+
let &cpo = s:keepcpo
80+
unlet s:keepcpo
81+
82+
" vim: ts=8

0 commit comments

Comments
 (0)