package omd

  1. Overview
  2. Docs
A Markdown frontend in pure OCaml

Install

Dune Dependency

Authors

Maintainers

Sources

omd-2.0.0.alpha1.tbz
sha256=5800b920db48d68fa77d8270d64a45989eac398f76d733267827c9a0b2a90390
sha512=0c545a52a706a47fd9fe233f3daf7d4d4907ddd32b6faa9bb75df9086995f44ea341ed9b30d334c393d4f340c7f3bc27e99a0f8cb70943c7d4bd30128ed51fef

doc/src/omd/ast.ml.html

Source file ast.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
type attributes =
  (string * string) list

type list_type =
  | Ordered of int * char
  | Bullet of char

type list_spacing =
  | Loose
  | Tight

let same_block_list_kind k1 k2 =
  match k1, k2 with
  | Ordered (_, c1), Ordered (_, c2)
  | Bullet c1, Bullet c2 -> c1 = c2
  | _ -> false

type link_def =
  {
    label: string;
    destination: string;
    title: string option;
    attributes: attributes;
  }

module type T = sig
  type t
end

module MakeBlock (I : T) = struct
  type def_elt =
    {
      term: I.t;
      defs: I.t list;
    }

  and block =
    {
      bl_desc: block_desc;
      bl_attributes: attributes;
    }

  and block_desc =
    | Paragraph of I.t
    | List of list_type * list_spacing * block list list
    | Blockquote of block list
    | Thematic_break
    | Heading of int * I.t
    | Code_block of string * string
    | Html_block of string
    | Definition_list of def_elt list
end

type link =
  {
    label: inline;
    destination: string;
    title: string option;
  }

and inline =
  {
    il_desc: inline_desc;
    il_attributes: attributes;
  }

and inline_desc =
  | Concat of inline list
  | Text of string
  | Emph of inline
  | Strong of inline
  | Code of string
  | Hard_break
  | Soft_break
  | Link of link
  | Image of link
  | Html of string

module Raw = MakeBlock (String)

module Inline = struct type t = inline end

include MakeBlock (Inline)

module MakeMapper (Src : T) (Dst : T) = struct
  module SrcBlock = MakeBlock(Src)
  module DstBlock = MakeBlock(Dst)

  let rec map (f : Src.t -> Dst.t) : SrcBlock.block -> DstBlock.block =
    fun {bl_desc; bl_attributes} ->
    let bl_desc =
      match bl_desc with
      | SrcBlock.Paragraph x -> DstBlock.Paragraph (f x)
      | List (ty, sp, bl) ->
          List (ty, sp, List.map (List.map (map f)) bl)
      | Blockquote xs ->
          Blockquote (List.map (map f) xs)
      | Thematic_break ->
          Thematic_break
      | Heading (level, text) ->
          Heading (level, f text)
      | Definition_list l ->
          let f {SrcBlock.term; defs} = {DstBlock.term = f term; defs = List.map f defs} in
          Definition_list (List.map f l)
      | Code_block (label, code) ->
          Code_block (label, code)
      | Html_block x ->
          Html_block x
    in
    {bl_desc; bl_attributes}
end

module Mapper = MakeMapper (String) (Inline)
OCaml

Innovation. Community. Security.