[OCaml] Mobile-friendly clone of cgit.
1
(** Shared document AST and renderer for prose formats.
2
3
Format-specific parsing is supplied by the {!format} type; the renderer, TOC
4
generation, and anchor management are format-independent.
5
6
Every text fragment is emitted through {!Ui}, ensuring safe escaping of
7
repository content. *)
8
9
(** {1 Document AST} *)
10
11
type inline =
12
| Text of string
13
| Code of string
14
| Verbatim of string
15
| Link of { href : string; text : string } (** Inline markup elements. *)
16
17
type block =
18
| Heading of int * string
19
| Paragraph of string
20
| Unordered_list of string list
21
| Ordered_list of string list
22
| Definition_list of (string * string) list
23
| Code_block of string option * string (** Block-level document elements. *)
24
25
type document = {
26
title : string option;
27
metadata : (string * string) list;
28
blocks : block list;
29
}
30
(** A parsed document with optional title, metadata, and body blocks. *)
31
32
(** {1 Format interface} *)
33
34
type format = {
35
name : string;
36
css_class : string;
37
parse : string -> document;
38
inline : string -> Ui.node list;
39
}
40
(** A documentation format provides parsing and inline markup rendering. *)
41
42
(** {1 Shared utilities} *)
43
44
val first_word : string -> string option
45
(** Extract the first whitespace-delimited word from a string. *)
46
47
val is_continuation : string -> bool
48
(** [true] when a line is indented and non-blank, indicating it continues the
49
previous list item. *)
50
51
val take_continuations : string list -> string list * string list
52
(** Split off leading continuation lines from the remaining input. *)
53
54
val take_until :
55
(string -> bool) -> string list -> string list -> string list * string list
56
(** [take_until close collected lines] collects lines until [close] returns
57
[true], returning the collected lines and the remainder after the closing
58
line. *)
59
60
(** {1 Shared list-item classifiers} *)
61
62
val unordered_item : string -> string option
63
(** Recognise an unordered list item ([-], [+], or indented [*]). *)
64
65
val ordered_item : string -> string option
66
(** Recognise an ordered list item ([1.], [2)], etc.). *)
67
68
val is_boundary_common : string -> bool
69
(** [true] when a line starts a new block (blank, or a list item). *)
70
71
(** {1 Rendering} *)
72
73
val render : format -> string -> Ui.node
74
(** Render document content using the given format. Handles parsing, TOC
75
generation, and block rendering. *)
76