Class: CommonMarker::HtmlRenderer
- Inherits:
-
Renderer
- Object
- Renderer
- CommonMarker::HtmlRenderer
show all
- Defined in:
- lib/commonmarker/renderer/html_renderer.rb
Instance Attribute Summary
Attributes inherited from Renderer
#in_plain, #in_tight, #warnings
Instance Method Summary
collapse
Methods inherited from Renderer
#block, #blocksep, #container, #containersep, #cr, #document, #initialize, #out, #plain, #reference_def
Instance Method Details
#blockquote(_) ⇒ Object
58
59
60
61
62
63
64
|
# File 'lib/commonmarker/renderer/html_renderer.rb', line 58
def blockquote(_)
block do
container("<blockquote>\n", '</blockquote>') do
out(:children)
end
end
end
|
#code(node) ⇒ Object
126
127
128
129
130
|
# File 'lib/commonmarker/renderer/html_renderer.rb', line 126
def code(node)
out('<code>')
out(escape_html(node.string_content))
out('</code>')
end
|
#code_block(node) ⇒ Object
72
73
74
75
76
77
78
79
80
81
82
83
|
# File 'lib/commonmarker/renderer/html_renderer.rb', line 72
def code_block(node)
block do
out('<pre><code')
if node.fence_info && !node.fence_info.empty?
out(' class="language-', node.fence_info.split(/\s+/)[0], '">')
else
out('>')
end
out(escape_html(node.string_content))
out('</code></pre>')
end
end
|
#emph(_) ⇒ Object
95
96
97
|
# File 'lib/commonmarker/renderer/html_renderer.rb', line 95
def emph(_)
out('<em>', :children, '</em>')
end
|
7
8
9
10
11
12
|
# File 'lib/commonmarker/renderer/html_renderer.rb', line 7
def (node)
block do
out('<h', node., '>', :children,
'</h', node., '>')
end
end
|
#hrule(_) ⇒ Object
66
67
68
69
70
|
# File 'lib/commonmarker/renderer/html_renderer.rb', line 66
def hrule(_)
block do
out('<hr />')
end
end
|
#html(node) ⇒ Object
85
86
87
88
89
|
# File 'lib/commonmarker/renderer/html_renderer.rb', line 85
def html(node)
block do
out(node.string_content)
end
end
|
#image(node) ⇒ Object
111
112
113
114
115
116
117
118
119
120
|
# File 'lib/commonmarker/renderer/html_renderer.rb', line 111
def image(node)
out('<img src="', escape_href(node.url), '"')
plain do
out(' alt="', :children, '"')
end
if node.title && !node.title.empty?
out(' title="', escape_html(node.title), '"')
end
out(' />')
end
|
#inline_html(node) ⇒ Object
91
92
93
|
# File 'lib/commonmarker/renderer/html_renderer.rb', line 91
def inline_html(node)
out(node.string_content)
end
|
#linebreak(node) ⇒ Object
132
133
134
135
|
# File 'lib/commonmarker/renderer/html_renderer.rb', line 132
def linebreak(node)
out('<br />')
softbreak(node)
end
|
#link(node) ⇒ Object
103
104
105
106
107
108
109
|
# File 'lib/commonmarker/renderer/html_renderer.rb', line 103
def link(node)
out('<a href="', node.url.nil? ? '' : escape_href(node.url), '"')
if node.title && !node.title.empty?
out(' title="', escape_html(node.title), '"')
end
out('>', :children, '</a>')
end
|
#list(node) ⇒ Object
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
# File 'lib/commonmarker/renderer/html_renderer.rb', line 26
def list(node)
old_in_tight = @in_tight
@in_tight = node.list_tight
block do
if node.list_type == :bullet_list
container("<ul>\n", '</ul>') do
out(:children)
end
else
start = if node.list_start == 1
"<ol>\n"
else
"<ol start=\"#{node.list_start}\">\n"
end
container(start, '</ol>') do
out(:children)
end
end
end
@in_tight = old_in_tight
end
|
#list_item(_) ⇒ Object
50
51
52
53
54
55
56
|
# File 'lib/commonmarker/renderer/html_renderer.rb', line 50
def list_item(_)
block do
container('<li>', '</li>') do
out(:children)
end
end
end
|
#paragraph(node) ⇒ Object
14
15
16
17
18
19
20
21
22
23
24
|
# File 'lib/commonmarker/renderer/html_renderer.rb', line 14
def paragraph(node)
if @in_tight && node.parent.type != :blockquote
out(:children)
else
block do
container('<p>', '</p>') do
out(:children)
end
end
end
end
|
#render(node) ⇒ Object
3
4
5
|
# File 'lib/commonmarker/renderer/html_renderer.rb', line 3
def render(node)
super(node)
end
|
#softbreak(_) ⇒ Object
137
138
139
|
# File 'lib/commonmarker/renderer/html_renderer.rb', line 137
def softbreak(_)
out("\n")
end
|
#strong(_) ⇒ Object
99
100
101
|
# File 'lib/commonmarker/renderer/html_renderer.rb', line 99
def strong(_)
out('<strong>', :children, '</strong>')
end
|
#text(node) ⇒ Object
122
123
124
|
# File 'lib/commonmarker/renderer/html_renderer.rb', line 122
def text(node)
out(escape_html(node.string_content))
end
|