@@ -2,20 +2,33 @@ open SharedTypes
2
2
3
3
let codeBlock code = Printf. sprintf " ```rescript\n %s\n ```" code
4
4
5
+ (* Light weight, hopefully-enough-for-the-purpose fn to encode URI components.
6
+ Built to handle the reserved characters listed in
7
+ https://en.wikipedia.org/wiki/Percent-encoding. Note that this function is not
8
+ general purpose, rather it's currently only for URL encoding the argument list
9
+ passed to command links in markdown. *)
5
10
let encodeURIComponent text =
6
11
let ln = String. length text in
7
12
let buf = Buffer. create ln in
8
13
let rec loop i =
9
14
if i < ln then (
10
15
(match text.[i] with
11
16
| '"' -> Buffer. add_string buf " %22"
17
+ | '\' ' -> Buffer. add_string buf " %22"
12
18
| ':' -> Buffer. add_string buf " %3A"
19
+ | ';' -> Buffer. add_string buf " %3B"
13
20
| '/' -> Buffer. add_string buf " %2F"
14
21
| '\\' -> Buffer. add_string buf " %5C"
15
22
| ',' -> Buffer. add_string buf " %2C"
16
23
| '&' -> Buffer. add_string buf " %26"
17
24
| '[' -> Buffer. add_string buf " %5B"
18
25
| ']' -> Buffer. add_string buf " %5D"
26
+ | '#' -> Buffer. add_string buf " %23"
27
+ | '$' -> Buffer. add_string buf " %24"
28
+ | '+' -> Buffer. add_string buf " %2B"
29
+ | '=' -> Buffer. add_string buf " %3D"
30
+ | '?' -> Buffer. add_string buf " %3F"
31
+ | '@' -> Buffer. add_string buf " %40"
19
32
| c -> Buffer. add_char buf c);
20
33
loop (i + 1 ))
21
34
in
0 commit comments