class CommonMarker::HtmlRenderer
Public Instance Methods
blockquote(node)
click to toggle source
# File lib/commonmarker/renderer/html_renderer.rb, line 69 def blockquote(node) block do container("<blockquote#{sourcepos(node)}>\n", '</blockquote>') do out(:children) end end end
code(node)
click to toggle source
# File lib/commonmarker/renderer/html_renderer.rb, line 153 def code(node) out('<code>') out(escape_html(node.string_content)) out('</code>') end
code_block(node)
click to toggle source
# File lib/commonmarker/renderer/html_renderer.rb, line 83 def code_block(node) block do if option_enabled?(:GITHUB_PRE_LANG) out("<pre#{sourcepos(node)}") if node.fence_info && !node.fence_info.empty? out(' lang="', node.fence_info.split(/\s+/)[0], '"') end out('><code>') else out("<pre#{sourcepos(node)}><code") if node.fence_info && !node.fence_info.empty? out(' class="language-', node.fence_info.split(/\s+/)[0], '">') else out('>') end end out(escape_html(node.string_content)) out('</code></pre>') end end
document(_)
click to toggle source
Calls superclass method
CommonMarker::Renderer#document
# File lib/commonmarker/renderer/html_renderer.rb, line 7 def document(_) super if @written_footnote_ix out("</ol>\n</section>\n") end end
emph(_)
click to toggle source
# File lib/commonmarker/renderer/html_renderer.rb, line 122 def emph(_) out('<em>', :children, '</em>') end
footnote_definition(_)
click to toggle source
# File lib/commonmarker/renderer/html_renderer.rb, line 217 def footnote_definition(_) if !@footnote_ix out("<section class=\"footnotes\">\n<ol>\n") @footnote_ix = 0 end @footnote_ix += 1 out("<li id=\"fn#@footnote_ix\">\n", :children) if out_footnote_backref out("\n") end out("</li>\n") #</ol> #</section> end
footnote_reference(node)
click to toggle source
# File lib/commonmarker/renderer/html_renderer.rb, line 213 def footnote_reference(node) out("<sup class=\"footnote-ref\"><a href=\"#fn#{node.string_content}\" id=\"fnref#{node.string_content}\">#{node.string_content}</a></sup>") end
header(node)
click to toggle source
# File lib/commonmarker/renderer/html_renderer.rb, line 14 def header(node) block do out('<h', node.header_level, "#{sourcepos(node)}>", :children, '</h', node.header_level, '>') end end
hrule(node)
click to toggle source
# File lib/commonmarker/renderer/html_renderer.rb, line 77 def hrule(node) block do out("<hr#{sourcepos(node)} />") end end
html(node)
click to toggle source
# File lib/commonmarker/renderer/html_renderer.rb, line 104 def html(node) block do if option_enabled?(:SAFE) out('<!-- raw HTML omitted -->') else out(tagfilter(node.string_content)) end end end
image(node)
click to toggle source
# File lib/commonmarker/renderer/html_renderer.rb, line 138 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)
click to toggle source
# File lib/commonmarker/renderer/html_renderer.rb, line 114 def inline_html(node) if option_enabled?(:SAFE) out('<!-- raw HTML omitted -->') else out(tagfilter(node.string_content)) end end
linebreak(node)
click to toggle source
# File lib/commonmarker/renderer/html_renderer.rb, line 159 def linebreak(node) out("<br />\n") end
link(node)
click to toggle source
# File lib/commonmarker/renderer/html_renderer.rb, line 130 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)
click to toggle source
# File lib/commonmarker/renderer/html_renderer.rb, line 37 def list(node) old_in_tight = @in_tight @in_tight = node.list_tight block do if node.list_type == :bullet_list container("<ul#{sourcepos(node)}>\n", '</ul>') do out(:children) end else start = if node.list_start == 1 "<ol#{sourcepos(node)}>\n" else "<ol start=\"#{node.list_start}\"#{sourcepos(node)}>\n" end container(start, '</ol>') do out(:children) end end end @in_tight = old_in_tight end
list_item(node)
click to toggle source
# File lib/commonmarker/renderer/html_renderer.rb, line 61 def list_item(node) block do container("<li#{sourcepos(node)}>", '</li>') do out(:children) end end end
paragraph(node)
click to toggle source
# File lib/commonmarker/renderer/html_renderer.rb, line 21 def paragraph(node) if @in_tight && node.parent.type != :blockquote out(:children) else block do container("<p#{sourcepos(node)}>", '</p>') do out(:children) if node.parent.type == :footnote_definition && node.next.nil? out(" ") out_footnote_backref end end end end end
render(node)
click to toggle source
Calls superclass method
CommonMarker::Renderer#render
# File lib/commonmarker/renderer/html_renderer.rb, line 3 def render(node) super(node) end
softbreak(_)
click to toggle source
# File lib/commonmarker/renderer/html_renderer.rb, line 163 def softbreak(_) if option_enabled?(:HARDBREAKS) out("<br />\n") elsif option_enabled?(:NOBREAKS) out(' ') else out("\n") end end
strikethrough(_)
click to toggle source
# File lib/commonmarker/renderer/html_renderer.rb, line 209 def strikethrough(_) out('<del>', :children, '</del>') end
strong(_)
click to toggle source
# File lib/commonmarker/renderer/html_renderer.rb, line 126 def strong(_) out('<strong>', :children, '</strong>') end
table(node)
click to toggle source
# File lib/commonmarker/renderer/html_renderer.rb, line 173 def table(node) @alignments = node.table_alignments @needs_close_tbody = false out("<table#{sourcepos(node)}>\n", :children) out("</tbody>") if @needs_close_tbody out("</table>\n") end
table_cell(node)
click to toggle source
# File lib/commonmarker/renderer/html_renderer.rb, line 198 def table_cell(node) align = case @alignments[@column_index] when :left; ' align="left"' when :right; ' align="right"' when :center; ' align="center"' else; '' end out(@in_header ? "\n<th#{align}#{sourcepos(node)}>" : "\n<td#{align}#{sourcepos(node)}>", :children, @in_header ? "</th>" : "</td>") @column_index += 1 end
table_header(node)
click to toggle source
# File lib/commonmarker/renderer/html_renderer.rb, line 181 def table_header(node) @column_index = 0 @in_header = true out("<thead>\n<tr#{sourcepos(node)}>", :children, "\n</tr>\n</thead>") @in_header = false end
table_row(node)
click to toggle source
# File lib/commonmarker/renderer/html_renderer.rb, line 189 def table_row(node) @column_index = 0 if !@in_header && !@needs_close_tbody @needs_close_tbody = true out("\n<tbody>") end out("\n<tr#{sourcepos(node)}>", :children, "\n</tr>") end
text(node)
click to toggle source
# File lib/commonmarker/renderer/html_renderer.rb, line 149 def text(node) out(escape_html(node.string_content)) end
Private Instance Methods
out_footnote_backref()
click to toggle source
# File lib/commonmarker/renderer/html_renderer.rb, line 235 def out_footnote_backref return false if @written_footnote_ix == @footnote_ix @written_footnote_ix = @footnote_ix out("<a href=\"#fnref#@footnote_ix\" class=\"footnote-backref\">↩</a>") true end