PR#7363: add a texinfo title option to ocamldoc
parent
e30e82a219
commit
e5715c7bf5
|
@ -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 ^
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -242,34 +242,28 @@ end
|
|||
|
||||
(** {1 Generation of Texinfo code} *)
|
||||
|
||||
(** {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 ") ;
|
||||
]
|
||||
|
||||
let title = fst
|
||||
let heading = snd
|
||||
|
||||
let fallback_title =
|
||||
"@unnumberedsubsubsec "
|
||||
|
||||
let fallback_heading =
|
||||
"@subsubheading "
|
||||
|
||||
(** This class generates Texinfo code from text structures *)
|
||||
class text =
|
||||
object(self)
|
||||
|
||||
|
||||
(** Associations between a title number and texinfo code. *)
|
||||
val titles = [
|
||||
0, "@chapter " ;
|
||||
1, "@chapter " ;
|
||||
2, "@section " ;
|
||||
3, "@subsection " ;
|
||||
4, "@subsubsection " ;
|
||||
]
|
||||
|
||||
val fallback_title =
|
||||
"@unnumberedsubsubsec "
|
||||
|
||||
val headings = [
|
||||
0, "@majorheading " ;
|
||||
1, "@majorheading " ;
|
||||
2, "@heading " ;
|
||||
3, "@subheading " ;
|
||||
4, "@subsubheading " ;
|
||||
]
|
||||
|
||||
val fallback_heading =
|
||||
"@subsubheading "
|
||||
|
||||
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"
|
||||
|
|
Loading…
Reference in New Issue