(* *)
#require "markdown";;
open Markdown.Markup
let test_inlines test_case =
Format.printf "%a@\n%!" pp_inlines test_case
let test_blocks test_case =
Format.printf "%a@\n%!" pp_blocks test_case
(** Add artificial indentation to the output to avoid messing with Mdx's format. *)
let test_blocks_indented test_case =
Format.printf " @[%a@]@\n%!" pp_blocks test_case
Combining:
# test_inlines
((++)
(text "text one")
(text "text two"));;
text one text two
- : unit = ()
# test_inlines
((text "abc" ++ text "def")
++ (text "xyz" ++ text "tuv"));;
abc def xyz tuv
- : unit = ()
# test_inlines
((++)
(bold (text "This should be marked as bold"))
(italic (text "This should be italic")));;
**This should be marked as bold** _This should be italic_
- : unit = ()
# test_inlines
(bold
(text "This is bold"
++ italic (text "and this is italic in bold")
++ text "."));;
**This is bold _and this is italic in bold_ .**
- : unit = ()
# test_inlines
(superscript (text "This superscript")
++ subscript (text "This is subscript"));;
<sup>This superscript</sup> <sub>This is subscript</sub>
- : unit = ()
# test_inlines
(anchor "value to id attribute");;
<a id="value to id attribute"></a>
- : unit = ()
Elements:
# test_inlines
(code_span "type t");;
`type t`
- : unit = ()
# test_inlines
(code_span "Some `t");;
``Some `t``
- : unit = ()
# test_inlines
(link ~href: "google.com" (text "Google"));;
[Google](google.com)
- : unit = ()
Combining:
# test_blocks
(blocks
(paragraph (text "abc"))
(paragraph (text "def")));;
abc
def
- : unit = ()
# test_blocks
(blocks
(blocks (paragraph (text "abc")) (paragraph (text "def")))
(blocks (paragraph (text "xyz")) (paragraph (text "tuv"))));;
abc
def
xyz
tuv
- : unit = ()
Headings:
# test_blocks_indented
(heading 1 (text "A simple heading"));;
# A simple heading
- : unit = ()
# test_blocks_indented
(heading 3 (text "A" ++ bold (text "complicated") ++ text "heading"));;
### A **complicated** heading
- : unit = ()
# test_blocks_indented
(heading 3
((join
(join nbsp nbsp)
(text "A heading with nbsps"))));;
### A heading with nbsps
- : unit = ()
Code blocks:
# (* Add some indentation to avoid interfering with Mdx syntax. *)
Format.printf "@[<2> %a@]@\n%!" pp_blocks
(code_block "some code block");;
some code block
- : unit = ()
Lists:
# test_blocks
(* list items with several blocks. *)
(unordered_list
[(blocks (paragraph (text "Monday"))
(paragraph (text "is the first day of the week.")));
(blocks (paragraph (text "Tuesday"))
(paragraph (text "is the second day of the week.")))]);;
- Monday
is the first day of the week.
- Tuesday
is the second day of the week.
- : unit = ()
# test_blocks
(ordered_list
[(blocks
(paragraph (text "One"))
(paragraph (text "First digit.")));
(blocks
(paragraph (text "Two"))
(paragraph (text "Second digit.")))]);;
1. One
First digit.
2. Two
Second digit.
- : unit = ()
# test_blocks
(* test for a nested list function. *)
(ordered_list
[(blocks
(paragraph (text "Outer item"))
(ordered_list [(paragraph (text "This is an inner item"))]))]);;
1. Outer item
1. This is an inner item
- : unit = ()
# test_blocks
(ordered_list
[(blocks
(paragraph (text "Outer ordered list item"))
(unordered_list
[(paragraph (text "This is an inner unordered list item"))]))]);;
1. Outer ordered list item
- This is an inner unordered list item
- : unit = ()
# test_blocks
(raw_markup "<span> ... </span>");;
<span> ... </span>
- : unit = ()