Skip to content
Snippets Groups Projects
Commit eb862a5a authored by Virgile Prevosto's avatar Virgile Prevosto
Browse files

[mdr] prepare merge of the two Markdown libraries

parent 2ae3b763
No related branches found
No related tags found
No related merge requests found
...@@ -24,15 +24,11 @@ $(Report_markdown_DIR)/mdr_version.ml: $(Report_markdown_DIR)/Makefile ...@@ -24,15 +24,11 @@ $(Report_markdown_DIR)/mdr_version.ml: $(Report_markdown_DIR)/Makefile
$(Report_markdown_DIR)/Report_markdown.mli: \ $(Report_markdown_DIR)/Report_markdown.mli: \
$(Report_markdown_DIR)/mdr_params.mli \ $(Report_markdown_DIR)/mdr_params.mli \
$(Report_markdown_DIR)/markdown.mli \
$(Report_markdown_DIR)/md_gen.mli \ $(Report_markdown_DIR)/md_gen.mli \
$(Report_markdown_DIR)/Makefile $(Report_markdown_DIR)/Makefile
echo "module Mdr_params: sig" > $@ echo "module Mdr_params: sig" > $@
cat $(Report_markdown_DIR)/mdr_params.mli >> $@ cat $(Report_markdown_DIR)/mdr_params.mli >> $@
echo "end" >> $@ echo "end" >> $@
echo "module Markdown: sig" >> $@
cat $(Report_markdown_DIR)/markdown.mli >> $@
echo "end" >> $@
echo "module Md_gen: sig" >> $@ echo "module Md_gen: sig" >> $@
cat $(Report_markdown_DIR)/md_gen.mli >> $@ cat $(Report_markdown_DIR)/md_gen.mli >> $@
echo "end" >> $@ echo "end" >> $@
......
type align = Left | Center | Right type align = Left | Center | Right
type href =
| URL of string
| Page of string
| Name of string
| Section of string * string
type inline = type inline =
| Plain of string | Plain of string
| Emph of string | Emph of string
| Bold of string | Bold of string
| Inline_code of string | Inline_code of string
| Link of text * string (** [Link(text,url)] *) | Link of text * href (** [Link(text,url)] *)
| Image of string * string (** [Image(alt,location)] *) | Image of string * string (** [Image(alt,location)] *)
and text = inline list and text = inline list
...@@ -47,20 +53,50 @@ let plain s = [ Plain s] ...@@ -47,20 +53,50 @@ let plain s = [ Plain s]
let plain_format txt = Format.kasprintf plain txt let plain_format txt = Format.kasprintf plain txt
let plain_link s = Link ([Inline_code s],s) let plain_link h =
let s = match h with
| URL url -> url
| Page p -> p
| Section (_,s) -> s
| Name a -> a
in
Link ([Inline_code s], URL s)
let codelines lang pp code = let codelines lang pp code =
let s = Format.asprintf "@[%a@]" pp code in let s = Format.asprintf "@[%a@]" pp code in
let lines = String.split_on_char '\n' s in let lines = String.split_on_char '\n' s in
Code_block (lang, lines) Code_block (lang, lines)
let id m =
let buffer = Buffer.create (String.length m) in
let lowercase = Char.lowercase_ascii in
let dash = ref false in
let emit c =
if !dash then (Buffer.add_char buffer '-' ; dash := false) ;
Buffer.add_char buffer c in
String.iter
(function
| '0'..'9' as c -> emit c
| 'a'..'z' as c -> emit c
| 'A'..'Z' as c -> emit (lowercase c)
| '.' | '_' as c -> emit c
| ' ' | '\t' | '\n' | '-' -> dash := (Buffer.length buffer > 0)
| _ -> ()) m ;
Buffer.contents buffer
let pp_href fmt = function
| URL s | Page s -> Format.pp_print_string fmt s
| Section (p,s) -> Format.fprintf fmt "%s#%s" p (id s)
| Name a -> Format.fprintf fmt "#%s" (id a)
let rec pp_inline fmt = let rec pp_inline fmt =
function function
| Plain s -> Format.pp_print_string fmt s | Plain s -> Format.pp_print_string fmt s
| Emph s -> Format.fprintf fmt "_%s_" (String.trim s) | Emph s -> Format.fprintf fmt "_%s_" (String.trim s)
| Bold s -> Format.fprintf fmt "**%s**" (String.trim s) | Bold s -> Format.fprintf fmt "**%s**" (String.trim s)
| Inline_code s -> Format.fprintf fmt "`%s`" (String.trim s) | Inline_code s -> Format.fprintf fmt "`%s`" (String.trim s)
| Link (text,url) -> Format.fprintf fmt "@[<h>[%a](%s)@]@ " pp_text text url | Link (text,url) ->
Format.fprintf fmt "@[<h>[%a](%a)@]@ " pp_text text pp_href url
| Image (alt,url) -> Format.fprintf fmt "@[<h>![%s](%s)@]@ " alt url | Image (alt,url) -> Format.fprintf fmt "@[<h>![%s](%s)@]@ " alt url
and pp_text fmt l = and pp_text fmt l =
......
type align = Left | Center | Right type align = Left | Center | Right
type href =
| URL of string
| Page of string
| Name of string
| Section of string * string
type inline = type inline =
| Plain of string | Plain of string
| Emph of string | Emph of string
| Bold of string | Bold of string
| Inline_code of string | Inline_code of string
| Link of text * string (** [Link(text,url)] *) | Link of text * href
| Image of string * string (** [Image(alt,location)] *) | Image of string * string (** [Image(alt,location)] *)
and text = inline list and text = inline list
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment