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 # Simple *groff* decorator restricted for manpages.
20 # `Decorator` that outputs markdown.
24 redef fun add_ruler
(v
, block
) do v
.add
"***\n"
26 redef fun add_headline
(v
, block
) do
33 # We use dictionary (titled paragraph) to simulate a 3rd level (or more)
40 redef fun add_paragraph
(v
, block
) do
41 if not in_unorderedlist
and not in_orderedlist
then
50 redef fun add_code
(v
, block
) do
51 v
.add
".RS\n.nf\n\\f[C]\n"
54 v
.add
"\\f[]\n.fi\n.RE\n"
57 redef fun add_blockquote
(v
, block
) do
63 redef fun add_unorderedlist
(v
, block
) do
65 in_unorderedlist
= true
67 in_unorderedlist
= false
70 private var in_unorderedlist
= false
72 redef fun add_orderedlist
(v
, block
) do
77 in_orderedlist
= false
80 private var in_orderedlist
= false
81 private var current_li
= 0
83 redef fun add_listitem
(v
, block
) do
84 if in_unorderedlist
then
85 v
.add
".IP \\[bu] 3\n"
86 else if in_orderedlist
then
88 v
.add
".IP \"{current_li}.\
" 3\n"
94 redef fun add_em
(v
, text
) do
100 redef fun add_strong
(v
, text
) do
106 redef fun add_strike
(v
, text
) do
112 redef fun add_image
(v
, link
, name
, comment
) do
115 append_value
(v
, link
)
116 if comment
!= null and not comment
.is_empty
then
118 append_value
(v
, comment
)
123 redef fun add_link
(v
, link
, name
, comment
) do
126 append_value
(v
, link
)
127 if comment
!= null and not comment
.is_empty
then
129 append_value
(v
, comment
)
134 redef fun add_abbr
(v
, name
, comment
) do
138 append_value(v, comment)
142 redef fun add_span_code(v, text, from, to) do
144 append_code(v, text, from, to)
148 redef fun add_line_break(v) do
152 redef fun append_value(v, text) do for c in text do escape_char(v, c)
154 redef fun add_char(v, c) do
155 # Escape - because manpages
162 redef fun escape_char(v, c) do add_char(v, c)
164 redef fun append_code(v, buffer, from, to) do
165 for i in [from..to[ do
167 if c == '-' or c == ' ' then