1 # This file is part of NIT ( http://www.nitlanguage.org ).
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
15 # Manpages rendering of Markdown documents
16 module markdown_man_rendering
18 import markdown_rendering
19 import markdown_github
20 import markdown_wikilinks
22 # Markdown document renderer to Manpage
26 # Output under construction
27 private var man
: Buffer is noinit
29 # Render `node` as Markdown
30 redef fun render
(node
) do
33 return man
.write_to_string
36 redef fun visit
(node
) do node
.render_man
(self)
38 # Add `string` to `man`
39 fun add
(string
: String) do
40 man
.append
(string
.replace
("-", "\\-"))
43 # Add code that need to be escaped
44 fun add_code
(code
: String) do
45 add code
.replace
(" ", "\\ ")
48 # Add a blank line to the output
56 # Render `self` as Manpage format
57 fun render_man
(v
: ManRenderer) do visit_all
(v
)
62 redef class MdBlockQuote
63 redef fun render_man
(v
) do
71 redef class MdCodeBlock
72 redef fun render_man
(v
) do
73 v
.add
".RS\n.nf\n\\f[C]"
76 var literal
= self.literal
77 if literal
!= null then
78 var lines
= literal
.split
("\n")
79 for i
in [0 .. lines
.length
[ do
80 if i
== lines
.length
- 1 then break
87 v
.add
"\\f[]\n.fi\n.RE"
93 redef fun render_man
(v
) do
94 var level
= self.level
98 else if level
== 2 then
100 else if level
>= 3 then
101 # We use dictionary (titled paragraph) to simulate a 3rd level (or more)
109 redef class MdUnorderedList
110 redef fun render_man
(v
) do
114 var node
= first_child
115 while node
!= null do
128 redef class MdOrderedList
129 redef fun render_man
(v
) do
133 var index
= start_number
134 var node
= first_child
135 while node
!= null do
136 v
.add
".IP \"{index}.\
" 3"
149 redef class MdParagraph
150 redef fun render_man
(v
) do
151 var in_list
= is_in_list
162 redef class MdThematicBreak
163 redef fun render_man
(v
) do
169 redef class MdHtmlBlock
170 redef fun render_man
(v
) do
172 v
.add literal
or else ""
179 redef class MdLineBreak
180 redef fun render_man
(v
) do
186 redef fun render_man
(v
) do
193 redef class MdEmphasis
194 redef fun render_man
(v
) do
201 redef class MdStrongEmphasis
202 redef fun render_man
(v
) do
209 redef class MdHtmlInline
210 redef fun render_man
(v
) do
215 redef class MdLinkOrImage
216 redef fun render_man
(v
) do
217 var title
= self.title
222 if title
!= null and not title
.is_empty
then
231 redef fun render_man
(v
) do
239 redef fun render_man
(v
) do
248 redef class MdWikilink
249 redef fun render_man
(v
) do
251 var title
= self.title
252 if title
!= null then