Skip to content

Commit

Permalink
add config option parse_marker and parse_priority
Browse files Browse the repository at this point in the history
  • Loading branch information
RCmerci committed Jul 31, 2024
1 parent 6601fa5 commit 2256e47
Show file tree
Hide file tree
Showing 13 changed files with 80 additions and 43 deletions.
2 changes: 1 addition & 1 deletion .ocamlformat
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version=0.16.0
version=0.26.2
break-separators=before
dock-collection-brackets=false
break-sequences=true
Expand Down
3 changes: 2 additions & 1 deletion bench/bench.ml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ open Core_bench
open Angstrom

let doc_org = load_file "./examples/doc.org"

let syntax_md = load_file "./examples/syntax.md"

let config =
Expand All @@ -22,6 +21,8 @@ let config =
; export_md_remove_options = []
; hiccup_in_block = true
; enable_drawers = true
; parse_marker = true
; parse_priority = true
}

let outline_config = { config with parse_outline_only = true }
Expand Down
5 changes: 3 additions & 2 deletions bin/main.ml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ let generate backend output _opts filename =
; export_md_remove_options = []
; hiccup_in_block = true
; enable_drawers = true
; parse_marker = true
; parse_priority = true
}
in
let ast = parse config (String.concat "\n" lines) in
Expand Down Expand Up @@ -89,9 +91,7 @@ let options =
& info [ "x"; "option" ] ~docv:"OPTIONS" ~doc)

let cmd = Term.(const generate $ backend $ output $ options $ filename)

let doc = "converts org-mode or markdown files into various formats"

let options = []

let man =
Expand All @@ -104,6 +104,7 @@ let man =
@ options

let infos = Cmd.info "mldoc" ~version:"0" ~doc ~man

let main () =
match Cmd.v infos cmd |> Cmd.eval_value with
| Ok (`Ok expr) -> Lwt_main.run expr
Expand Down
6 changes: 5 additions & 1 deletion lib/.ocamlinit
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,8 @@ let config = { toc = true; parse_outline_only = false; heading_number = true
export_md_indent_style = Conf.Dashes;
export_md_remove_options = [];
hiccup_in_block = true;
inline_skip_macro = false};;
inline_skip_macro = false;
enable_drawers = true;
parse_marker = true;
parse_priority = true;
};;
2 changes: 2 additions & 0 deletions lib/export/conf.ml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ type t =
; export_md_remove_options : meta_chars list [@default []]
; hiccup_in_block : bool [@default true]
; enable_drawers : bool [@default true]
; parse_marker: bool [@default true]
; parse_priority: bool [@default true]
}
[@@deriving yojson]

Expand Down
5 changes: 2 additions & 3 deletions lib/export/opml.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ open Prelude
open Conf

let default_state = Markdown.default_state

let empty_references = Reference.empty_parsed_t

let default_config =
Expand All @@ -19,10 +18,11 @@ let default_config =
; export_md_remove_options = []
; hiccup_in_block = true
; enable_drawers = true
; parse_marker = true
; parse_priority = true
}

let attr ?(uri = "") local value : Xmlm.attribute = ((uri, local), value)

let tag name attrs : Xmlm.tag = (("", name), attrs)

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

module OPMLExporter = struct
let name = "opml"

let default_filename = change_ext "opml"

let export ~refs _config (doc : Document.t) output =
Expand Down
16 changes: 13 additions & 3 deletions lib/syntax/heading0.ml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@ struct
let markdown_heading =
Markdown_level.parse >>| fun (indents, s) ->
let len = String.length s in
(Option.map_default (fun indents -> String.length indents + 1) 1 indents, false, Some len)
( Option.map_default
(fun indents -> String.length indents + 1)
1 indents
, false
, Some len )
in
let unordered =
lift2
Expand Down Expand Up @@ -204,8 +208,14 @@ struct
; size
})
(level config <?> "Heading level")
(optional (ws *> marker <?> "Heading marker"))
(optional (ws *> priority <?> "Heading priority"))
(if not config.parse_marker then
return None
else
optional (ws *> marker <?> "Heading marker"))
(if not config.parse_priority then
return None
else
optional (ws *> priority <?> "Heading priority"))
(optional (ws *> Angstrom.both pos (title config) <?> "Heading title"))
in
p <* optional (end_of_line <|> end_of_input)
Expand Down
3 changes: 2 additions & 1 deletion lib/transform/markdown_transformer.ml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ module String_Tree_Value : sig
type t = string Z.l

val of_value : Tree_type.value -> config:Conf.t -> t

val to_value : t -> Tree_type.value_with_content
end = struct
type t = string Z.l
Expand All @@ -24,6 +23,8 @@ end = struct
; export_md_remove_options = []
; hiccup_in_block = true
; enable_drawers = true
; parse_marker = true
; parse_priority = true
}

let rec of_value v ~config =
Expand Down
4 changes: 3 additions & 1 deletion test/test_export_markdown.ml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ let default_config : Conf.t =
; export_md_remove_options = []
; hiccup_in_block = true
; enable_drawers = true
; parse_marker = true
; parse_priority = true
}

let refs : Reference.parsed_t =
Expand Down Expand Up @@ -70,7 +72,7 @@ let export_md =
, testcases
[ ( "merge paragraph"
, `Quick
(* append 2 spaces at end to add <br /> break tag when rendering*)
(* append 2 spaces at end to add <br /> break tag when rendering*)
, check_aux "- text1 ((ref1)) text2" "- text1 ref1-text text2 " )
] )
; ( "export md"
Expand Down
2 changes: 2 additions & 0 deletions test/test_export_opml.ml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ let default_config : Conf.t =
; export_md_remove_options = []
; hiccup_in_block = true
; enable_drawers = true
; parse_marker = true
; parse_priority = true
}

let check_aux ?(config = default_config) source expect =
Expand Down
53 changes: 28 additions & 25 deletions test/test_markdown.ml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ let default_config : Conf.t =
; export_md_remove_options = []
; hiccup_in_block = true
; enable_drawers = true
; parse_marker = true
; parse_priority = true
}

let check_mldoc_type =
Expand Down Expand Up @@ -650,37 +652,38 @@ let inline =
] )
; ( "inline-entity"
, testcases
[
( "space separator"
, `Quick
, check_aux "\\Delta G"
[ ( "space separator"
, `Quick
, check_aux "\\Delta G"
(paragraph
[ I.Entity
{ name = "Delta"
; latex = "\\Delta"
; latex_mathp = true
; html = "&Delta;"
; ascii = "Delta"
; unicode = "Δ"}
; I.Plain " G" ]))
; ( "no separator"
, `Quick
, check_aux "\\DeltaG"
(paragraph
[ I.Plain "DeltaG" ]))
; ( "{} separator"
{ name = "Delta"
; latex = "\\Delta"
; latex_mathp = true
; html = "&Delta;"
; ascii = "Delta"
; unicode = "Δ"
}
; I.Plain " G"
]) )
; ( "no separator"
, `Quick
, check_aux "\\DeltaG" (paragraph [ I.Plain "DeltaG" ]) )
; ( "{} separator"
, `Quick
, check_aux "\\Delta{}G"
(paragraph
[ I.Entity
{ name = "Delta"
; latex = "\\Delta"
; latex_mathp = true
; html = "&Delta;"
; ascii = "Delta"
; unicode = "Δ"}
; I.Plain "G" ]))
])
{ name = "Delta"
; latex = "\\Delta"
; latex_mathp = true
; html = "&Delta;"
; ascii = "Delta"
; unicode = "Δ"
}
; I.Plain "G"
]) )
] )
; ( "emphasis"
, testcases
[ ( "normal"
Expand Down
8 changes: 7 additions & 1 deletion test/test_org.ml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ let default_config : Conf.t =
; export_md_remove_options = []
; hiccup_in_block = true
; enable_drawers = true
; parse_marker = true
; parse_priority = true
}

let check_mldoc_type =
Expand Down Expand Up @@ -210,7 +212,11 @@ let block =
, check_aux
":PROPERTIES:\n:XXX: 1\n:yyy: 2\n:END:\n#+ZZZ: 3\n#+UUU: 4"
(Property_Drawer
[ ("XXX", "1", []); ("yyy", "2", []); ("ZZZ", "3", []); ("UUU", "4", []) ]) )
[ ("XXX", "1", [])
; ("yyy", "2", [])
; ("ZZZ", "3", [])
; ("UUU", "4", [])
]) )
; ( "no drawer in quote"
, `Quick
, check_aux "#+BEGIN_QUOTE\na:: b\n#+END_QUOTE"
Expand Down
14 changes: 10 additions & 4 deletions test/test_outline_markdown.ml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ let default_config : Conf.t =
; export_md_remove_options = []
; hiccup_in_block = true
; enable_drawers = true
; parse_marker = true
; parse_priority = true
}

let check_mldoc_type =
Expand Down Expand Up @@ -321,13 +323,15 @@ let inline =
, check_aux
":PROPERTIES:\n:type: programming_lang\n:creator: test\n:END:"
(Property_Drawer
[ ("type", "programming_lang", []); ("creator", "test", []) ]) )
[ ("type", "programming_lang", []); ("creator", "test", []) ])
)
; ( "spaces-before-drawer"
, `Quick
, check_aux
" :PROPERTIES:\n:type: programming_lang\n:creator: test\n:END:"
(Property_Drawer
[ ("type", "programming_lang", []); ("creator", "test", []) ]) )
[ ("type", "programming_lang", []); ("creator", "test", []) ])
)
; ( "endwith-carriage-return"
, `Quick
, check_aux
Expand All @@ -336,7 +340,8 @@ let inline =
:done: 1614485743195\r\n\
:END:\n"
(Property_Drawer
[ ("now", "1614485729874", []); ("done", "1614485743195", []) ]) )
[ ("now", "1614485729874", []); ("done", "1614485743195", []) ])
)
; ( "endwith-carriage-return-2"
, `Quick
, check_aux
Expand All @@ -345,7 +350,8 @@ let inline =
:done: 1614485743195\r\n\
:END:\r\n"
(Property_Drawer
[ ("now", "1614485729874", []); ("done", "1614485743195", []) ]) )
[ ("now", "1614485729874", []); ("done", "1614485743195", []) ])
)
; ( "simplified-property-syntax"
, `Quick
, check_aux "a.b.c:: def\na-b-c::"
Expand Down

0 comments on commit 2256e47

Please sign in to comment.