20
20
% % %CopyrightEnd%
21
21
% %
22
22
-module (man_docs ).
23
+ -moduledocs false .
24
+
23
25
-include_lib (" kernel/include/eep48.hrl" ).
24
26
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 ]).
26
28
27
29
% % Formats a module documentation as a roff man page.
28
30
% % 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
30
32
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 ) ->
33
36
case code :get_doc (Module ) of
34
37
{ok , Docs } ->
35
- module_to_manpage (Module , Path , Docs );
38
+ module_to_manpage (Module , Path , Docs , Section );
36
39
_Error ->
37
40
~ " "
38
41
end .
39
- -spec module_to_manpage (Module , Path , Docs ) -> unicode :chardata () when
42
+ -spec module_to_manpage (Module , Path , Docs , Section ) -> unicode :chardata () when
40
43
Module :: module (),
41
44
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 ->
44
48
~ " " ;
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 )
46
50
when is_atom (Module ) ->
47
- PreludeNDescription = markdown_to_manpage (ModuleDoc , Path ),
51
+ PreludeNDescription = markdown_to_manpage (ModuleDoc , Path , Section ),
48
52
49
53
Types = [Doc || {{type ,_ ,_ },_ ,_ ,_ ,_ }= Doc <- AllDocs ],
50
54
TypesSection = format_section (" DATA TYPES" , Types , Module , AllDocs ),
@@ -56,10 +60,10 @@ module_to_manpage(Module, Path, #docs_v1{module_doc = #{~"en" := ModuleDoc}, doc
56
60
iolist_to_binary ([PreludeNDescription , TypesSection , FunctionsSection , CallbacksSection ]).
57
61
58
62
% % 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 ) ->
63
+ -spec markdown_to_manpage (binary () | shell_docs :chunk_elements (), file :filename (), string () ) -> binary ().
64
+ markdown_to_manpage (Markdown , Path , Section ) when is_binary (Markdown ) ->
65
+ markdown_to_manpage (shell_docs_markdown :parse_md (Markdown ), Path , Section );
66
+ markdown_to_manpage (MarkdownChunks , Path , Section ) ->
63
67
Path1 = filename :absname (Path ),
64
68
App = case filename :split (string :prefix (Path1 , os :getenv (" ERL_TOP" ))) of
65
69
[" /" , " lib" , AppStr | _ ] ->
@@ -80,8 +84,8 @@ markdown_to_manpage(MarkdownChunks, Path) ->
80
84
Extension = filename :extension (Path ),
81
85
FileName = list_to_binary (filename :rootname (filename :basename (Path ), Extension )),
82
86
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 ]),
87
+ Prelude = io_lib :format (" .TH ~s ~s \" ~s ~s \" \" Ericsson AB\" \" Erlang Module Definition\"\n " ,
88
+ [Name , Section , atom_to_binary (App ), Version ]),
85
89
I = conv (MarkdownChunks , Name ),
86
90
iolist_to_binary ([Prelude |I ]).
87
91
@@ -113,10 +117,11 @@ conv([{h1,_,[Head]}|T],_) ->
113
117
Name = ~ " .SH NAME\n " ,
114
118
Desc = ~ " .SH DESCRIPTION\n " ,
115
119
[Name ,Head ,$\n ,Desc |format (T )];
116
- conv ([H |T ], Head ) ->
120
+ conv ([{ p , _ , _ } = ShortDesc0 |T ], Head ) ->
117
121
Name = ~ " .SH NAME\n " ,
118
122
Desc = ~ " .SH DESCRIPTION\n " ,
119
- [Name ,Head ,~ " - " ,format_one (H ),$\n ,Desc |format (T )].
123
+ [~ " .PP\n " |ShortDesc ] = format_one (ShortDesc0 ),
124
+ [Name ,Head ,~B " \- " ,ShortDesc ,$\n ,Desc |format (T )].
120
125
121
126
escape (Text ) when is_list (Text ) ->
122
127
escape (iolist_to_binary (Text ));
0 commit comments