2020% % %CopyrightEnd%
2121% %
2222-module (man_docs ).
23+ -moduledoc false .
24+
2325-include_lib (" kernel/include/eep48.hrl" ).
2426
25- -export ([module_to_manpage /2 , module_to_manpage /3 , markdown_to_manpage /2 ]).
27+ -export ([module_to_manpage /3 , module_to_manpage /4 , markdown_to_manpage /3 ]).
2628
2729% % Formats a module documentation as a roff man page.
2830% % Fetches the documentation for a module with `code:get_doc/1`
29- -spec module_to_manpage (Module , Path ) -> unicode :chardata () when
31+ -spec module_to_manpage (Module , Path , Section ) -> unicode :chardata () when
3032 Module :: module (),
31- Path :: string ().
32- module_to_manpage (Module , Path ) when is_atom (Module ) ->
33+ Path :: string (),
34+ Section :: string ().
35+ module_to_manpage (Module , Path , Section ) when is_atom (Module ) ->
3336 case code :get_doc (Module ) of
3437 {ok , Docs } ->
35- module_to_manpage (Module , Path , Docs );
38+ module_to_manpage (Module , Path , Docs , Section );
3639 _Error ->
3740 ~ " "
3841 end .
39- -spec module_to_manpage (Module , Path , Docs ) -> unicode :chardata () when
42+ -spec module_to_manpage (Module , Path , Docs , Section ) -> unicode :chardata () when
4043 Module :: module (),
4144 Path :: string (),
42- Docs :: # docs_v1 {}.
43- module_to_manpage (_Module , _Path , # docs_v1 {module_doc = None }) when None =:= none ; None =:= hidden ->
45+ Docs :: # docs_v1 {},
46+ Section :: string ().
47+ module_to_manpage (_Module , _Path , # docs_v1 {module_doc = None }, _Section ) when None =:= none ; None =:= hidden ->
4448 ~ " " ;
45- module_to_manpage (Module , Path , # docs_v1 {module_doc = #{~ " en" := ModuleDoc }, docs = AllDocs })
49+ module_to_manpage (Module , Path , # docs_v1 {module_doc = #{~ " en" := ModuleDoc }, docs = AllDocs }, Section )
4650 when is_atom (Module ) ->
47- PreludeNDescription = markdown_to_manpage (ModuleDoc , Path ),
51+ PreludeNDescription = if is_binary (ModuleDoc ) -> markdown_to_manpage (ModuleDoc , Path , Section );
52+ true -> markdown_to_manpage1 (ModuleDoc , Path , Section )
53+ end ,
4854
4955 Types = [Doc || {{type ,_ ,_ },_ ,_ ,_ ,_ }= Doc <- AllDocs ],
5056 TypesSection = format_section (" DATA TYPES" , Types , Module , AllDocs ),
@@ -56,10 +62,10 @@ module_to_manpage(Module, Path, #docs_v1{module_doc = #{~"en" := ModuleDoc}, doc
5662 iolist_to_binary ([PreludeNDescription , TypesSection , FunctionsSection , CallbacksSection ]).
5763
5864% % Formats markdown as a roff man page.
59- -spec markdown_to_manpage (binary () | shell_docs : chunk_elements (), file : filename ()) -> binary ().
60- markdown_to_manpage (Markdown , Path ) when is_binary ( Markdown ) ->
61- markdown_to_manpage (shell_docs_markdown :parse_md (Markdown ), Path );
62- markdown_to_manpage (MarkdownChunks , Path ) ->
65+ -spec markdown_to_manpage (binary (), file : filename (), string ()) -> binary ().
66+ markdown_to_manpage (Markdown , Path , Section ) ->
67+ markdown_to_manpage1 (shell_docs_markdown :parse_md (Markdown ), Path , Section ).
68+ markdown_to_manpage1 (MarkdownChunks , Path , Section ) ->
6369 Path1 = filename :absname (Path ),
6470 App = case filename :split (string :prefix (Path1 , os :getenv (" ERL_TOP" ))) of
6571 [" /" , " lib" , AppStr | _ ] ->
@@ -80,8 +86,8 @@ markdown_to_manpage(MarkdownChunks, Path) ->
8086 Extension = filename :extension (Path ),
8187 FileName = list_to_binary (filename :rootname (filename :basename (Path ), Extension )),
8288 Name = get_name (MarkdownChunks , FileName ),
83- Prelude = io_lib :format (" .TH ~s 3 \" ~s ~s \" \" Ericsson AB\" \" Erlang Module Definition\"\n " ,
84- [Name , atom_to_binary (App ), Version ]),
89+ Prelude = io_lib :format (" .TH ~s ~s \" ~s ~s \" \" Ericsson AB\" \" Erlang Module Definition\"\n " ,
90+ [Name , Section , atom_to_binary (App ), Version ]),
8591 I = conv (MarkdownChunks , Name ),
8692 iolist_to_binary ([Prelude |I ]).
8793
@@ -113,10 +119,11 @@ conv([{h1,_,[Head]}|T],_) ->
113119 Name = ~ " .SH NAME\n " ,
114120 Desc = ~ " .SH DESCRIPTION\n " ,
115121 [Name ,Head ,$\n ,Desc |format (T )];
116- conv ([H |T ], Head ) ->
122+ conv ([{ p , _ , _ } = ShortDesc0 |T ], Head ) ->
117123 Name = ~ " .SH NAME\n " ,
118124 Desc = ~ " .SH DESCRIPTION\n " ,
119- [Name ,Head ,~ " - " ,format_one (H ),$\n ,Desc |format (T )].
125+ [~ " .PP\n " |ShortDesc ] = format_one (ShortDesc0 ),
126+ [Name ,Head ,~B " \- " ,ShortDesc ,$\n ,Desc |format (T )].
120127
121128escape (Text ) when is_list (Text ) ->
122129 escape (iolist_to_binary (Text ));
@@ -183,16 +190,10 @@ format_p(Is0) ->
183190 Text = string :trim (Text0 , leading ),
184191 [~ " .PP\n " ,Text ,$\n ].
185192
186- format_p_item ({code ,_ ,Text }) ->
193+ format_p_item ({Fi ,_ ,Text }) when Fi =:= code ; Fi =:= i ; Fi =:= a ->
187194 [~B " \fI" ,format_p_item (Text ),~B " \fR" ];
188- format_p_item ({em ,_ ,Text }) ->
195+ format_p_item ({Fb ,_ ,Text }) when Fb =:= em ; Fb =:= strong ->
189196 [~B " \fB" ,format_p_item (Text ),~B " \fR" ];
190- format_p_item ({i ,_ ,Text }) ->
191- [~B " \fI" ,format_p_item (Text ),~B " \fR" ];
192- format_p_item ({a ,_ ,Text }) ->
193- [~B " \fI" ,format_p_item (Text ),~B " \fR" ];
194- format_p_item ({strong ,_ ,Text }) ->
195- [" \\ fB" , format_p_item (Text ), " \\ fR" ];
196197format_p_item ([H |T ]) ->
197198 [format_p_item (H )|format_p_item (T )];
198199format_p_item ([]) ->
0 commit comments