Skip to content

Commit

Permalink
Fixes for markdown mode
Browse files Browse the repository at this point in the history
  • Loading branch information
jonludlam committed Dec 19, 2024
1 parent 9355761 commit 6ce4e9b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
16 changes: 10 additions & 6 deletions src/markdown/doc_of_md.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) =
Expand Down
15 changes: 11 additions & 4 deletions src/markdown/odoc_md.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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

Expand All @@ -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 =
Expand Down

0 comments on commit 6ce4e9b

Please sign in to comment.