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
(** Extensions to the Cmarkit AST *)

type asset =
  | Local of { mime_type : string option; content : string }
  | Remote of string

open Cmarkit

type Block.t +=
  | Div of Block.t attributed node
  | SlipScript of Block.Code_block.t attributed node

module Folder = struct
  let block_ext_default f acc = function
    | Div ((b, _), _) -> Folder.fold_block f acc b
    | SlipScript _ -> acc
    | _ -> assert false

  let make = Folder.make ~block_ext_default
end

module Mapper = struct
  let ( let* ) = Option.bind

  let block_ext_default m = function
    | Div ((b, attrs), meta) ->
        let* b = Mapper.map_block m b in
        Some (Div ((b, attrs), meta))
    | SlipScript _ as b -> Some b
    | _ -> assert false

  let make = Mapper.make ~block_ext_default
end