Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for braces-only mode in subscript #139

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions bench/bench.ml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ let config =
; export_md_remove_options = []
; hiccup_in_block = true
; enable_drawers = true
; skip_no_braces = false
}

let outline_config = { config with parse_outline_only = true }
Expand Down
1 change: 1 addition & 0 deletions bin/main.ml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ let generate backend output _opts filename =
; export_md_remove_options = []
; hiccup_in_block = true
; enable_drawers = true
; skip_no_braces = false
}
in
let ast = parse config (String.concat "\n" lines) in
Expand Down
1 change: 1 addition & 0 deletions lib/export/conf.ml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ type t =
; export_md_remove_options : meta_chars list [@default []]
; hiccup_in_block : bool [@default true]
; enable_drawers : bool [@default true]
; skip_no_braces : bool [@default false]
}
[@@deriving yojson]

Expand Down
1 change: 1 addition & 0 deletions lib/export/opml.ml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ let default_config =
; export_md_remove_options = []
; hiccup_in_block = true
; enable_drawers = true
; skip_no_braces = false
}

let attr ?(uri = "") local value : Xmlm.attribute = ((uri, local), value)
Expand Down
8 changes: 4 additions & 4 deletions lib/syntax/inline.ml
Original file line number Diff line number Diff line change
Expand Up @@ -503,11 +503,11 @@ let gen_script config s f =
many1 (choice [ emphasis config; plain config; whitespaces; entity ])
in
string (s ^ "{") *> take_while1 (fun c -> non_eol c && c <> '}')
<* char '}' <|> p1
<* char '}' <|> (if config.skip_no_braces then fail "plain" else p1)
>>| fun s ->
match parse_string ~consume:All p s with
| Ok result -> f @@ concat_plains_without_pos result
| Error _e -> f [ Plain s ]
match parse_string ~consume:All p s with
| Ok result -> f @@ concat_plains_without_pos result
| Error _e -> f [ Plain s ]

let subscript config = gen_script config "_" (fun x -> Subscript x)

Expand Down
1 change: 1 addition & 0 deletions lib/transform/markdown_transformer.ml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ end = struct
; export_md_remove_options = []
; hiccup_in_block = true
; enable_drawers = true
; skip_no_braces = false
}

let rec of_value v ~config =
Expand Down
1 change: 1 addition & 0 deletions test/test_export_markdown.ml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ let default_config : Conf.t =
; export_md_remove_options = []
; hiccup_in_block = true
; enable_drawers = true
; skip_no_braces = false
}

let refs : Reference.parsed_t =
Expand Down
1 change: 1 addition & 0 deletions test/test_export_opml.ml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ let default_config : Conf.t =
; export_md_remove_options = []
; hiccup_in_block = true
; enable_drawers = true
; skip_no_braces = false
}

let check_aux ?(config = default_config) source expect =
Expand Down
1 change: 1 addition & 0 deletions test/test_markdown.ml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ let default_config : Conf.t =
; export_md_remove_options = []
; hiccup_in_block = true
; enable_drawers = true
; skip_no_braces = false
}

let check_mldoc_type =
Expand Down
35 changes: 33 additions & 2 deletions test/test_org.ml
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,34 @@ let default_config : Conf.t =
; export_md_remove_options = []
; hiccup_in_block = true
; enable_drawers = true
; skip_no_braces = false
}

let check_mldoc_type =
Alcotest.check (Alcotest.testable Type.pp ( = )) "check mldoc type"

let check_aux source expect =
let result = Mldoc.Parser.parse default_config source |> List.hd |> fst in
let check_aux ?(config = default_config) source expect =
let result = Mldoc.Parser.parse config source |> List.hd |> fst in
fun _ -> check_mldoc_type expect result

let braces_config : Conf.t =
{ toc = true
; parse_outline_only = false
; heading_number = true
; keep_line_break = false
; format = Conf.Org
; heading_to_list = false
; exporting_keep_properties = false
; inline_type_with_pos = false
; inline_skip_macro = false
; export_md_indent_style = Conf.Dashes
; export_md_remove_options = []
; hiccup_in_block = true
; enable_drawers = true
; skip_no_braces = true
}


let testcases =
List.map (fun (case, level, f) -> Alcotest.test_case case level f)

Expand Down Expand Up @@ -60,6 +79,18 @@ let inline =
, `Quick
, check_aux "a_b_c"
(paragraph [ I.Plain "a"; I.Subscript [ I.Plain "b_c" ] ]) )
; ( "not emphasis (3)"
, `Quick
, check_aux "a_{bc}"
(paragraph [ I.Plain "a"; I.Subscript [ I.Plain "bc" ] ]) )
; ( "not emphasis (4) - force braces"
, `Quick
, check_aux ~config:braces_config "a_{bc}"
(paragraph [ I.Plain "a"; I.Subscript [ I.Plain "bc" ] ]) )
; ( "not emphasis (5) - force braces"
, `Quick
, check_aux ~config:braces_config "a_bc"
(paragraph [ I.Plain "a_bc" ]) )
; ( "contains underline"
, `Quick
, check_aux "_a _ a_"
Expand Down
1 change: 1 addition & 0 deletions test/test_outline_markdown.ml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ let default_config : Conf.t =
; export_md_remove_options = []
; hiccup_in_block = true
; enable_drawers = true
; skip_no_braces = false
}

let check_mldoc_type =
Expand Down