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(node) ⇒ Object
57
58
59
60
61
62
63
|
# File 'lib/commonmarker/renderer/html_renderer.rb', line 57
def blockquote(node)
block do
container("<blockquote>\n", '</blockquote>') do
out(:children)
end
end
end
|
#code(node) ⇒ Object
125
126
127
128
129
|
# File 'lib/commonmarker/renderer/html_renderer.rb', line 125
def code(node)
out('<code>')
out(escape_html(node.string_content))
out('</code>')
end
|
#code_block(node) ⇒ Object
71
72
73
74
75
76
77
78
79
80
81
82
|
# File 'lib/commonmarker/renderer/html_renderer.rb', line 71
def code_block(node)
block do
out('<pre><code')
if node.fence_info && node.fence_info.length > 0
out(' class="language-', node.fence_info.split(/\s+/)[0], '">')
else
out(">")
end
out(escape_html(node.string_content))
out('</code></pre>')
end
end
|
#emph(node) ⇒ Object
94
95
96
|
# File 'lib/commonmarker/renderer/html_renderer.rb', line 94
def emph(node)
out('<em>', :children, '</em>')
end
|
#escape_html(str) ⇒ Object
145
146
147
|
# File 'lib/commonmarker/renderer/html_renderer.rb', line 145
def escape_html(str)
EscapeUtils.escape_html(str).gsub(''', "'").gsub('/', '/')
end
|
#escape_uri(str) ⇒ Object
these next two methods are horrendous BS
141
142
143
|
# File 'lib/commonmarker/renderer/html_renderer.rb', line 141
def escape_uri(str)
EscapeUtils.escape_uri(str.gsub('%20', ' ')).gsub(']', '%5D').gsub('&', '&').gsub('[', '%5B')
end
|
9
10
11
12
13
14
|
# File 'lib/commonmarker/renderer/html_renderer.rb', line 9
def (node)
block do
out('<h', node., '>', :children,
'</h', node., ">")
end
end
|
#hrule(node) ⇒ Object
65
66
67
68
69
|
# File 'lib/commonmarker/renderer/html_renderer.rb', line 65
def hrule(node)
block do
out('<hr />')
end
end
|
#html(node) ⇒ Object
84
85
86
87
88
|
# File 'lib/commonmarker/renderer/html_renderer.rb', line 84
def html(node)
block do
out(node.string_content)
end
end
|
#image(node) ⇒ Object
110
111
112
113
114
115
116
117
118
119
|
# File 'lib/commonmarker/renderer/html_renderer.rb', line 110
def image(node)
out('<img src="', escape_uri(node.url), '"')
plain do
out(' alt="', :children, '"')
end
if node.title && node.title.length > 0
out(' title="', escape_html(node.title), '"')
end
out(' />')
end
|
#inline_html(node) ⇒ Object
90
91
92
|
# File 'lib/commonmarker/renderer/html_renderer.rb', line 90
def inline_html(node)
out(node.string_content)
end
|
#linebreak(node) ⇒ Object
131
132
133
134
|
# File 'lib/commonmarker/renderer/html_renderer.rb', line 131
def linebreak(node)
out('<br />')
softbreak(node)
end
|
#link(node) ⇒ Object
102
103
104
105
106
107
108
|
# File 'lib/commonmarker/renderer/html_renderer.rb', line 102
def link(node)
out('<a href="', node.url.nil? ? '' : escape_uri(node.url), '"')
if node.title && node.title.length > 0
out(' title="', escape_html(node.title), '"')
end
out('>', :children, '</a>')
end
|
#list(node) ⇒ Object
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
# File 'lib/commonmarker/renderer/html_renderer.rb', line 28
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 = node.list_start == 1 ? "<ol>\n" :
('<ol start="' + node.list_start.to_s + "\">\n")
container(start, '</ol>') do
out(:children)
end
end
end
@in_tight = old_in_tight
end
|
#list_item(node) ⇒ Object
49
50
51
52
53
54
55
|
# File 'lib/commonmarker/renderer/html_renderer.rb', line 49
def list_item(node)
block do
container('<li>', '</li>') do
out(:children)
end
end
end
|
#paragraph(node) ⇒ Object
16
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/commonmarker/renderer/html_renderer.rb', line 16
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
5
6
7
|
# File 'lib/commonmarker/renderer/html_renderer.rb', line 5
def render(node)
result = super(node)
end
|
#softbreak(node) ⇒ Object
136
137
138
|
# File 'lib/commonmarker/renderer/html_renderer.rb', line 136
def softbreak(node)
out("\n")
end
|
#strong(node) ⇒ Object
98
99
100
|
# File 'lib/commonmarker/renderer/html_renderer.rb', line 98
def strong(node)
out('<strong>', :children, '</strong>')
end
|
#text(node) ⇒ Object
121
122
123
|
# File 'lib/commonmarker/renderer/html_renderer.rb', line 121
def text(node)
out(escape_html(node.string_content))
end
|