diff options
| author | octachron <octa@polychoron.fr> | 2016-10-01 19:51:09 +0200 |
|---|---|---|
| committer | octachron <octa@polychoron.fr> | 2017-10-04 13:05:05 +0200 |
| commit | e5715c7bf58246b09ef7a29b75fd9a0f0f7ed76f (patch) | |
| tree | d7b0212c4eea51b66321d88ad0cb1150f39488ea | |
| parent | e30e82a2198d8649d773fbe346e4ba358f7cfef4 (diff) | |
| download | ocaml-e5715c7bf58246b09ef7a29b75fd9a0f0f7ed76f.tar.gz | |
PR#7363: add a texinfo title option to ocamldoc
| -rw-r--r-- | ocamldoc/odoc_args.ml | 29 | ||||
| -rw-r--r-- | ocamldoc/odoc_messages.ml | 8 | ||||
| -rw-r--r-- | ocamldoc/odoc_texi.ml | 44 |
3 files changed, 46 insertions, 35 deletions
diff --git a/ocamldoc/odoc_args.ml b/ocamldoc/odoc_args.ml index 4d825b6e07..ed14b4f9c5 100644 --- a/ocamldoc/odoc_args.ml +++ b/ocamldoc/odoc_args.ml @@ -144,16 +144,22 @@ let analyse_merge_options s = let f_latex_title s = - try - let pos = String.index s ',' in - let n = int_of_string (String.sub s 0 pos) in - let len = String.length s in - let command = String.sub s (pos + 1) (len - pos - 1) in - Odoc_latex.latex_titles := List.remove_assoc n !Odoc_latex.latex_titles ; - Odoc_latex.latex_titles := (n, command) :: !Odoc_latex.latex_titles - with - Not_found - | Invalid_argument _ -> + match String.split_on_char ',' s with + | [n;command] -> + let n = int_of_string n in + Odoc_latex.latex_titles := List.remove_assoc n !Odoc_latex.latex_titles ; + Odoc_latex.latex_titles := (n, command) :: !Odoc_latex.latex_titles + | _ -> + incr Odoc_global.errors ; + prerr_endline (M.wrong_format s) + +let f_texinfo_title s = + match String.split_on_char ',' s with + | [n;title;heading] -> + let n = int_of_string n in + Odoc_texi.titles_and_headings := + (n, (title,heading) ) :: List.remove_assoc n !Odoc_texi.titles_and_headings; + | _ -> incr Odoc_global.errors ; prerr_endline (M.wrong_format s) @@ -352,6 +358,9 @@ let default_options = Options.list @ (* texi only options *) "-noindex", Arg.Clear Odoc_global.with_index, M.no_index ; "-esc8", Arg.Set Odoc_texi.esc_8bits, M.esc_8bits ; + "-texinfotitle", Arg.String f_texinfo_title, + M.texinfo_title Odoc_texi.titles_and_headings ; + "-info-section", Arg.String ((:=) Odoc_texi.info_section), M.info_section ; "-info-entry", Arg.String (fun s -> Odoc_texi.info_entry := !Odoc_texi.info_entry @ [ s ]), M.info_entry ^ diff --git a/ocamldoc/odoc_messages.ml b/ocamldoc/odoc_messages.ml index c46198861d..6e14f11634 100644 --- a/ocamldoc/odoc_messages.ml +++ b/ocamldoc/odoc_messages.ml @@ -203,6 +203,14 @@ let merge_all = ('A', "merge all") let no_index = " Do not build index for Info files "^texi_only let esc_8bits = " Escape accentuated characters in Info files "^texi_only +let texinfo_title r= + "n,style Associate {n } to the given sectionning style\n"^ + "\t\t(e.g. 'section') in the texInfo output "^texi_only^"\n"^ + "\t\tDefault sectionning is:\n\t\t"^ + (String.concat "\n\t\t" + (List.map (fun (n,(t,h)) -> + Printf.sprintf " %d -> %s, %s " n t h) !r)) + let info_section = " Specify section of Info directory "^texi_only let info_entry = " Specify Info directory entry "^texi_only diff --git a/ocamldoc/odoc_texi.ml b/ocamldoc/odoc_texi.ml index f722fc595a..22f2000b80 100644 --- a/ocamldoc/odoc_texi.ml +++ b/ocamldoc/odoc_texi.ml @@ -242,33 +242,27 @@ end (** {1 Generation of Texinfo code} *) -(** This class generates Texinfo code from text structures *) -class text = - object(self) - +(** {2 Associations between a title number and texinfo code.} *) +let titles_and_headings = ref [ + 0, ("@chapter ", "@majorheading ") ; + 1, ("@chapter ", "@majorheading ") ; + 2, ("@section ", "@heading ") ; + 3, ("@subsection ", "@subheading ") ; + 4, ("@subsubsection ", "@subsubheading ") ; + ] - (** Associations between a title number and texinfo code. *) - val titles = [ - 0, "@chapter " ; - 1, "@chapter " ; - 2, "@section " ; - 3, "@subsection " ; - 4, "@subsubsection " ; - ] +let title = fst +let heading = snd - val fallback_title = - "@unnumberedsubsubsec " +let fallback_title = + "@unnumberedsubsubsec " - val headings = [ - 0, "@majorheading " ; - 1, "@majorheading " ; - 2, "@heading " ; - 3, "@subheading " ; - 4, "@subsubheading " ; - ] +let fallback_heading = + "@subsubheading " - val fallback_heading = - "@subsubheading " +(** This class generates Texinfo code from text structures *) +class text = + object(self) method escape = Texi.escape @@ -353,7 +347,7 @@ class text = [ "@format" ; self#texi_of_text t ; "@end format" ; "" ] method texi_of_Title n t = let t_begin = - try List.assoc n titles + try title @@ List.assoc n !titles_and_headings with Not_found -> fallback_title in t_begin ^ (self#texi_of_text t) ^ "\n" method texi_of_Link s t = @@ -380,7 +374,7 @@ class text = method heading n t = let f = - try List.assoc n headings + try heading @@ List.assoc n !titles_and_headings with Not_found -> fallback_heading in f ^ (self#texi_of_text t) ^ "\n" |
