Skip to content

Commit 2256e47

Browse files
committed
add config option parse_marker and parse_priority
1 parent 6601fa5 commit 2256e47

13 files changed

+80
-43
lines changed

.ocamlformat

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
version=0.16.0
1+
version=0.26.2
22
break-separators=before
33
dock-collection-brackets=false
44
break-sequences=true

bench/bench.ml

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ open Core_bench
55
open Angstrom
66

77
let doc_org = load_file "./examples/doc.org"
8-
98
let syntax_md = load_file "./examples/syntax.md"
109

1110
let config =
@@ -22,6 +21,8 @@ let config =
2221
; export_md_remove_options = []
2322
; hiccup_in_block = true
2423
; enable_drawers = true
24+
; parse_marker = true
25+
; parse_priority = true
2526
}
2627

2728
let outline_config = { config with parse_outline_only = true }

bin/main.ml

+3-2
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ let generate backend output _opts filename =
4141
; export_md_remove_options = []
4242
; hiccup_in_block = true
4343
; enable_drawers = true
44+
; parse_marker = true
45+
; parse_priority = true
4446
}
4547
in
4648
let ast = parse config (String.concat "\n" lines) in
@@ -89,9 +91,7 @@ let options =
8991
& info [ "x"; "option" ] ~docv:"OPTIONS" ~doc)
9092

9193
let cmd = Term.(const generate $ backend $ output $ options $ filename)
92-
9394
let doc = "converts org-mode or markdown files into various formats"
94-
9595
let options = []
9696

9797
let man =
@@ -104,6 +104,7 @@ let man =
104104
@ options
105105

106106
let infos = Cmd.info "mldoc" ~version:"0" ~doc ~man
107+
107108
let main () =
108109
match Cmd.v infos cmd |> Cmd.eval_value with
109110
| Ok (`Ok expr) -> Lwt_main.run expr

lib/.ocamlinit

+5-1
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,8 @@ let config = { toc = true; parse_outline_only = false; heading_number = true
1818
export_md_indent_style = Conf.Dashes;
1919
export_md_remove_options = [];
2020
hiccup_in_block = true;
21-
inline_skip_macro = false};;
21+
inline_skip_macro = false;
22+
enable_drawers = true;
23+
parse_marker = true;
24+
parse_priority = true;
25+
};;

lib/export/conf.ml

+2
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ type t =
5454
; export_md_remove_options : meta_chars list [@default []]
5555
; hiccup_in_block : bool [@default true]
5656
; enable_drawers : bool [@default true]
57+
; parse_marker: bool [@default true]
58+
; parse_priority: bool [@default true]
5759
}
5860
[@@deriving yojson]
5961

lib/export/opml.ml

+2-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ open Prelude
22
open Conf
33

44
let default_state = Markdown.default_state
5-
65
let empty_references = Reference.empty_parsed_t
76

87
let default_config =
@@ -19,10 +18,11 @@ let default_config =
1918
; export_md_remove_options = []
2019
; hiccup_in_block = true
2120
; enable_drawers = true
21+
; parse_marker = true
22+
; parse_priority = true
2223
}
2324

2425
let attr ?(uri = "") local value : Xmlm.attribute = ((uri, local), value)
25-
2626
let tag name attrs : Xmlm.tag = (("", name), attrs)
2727

2828
(* only concat Leaf list, ignore Branch elem *)
@@ -102,7 +102,6 @@ let blocks refs tl title output_buf =
102102

103103
module OPMLExporter = struct
104104
let name = "opml"
105-
106105
let default_filename = change_ext "opml"
107106

108107
let export ~refs _config (doc : Document.t) output =

lib/syntax/heading0.ml

+13-3
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,11 @@ struct
4141
let markdown_heading =
4242
Markdown_level.parse >>| fun (indents, s) ->
4343
let len = String.length s in
44-
(Option.map_default (fun indents -> String.length indents + 1) 1 indents, false, Some len)
44+
( Option.map_default
45+
(fun indents -> String.length indents + 1)
46+
1 indents
47+
, false
48+
, Some len )
4549
in
4650
let unordered =
4751
lift2
@@ -204,8 +208,14 @@ struct
204208
; size
205209
})
206210
(level config <?> "Heading level")
207-
(optional (ws *> marker <?> "Heading marker"))
208-
(optional (ws *> priority <?> "Heading priority"))
211+
(if not config.parse_marker then
212+
return None
213+
else
214+
optional (ws *> marker <?> "Heading marker"))
215+
(if not config.parse_priority then
216+
return None
217+
else
218+
optional (ws *> priority <?> "Heading priority"))
209219
(optional (ws *> Angstrom.both pos (title config) <?> "Heading title"))
210220
in
211221
p <* optional (end_of_line <|> end_of_input)

lib/transform/markdown_transformer.ml

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ module String_Tree_Value : sig
55
type t = string Z.l
66

77
val of_value : Tree_type.value -> config:Conf.t -> t
8-
98
val to_value : t -> Tree_type.value_with_content
109
end = struct
1110
type t = string Z.l
@@ -24,6 +23,8 @@ end = struct
2423
; export_md_remove_options = []
2524
; hiccup_in_block = true
2625
; enable_drawers = true
26+
; parse_marker = true
27+
; parse_priority = true
2728
}
2829

2930
let rec of_value v ~config =

test/test_export_markdown.ml

+3-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ let default_config : Conf.t =
1212
; export_md_remove_options = []
1313
; hiccup_in_block = true
1414
; enable_drawers = true
15+
; parse_marker = true
16+
; parse_priority = true
1517
}
1618

1719
let refs : Reference.parsed_t =
@@ -70,7 +72,7 @@ let export_md =
7072
, testcases
7173
[ ( "merge paragraph"
7274
, `Quick
73-
(* append 2 spaces at end to add <br /> break tag when rendering*)
75+
(* append 2 spaces at end to add <br /> break tag when rendering*)
7476
, check_aux "- text1 ((ref1)) text2" "- text1 ref1-text text2 " )
7577
] )
7678
; ( "export md"

test/test_export_opml.ml

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ let default_config : Conf.t =
1212
; export_md_remove_options = []
1313
; hiccup_in_block = true
1414
; enable_drawers = true
15+
; parse_marker = true
16+
; parse_priority = true
1517
}
1618

1719
let check_aux ?(config = default_config) source expect =

test/test_markdown.ml

+28-25
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ let default_config : Conf.t =
1212
; export_md_remove_options = []
1313
; hiccup_in_block = true
1414
; enable_drawers = true
15+
; parse_marker = true
16+
; parse_priority = true
1517
}
1618

1719
let check_mldoc_type =
@@ -650,37 +652,38 @@ let inline =
650652
] )
651653
; ( "inline-entity"
652654
, testcases
653-
[
654-
( "space separator"
655-
, `Quick
656-
, check_aux "\\Delta G"
655+
[ ( "space separator"
656+
, `Quick
657+
, check_aux "\\Delta G"
657658
(paragraph
658659
[ I.Entity
659-
{ name = "Delta"
660-
; latex = "\\Delta"
661-
; latex_mathp = true
662-
; html = "&Delta;"
663-
; ascii = "Delta"
664-
; unicode = "Δ"}
665-
; I.Plain " G" ]))
666-
; ( "no separator"
667-
, `Quick
668-
, check_aux "\\DeltaG"
669-
(paragraph
670-
[ I.Plain "DeltaG" ]))
671-
; ( "{} separator"
660+
{ name = "Delta"
661+
; latex = "\\Delta"
662+
; latex_mathp = true
663+
; html = "&Delta;"
664+
; ascii = "Delta"
665+
; unicode = "Δ"
666+
}
667+
; I.Plain " G"
668+
]) )
669+
; ( "no separator"
670+
, `Quick
671+
, check_aux "\\DeltaG" (paragraph [ I.Plain "DeltaG" ]) )
672+
; ( "{} separator"
672673
, `Quick
673674
, check_aux "\\Delta{}G"
674675
(paragraph
675676
[ I.Entity
676-
{ name = "Delta"
677-
; latex = "\\Delta"
678-
; latex_mathp = true
679-
; html = "&Delta;"
680-
; ascii = "Delta"
681-
; unicode = "Δ"}
682-
; I.Plain "G" ]))
683-
])
677+
{ name = "Delta"
678+
; latex = "\\Delta"
679+
; latex_mathp = true
680+
; html = "&Delta;"
681+
; ascii = "Delta"
682+
; unicode = "Δ"
683+
}
684+
; I.Plain "G"
685+
]) )
686+
] )
684687
; ( "emphasis"
685688
, testcases
686689
[ ( "normal"

test/test_org.ml

+7-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ let default_config : Conf.t =
1212
; export_md_remove_options = []
1313
; hiccup_in_block = true
1414
; enable_drawers = true
15+
; parse_marker = true
16+
; parse_priority = true
1517
}
1618

1719
let check_mldoc_type =
@@ -210,7 +212,11 @@ let block =
210212
, check_aux
211213
":PROPERTIES:\n:XXX: 1\n:yyy: 2\n:END:\n#+ZZZ: 3\n#+UUU: 4"
212214
(Property_Drawer
213-
[ ("XXX", "1", []); ("yyy", "2", []); ("ZZZ", "3", []); ("UUU", "4", []) ]) )
215+
[ ("XXX", "1", [])
216+
; ("yyy", "2", [])
217+
; ("ZZZ", "3", [])
218+
; ("UUU", "4", [])
219+
]) )
214220
; ( "no drawer in quote"
215221
, `Quick
216222
, check_aux "#+BEGIN_QUOTE\na:: b\n#+END_QUOTE"

test/test_outline_markdown.ml

+10-4
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ let default_config : Conf.t =
1212
; export_md_remove_options = []
1313
; hiccup_in_block = true
1414
; enable_drawers = true
15+
; parse_marker = true
16+
; parse_priority = true
1517
}
1618

1719
let check_mldoc_type =
@@ -321,13 +323,15 @@ let inline =
321323
, check_aux
322324
":PROPERTIES:\n:type: programming_lang\n:creator: test\n:END:"
323325
(Property_Drawer
324-
[ ("type", "programming_lang", []); ("creator", "test", []) ]) )
326+
[ ("type", "programming_lang", []); ("creator", "test", []) ])
327+
)
325328
; ( "spaces-before-drawer"
326329
, `Quick
327330
, check_aux
328331
" :PROPERTIES:\n:type: programming_lang\n:creator: test\n:END:"
329332
(Property_Drawer
330-
[ ("type", "programming_lang", []); ("creator", "test", []) ]) )
333+
[ ("type", "programming_lang", []); ("creator", "test", []) ])
334+
)
331335
; ( "endwith-carriage-return"
332336
, `Quick
333337
, check_aux
@@ -336,7 +340,8 @@ let inline =
336340
:done: 1614485743195\r\n\
337341
:END:\n"
338342
(Property_Drawer
339-
[ ("now", "1614485729874", []); ("done", "1614485743195", []) ]) )
343+
[ ("now", "1614485729874", []); ("done", "1614485743195", []) ])
344+
)
340345
; ( "endwith-carriage-return-2"
341346
, `Quick
342347
, check_aux
@@ -345,7 +350,8 @@ let inline =
345350
:done: 1614485743195\r\n\
346351
:END:\r\n"
347352
(Property_Drawer
348-
[ ("now", "1614485729874", []); ("done", "1614485743195", []) ]) )
353+
[ ("now", "1614485729874", []); ("done", "1614485743195", []) ])
354+
)
349355
; ( "simplified-property-syntax"
350356
, `Quick
351357
, check_aux "a.b.c:: def\na-b-c::"

0 commit comments

Comments
 (0)