package kkmarkdown

  1. Overview
  2. Docs
A safe markdown engine

Install

Dune Dependency

Authors

Maintainers

Sources

1.1.0.tar.gz
md5=a20517d95590d03ff5b7670323b8b0dd
sha512=97b3faa09e23ab88c5b4dcabe88f29e5c675b6bb4b0c9230ec105a70b01b37b54274cc0ab4a5eed84a754a99e3664e116a7aba6c9697e3669229985f1bf749be

doc/src/kkmarkdown.lib/AllSpanRules.ml.html

Source file AllSpanRules.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
(** List of all span rules in descending order, except {!SpanRuleChars} *)
let all : (module SpanRule.S) list =
  [
    (module SpanRuleEscape);
    (module SpanRuleUnicode.Hex);
    (module SpanRuleUnicode.Dec);
    (module SpanRuleStack.EmStrong);
    (module SpanRuleStack.Strong);
    (module SpanRuleStack.Em);
    (module SpanRuleStack.Strike);
    (module SpanRuleStack.Code);
    (module SpanRuleA.Automatic);
    (module SpanRuleA.UnsafeNormal);
  ]

module Map = FirstChar.Map (struct
  module type Rule = SpanRule.S

  let first_char rule =
    let module Rule = (val rule : SpanRule.S) in
    Rule.first_char
end)

let first_char_map, any = Map.init all
let find c = Map.find c first_char_map

module SpanRuleChars = struct
  let is_safe = true
  let first_char = FirstChar.Any

  let construct _ ({ SpanRule.s; cur } as state) =
    let len = String.length s in

    let next_cur =
      let exception Done of int in
      try
        for i = cur + 1 to len - 1 do
          if Map.mem s.[i] first_char_map then raise (Done i)
        done;
        len
      with Done i -> i
    in
    let res = Typ.CharsSpan (String.sub s cur (next_cur - cur)) in
    state.cur <- next_cur;
    Some res
end

let any = any @ [ (module SpanRuleChars : SpanRule.S) ]
OCaml

Innovation. Community. Security.