From 6ce4e9b0656623a6671bdcc657eb4313b30a08ba Mon Sep 17 00:00:00 2001 From: Jon Ludlam Date: Sat, 14 Dec 2024 14:50:15 +0000 Subject: [PATCH] Fixes for markdown mode --- src/markdown/doc_of_md.ml | 16 ++++++++++------ src/markdown/odoc_md.ml | 15 +++++++++++---- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/src/markdown/doc_of_md.ml b/src/markdown/doc_of_md.ml index c06dce5257..d8badf96c5 100644 --- a/src/markdown/doc_of_md.ml +++ b/src/markdown/doc_of_md.ml @@ -64,11 +64,13 @@ let textloc_to_loc ~locator textloc = let point_of_line_and_byte_pos ~locator:(location, line_trim_counts) l pos = let line_num, line_pos = l in let line = location.Lexing.pos_lnum + line_num - 1 in - let column = line_trim_counts.(line_num - 1) + (pos - line_pos) in - let column = - match line_num with 1 -> comment_col ~location + column | _ -> column - in - { Loc.line; column } + try + let column = line_trim_counts.(line_num - 1) + (pos - line_pos) in + let column = + match line_num with 1 -> comment_col ~location + column | _ -> column + in + { Loc.line; column } + with _ -> { Loc.line = -1; column = -1 } in let file = Textloc.file textloc in let first_line = Textloc.first_line textloc in @@ -162,7 +164,9 @@ type nestable_ast_acc = let link_definition defs l = match Inline.Link.reference_definition defs l with | Some (Link_definition.Def (ld, _)) -> ld - | Some _ -> assert false (* if we parse without cmarkit extensions *) + | Some (Block.Footnote.Def (f, _)) -> + Link_definition.make ~label:(Block.Footnote.label f) () + | Some _ -> assert false | None -> assert false (* assert [l]'s referenced label is not synthetic *) let autolink_to_inline_element ~locator a m (is, warns) = diff --git a/src/markdown/odoc_md.ml b/src/markdown/odoc_md.ml index 177b8cac00..18b21cf3a7 100644 --- a/src/markdown/odoc_md.ml +++ b/src/markdown/odoc_md.ml @@ -40,10 +40,14 @@ let mk_page input_s id elements = frontmatter; } -let run input_s parent_id_str odoc_dir = +let run input_s parent_id_opt odoc_dir = (* Construct the id of this page *) let page_name = Filename.basename input_s |> Filename.chop_extension in - let parent_id = Odoc_odoc.Compile.mk_id parent_id_str in + let parent_id = + match parent_id_opt with + | Some parent_id_str -> Odoc_odoc.Compile.mk_id parent_id_str + | None -> None + in let id = Odoc_model.Paths.Identifier.Mk.leaf_page (parent_id, Odoc_model.Names.PageName.make_std page_name) @@ -53,7 +57,10 @@ let run input_s parent_id_str odoc_dir = let page = mk_page input_s id content in let output = - Fpath.(v odoc_dir // v parent_id_str / ("page-" ^ page_name ^ ".odoc")) + match parent_id_opt with + | None -> Fpath.(v odoc_dir / ("page-" ^ page_name ^ ".odoc")) + | Some parent_id_str -> + Fpath.(v odoc_dir // v parent_id_str / ("page-" ^ page_name ^ ".odoc")) in Odoc_odoc.Odoc_file.save_page output ~warnings page @@ -69,7 +76,7 @@ let parent_id = well as the location of the eventual html or other file." in Arg.( - required & opt (some string) None & info ~docv:"PARENT" ~doc [ "parent-id" ]) + value & opt (some string) None & info ~docv:"PARENT" ~doc [ "parent-id" ]) let output_dir = let doc =