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 # Markdown document rendering
16 module markdown_rendering
20 # Common interface for all markdown renderer
25 fun render
(node
: MdNode): String is abstract
28 # A renderer that output raw text
32 # Text under construction
33 private var text
: Buffer is noinit
35 redef fun render
(node
) do
41 # Append `string` to `text`
42 fun add
(string
: String) do text
.append
(string
)
44 redef fun visit
(node
) do node
.render_raw_text
(self)
49 # Return `self` as raw text
50 fun raw_text
: String do
51 var v
= new RawTextVisitor
55 # Render `self` as raw text
56 fun render_raw_text
(v
: RawTextVisitor) do visit_all
(v
)
60 redef fun render_raw_text
(v
) do v
.add literal
63 redef class MdLineBreak
64 redef fun render_raw_text
(v
) do v
.add
"\n"
68 redef fun render_raw_text
(v
) do v
.add literal