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 var headlines
= new ArrayMap[String, HeadLine]
26 redef fun add_ruler
(v
, block
) do v
.add
"***\n"
28 redef fun add_headline
(v
, block
) do
35 # We use dictionary (titled paragraph) to simulate a 3rd level (or more)
42 redef fun add_paragraph
(v
, block
) do
43 if not in_unorderedlist
and not in_orderedlist
then
52 redef fun add_code
(v
, block
) do
53 v
.add
".RS\n.nf\n\\f[C]\n"
56 v
.add
"\\f[]\n.fi\n.RE\n"
59 redef fun add_blockquote
(v
, block
) do
65 redef fun add_unorderedlist
(v
, block
) do
67 in_unorderedlist
= true
69 in_unorderedlist
= false
72 private var in_unorderedlist
= false
74 redef fun add_orderedlist
(v
, block
) do
79 in_orderedlist
= false
82 private var in_orderedlist
= false
83 private var current_li
= 0
85 redef fun add_listitem
(v
, block
) do
86 if in_unorderedlist
then
87 v
.add
".IP \\[bu] 3\n"
88 else if in_orderedlist
then
90 v
.add
".IP \"{current_li}.\
" 3\n"
96 redef fun add_em
(v
, text
) do
102 redef fun add_strong
(v
, text
) do
108 redef fun add_strike
(v
, text
) do
114 redef fun add_image
(v
, link
, name
, comment
) do
117 append_value
(v
, link
)
118 if comment
!= null and not comment
.is_empty
then
120 append_value
(v
, comment
)
125 redef fun add_link
(v
, link
, name
, comment
) do
128 append_value
(v
, link
)
129 if comment
!= null and not comment
.is_empty
then
131 append_value
(v
, comment
)
136 redef fun add_abbr
(v
, name
, comment
) do
140 append_value(v, comment)
144 redef fun add_span_code(v, text, from, to) do
146 append_code(v, text, from, to)
150 redef fun add_line_break(v) do
154 redef fun append_value(v, text) do for c in text do escape_char(v, c)
156 redef fun add_char(v, c) do
157 # Escape - because manpages
164 redef fun escape_char(v, c) do add_char(v, c)
166 redef fun append_code(v, buffer, from, to) do
167 for i in [from..to[ do
169 if c == '-' or c == ' ' then