···111111 in
112112 match (relative_target, anchor) with
113113 | [], "" -> "#"
114114+ (* TODO: This looks wrong ./ could technically be the current page *)
114115 | page, _ -> "./" ^ add_anchor @@ String.concat "/" page))
+12-16
src/markdown2/markdown_page.ml
···16161717module Url = Odoc_document.Url
18181919-let page_creator doc =
2020- fun (ppf : Format.formatter) ->
2121- let renderer = Cmarkit_commonmark.renderer () in
2222- Format.fprintf ppf "%s" (Cmarkit_renderer.doc_to_string renderer doc)
2323-2424-let make ~config ~url ~header:_ content children =
1919+let make ~config ~url ~header:_ doc children =
2520 let filename = Link.Path.as_filename ~config url in
2626- let content = page_creator content in
2121+ let content ppf =
2222+ let renderer = Cmarkit_commonmark.renderer () in
2323+ Format.fprintf ppf "%s" (Cmarkit_renderer.doc_to_string renderer doc)
2424+ in
2725 { Odoc_document.Renderer.filename; content; children; path = url }
28262929-let src_page_creator _name (block_list : Cmarkit.Block.t list) =
3030- fun (ppf : Format.formatter) ->
3131- let renderer = Cmarkit_commonmark.renderer () in
3232- let root_block = Cmarkit.Block.Blocks (block_list, Cmarkit.Meta.none) in
3333- let doc = Cmarkit.Doc.make root_block in
3434- Format.fprintf ppf "%s" (Cmarkit_renderer.doc_to_string renderer doc)
3535-3636-let make_src ~config ~url ~header:_ title content =
2727+let make_src ~config ~url ~header:_ _title block_list =
3728 let filename = Link.Path.as_filename ~config url in
3838- let content = src_page_creator title content in
2929+ let content (ppf : Format.formatter) =
3030+ let renderer = Cmarkit_commonmark.renderer () in
3131+ let root_block = Cmarkit.Block.Blocks (block_list, Cmarkit.Meta.none) in
3232+ let doc = Cmarkit.Doc.make root_block in
3333+ Format.fprintf ppf "%s" (Cmarkit_renderer.doc_to_string renderer doc)
3434+ in
3935 { Odoc_document.Renderer.filename; content; children = []; path = url }
-81
src/markdown2/markdown_source.ml
···11-open Odoc_utils
22-module HLink = Link
33-open Odoc_document.Types
44-open Tyxml
55-module Link = HLink
66-77-let html_of_doc ~config ~resolve docs =
88- let open Html in
99- let a :
1010- ( [< Html_types.a_attrib ],
1111- [< Html_types.span_content_fun ],
1212- [> Html_types.span ] )
1313- star =
1414- Unsafe.node "a"
1515- (* Makes it possible to use <a> inside span. Although this is not standard (see
1616- https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/Content_categories)
1717- it is validated by the {{:https://validator.w3.org/nu/#textarea}W3C}. *)
1818- in
1919- (* [a] tags should not contain in other [a] tags. If this happens, browsers
2020- start to be really weird. If PPX do bad things, such a situation could
2121- happen. We manually avoid this situation. *)
2222- let rec doc_to_html ~is_in_a doc =
2323- match doc with
2424- | Source_page.Plain_code s -> [ txt s ]
2525- | Tagged_code (info, docs) -> (
2626- let is_in_a = match info with Link _ -> true | _ -> is_in_a in
2727- let children = List.concat_map (doc_to_html ~is_in_a) docs in
2828- match info with
2929- | Syntax tok -> [ span ~a:[ a_class [ tok ] ] children ]
3030- (* Currently, we do not render links to documentation *)
3131- | Link { documentation = _; implementation = None } -> children
3232- | Link { documentation = _; implementation = Some anchor } ->
3333- let href = Link.href ~config ~resolve anchor in
3434- [ a ~a:[ a_href href ] children ]
3535- | Anchor lbl -> [ span ~a:[ a_id lbl ] children ])
3636- in
3737- let span_content = List.concat_map (doc_to_html ~is_in_a:false) docs in
3838- span ~a:[] span_content
3939-4040-let count_lines_in_string s =
4141- let n = ref 0 in
4242- String.iter (function '\n' -> incr n | _ -> ()) s;
4343- !n
4444-4545-(** Traverse the doc to count the number of lines. *)
4646-let rec count_lines_in_span = function
4747- | Source_page.Plain_code s -> count_lines_in_string s
4848- | Tagged_code (_, docs) -> count_lines docs
4949-5050-and count_lines l =
5151- let rec inner l acc =
5252- match l with
5353- | [] -> acc
5454- | hd :: tl -> inner tl (count_lines_in_span hd + acc)
5555- in
5656- inner l 0
5757-5858-let rec line_numbers acc n =
5959- let open Html in
6060- if n < 1 then acc
6161- else
6262- let l = string_of_int n in
6363- let anchor =
6464- a
6565- ~a:[ a_id ("L" ^ l); a_class [ "source_line" ]; a_href ("#L" ^ l) ]
6666- [ txt l ]
6767- in
6868- line_numbers (anchor :: txt "\n" :: acc) (n - 1)
6969-7070-let html_of_doc ~config ~resolve docs =
7171- let open Html in
7272- pre
7373- ~a:[ a_class [ "source_container" ] ]
7474- [
7575- code
7676- ~a:[ a_class [ "source_line_column" ] ]
7777- (line_numbers [] (count_lines docs));
7878- code
7979- ~a:[ a_class [ "source_code" ] ]
8080- [ html_of_doc ~config ~resolve docs ];
8181- ]
···11-(* Type definitions for the Markdown renderer *)
22-33-type uri = Absolute of string | Relative of Odoc_document.Url.Path.t option
44-55-type file_uri = Absolute of string | Relative of Odoc_document.Url.Path.t
+3-3
test/integration/markdown.t/array.mli
···11-(** {0 List}
11+(** {0 Array}
2233- Utilities for List data type.
33+ Utilities for Array data type.
4455 This module is compatible with original ocaml stdlib. In general, all
66 functions comes with the original stdlib also applies to this collection,
···25252626val head : 'a t -> 'a option
2727(** [head xs] returns [None] if [xs] is the empty list, otherwise it returns
2828- [Some value] where [value] is the first element in the list.
2828+ [Some value] where [val ue] is the first element in the list.
2929 {[
3030 head [] = None;;
3131 head [ 1; 2; 3 ] = Some 1
+2-4
test/integration/markdown.t/page.mld
···22222323{3 References}
24242525-See [Odoc_odoc.Compile.compile].
2626-2727-See [Odoc_odoc.Compile.compile].
2525+See an empty reference {{!test.v}}.
28262929-See {{!/test.v}this function from another library}.
2727+See {{!test.v}this function from another library}.
30283129See {{!./test.mli}this page from another package}.
3230
+81-5
test/integration/markdown.t/run.t
···22 $ ocamlc -c -bin-annot test2.mli
33 $ ocamlc -c -bin-annot list.mli
44 $ odoc compile --package test -I . page.mld
55- File "page.mld", line 123, characters 0-11:
55+ File "page.mld", line 25, characters 23-34:
66+ Warning: '{{!...} ...}' (cross-reference) should not be empty.
77+ File "page.mld", line 121, characters 0-11:
68 Warning: Tags are not allowed in pages.
79 $ odoc compile --package test test.cmti
810 $ odoc compile --package test -I . test2.cmti
···1517 File "list.mli", line 37, characters 12-19:
1618 Warning: Reference to 'head' is ambiguous. Please specify its kind: section-head, val-head.
1719 $ odoc link page-page.odoc
1818- File "page.mld", line 83, characters 0-33:
2020+ File "page.mld", line 81, characters 0-33:
1921 Warning: Failed to resolve reference ./odoc_logo_placeholder.jpg Path 'odoc_logo_placeholder.jpg' not found
2020- File "page.mld", line 31, characters 4-49:
2222+ File "page.mld", line 29, characters 4-49:
2123 Warning: Failed to resolve reference ./test.mli Path 'test' not found
2222- File "page.mld", line 29, characters 4-50:
2323- Warning: Failed to resolve reference /test.v Path '/test' not found
2424 $ odoc markdown-generate test.odocl -o markdown
2525 $ odoc markdown-generate test2.odocl -o markdown
2626 $ odoc markdown-generate page-page.odocl -o markdown
···4040 ```
4141 module List : sig ... end
4242 ```
4343+4444+ $ cat markdown/test/page.md
4545+ ## Title
4646+ ### Subtitle
4747+ #### Referenceable title
4848+ See [Referenceable title](./#my_id).
4949+ #### Styled
5050+ **bold** text, *italic* text, *emphasized* text
5151+ H2O and 1st
5252+ #### Link
5353+ Here is a link: [https://www.example.com](https://www.example.com).
5454+ You can also click [here](https://www.example.com).
5555+ #### References
5656+ See an empty reference [`Test.v`](./Test.md#val-v).
5757+ See [this function from another library](./Test.md#val-v).
5858+ See [this page from another package]().
5959+ See [this section](./#styled) for the syntax of references.
6060+ #### Lists
6161+ - First item
6262+ - Second item
6363+ 0. First ordered item
6464+ 1. Second numbered item
6565+ - First item
6666+ - Second item
6767+ - can also be used
6868+ 0. First numbered item
6969+ 1. Second numbered item
7070+ 2. can also be used
7171+ #### Code blocks
7272+ Inline `code`.
7373+ ```ocaml
7474+ let _ = "Block code"
7575+ ```
7676+ ```text
7777+ Code block with {[inner code block syntax]}
7878+ ```
7979+ ```python
8080+ [i+1 for i in xrange(2)]
8181+ ```
8282+ #### Verbatim
8383+ ```
8484+ verbatim text
8585+ ```
8686+ #### Math
8787+ For inline math: `\sqrt 2`.
8888+ For display math:
8989+ ```
9090+ \sqrt 2
9191+ ```
9292+ #### Images
9393+ ![./odoc\_logo\_placeholder.jpg]()
9494+ 
9595+ #### Table
9696+ ##### Explicit syntax
9797+ \| Header 1 \| Header 2 \|
9898+ \| --- \| --- \|
9999+ \| Cell 1 \| Cell 2 \|
100100+ \| Cell 3 \| Cell 4 \|
101101+ ##### Light syntax
102102+ \| Header 1 \| Header 2 \|
103103+ \| --- \| --- \|
104104+ \| Cell 1 \| Cell 2 \|
105105+ \| Cell 3 \| Cell 4 \|
106106+ #### HTML
107107+ This is a strong tag: <strong> Odoc language lack support for quotation! </strong>
108108+109109+110110+ <div>
111111+ <blockquote>
112112+ Odoc language lack support for quotation!
113113+ </blockquote>
114114+ </div>
115115+116116+ #### Tags
117117+ since 4\.08
118118+ Tags are explained in this section.