class MD2DW::DokuwikiRenderer
Public Instance Methods
autolink(link, link_type)
click to toggle source
# File lib/md2dw/dokuwiki_renderer.rb, line 63 def autolink link, link_type link end
block_code(code, language)
click to toggle source
# File lib/md2dw/dokuwiki_renderer.rb, line 4 def block_code code, language language = " #{language}" unless language.nil? "\n<code%s>\n%s</code>\n" % [ language, code ] end
block_html(raw_html)
click to toggle source
# File lib/md2dw/dokuwiki_renderer.rb, line 17 def block_html raw_html raw_html end
block_quote(quote)
click to toggle source
# File lib/md2dw/dokuwiki_renderer.rb, line 13 def block_quote quote "\n<blockquote>%s</blockquote>\n" % quote end
codespan(code)
click to toggle source
# File lib/md2dw/dokuwiki_renderer.rb, line 67 def codespan code code = "%%#{code}%%" if code =~ /--/ "''%s''" % code end
footnote_def(content, number)
click to toggle source
# File lib/md2dw/dokuwiki_renderer.rb, line 25 def footnote_def content, number '[(r%s>%s)]' % [ number, content.strip ] end
footnote_ref(number)
click to toggle source
# File lib/md2dw/dokuwiki_renderer.rb, line 100 def footnote_ref number '[(r%s)]' % number end
footnotes(content)
click to toggle source
# File lib/md2dw/dokuwiki_renderer.rb, line 21 def footnotes content "\n%s\n\n" % content end
header(text, header_level)
click to toggle source
# File lib/md2dw/dokuwiki_renderer.rb, line 29 def header text, header_level level = 7 - header_level "\n%s %s %s\n" % [ '=' * level, text, '=' * level ] end
highlight(text)
click to toggle source
# File lib/md2dw/dokuwiki_renderer.rb, line 96 def highlight text '<mark>%s</mark>' % text end
hrule()
click to toggle source
# File lib/md2dw/dokuwiki_renderer.rb, line 34 def hrule "\n-----\n" end
image(link, title, alt_text)
click to toggle source
# File lib/md2dw/dokuwiki_renderer.rb, line 72 def image link, title, alt_text '{{%s}}' % link end
linebreak()
click to toggle source
# File lib/md2dw/dokuwiki_renderer.rb, line 76 def linebreak "\n" end
link(link, title, content)
click to toggle source
# File lib/md2dw/dokuwiki_renderer.rb, line 80 def link link, title, content '[[%s|%s]]' % [ link, content ] end
list(contents, list_type)
click to toggle source
# File lib/md2dw/dokuwiki_renderer.rb, line 38 def list contents, list_type "\n" + contents end
list_item(text, list_type)
click to toggle source
# File lib/md2dw/dokuwiki_renderer.rb, line 42 def list_item text, list_type char = list_type =~ /unordered/ ? '*' : '-' " %s %s" % [ char, text ] end
paragraph(text)
click to toggle source
# File lib/md2dw/dokuwiki_renderer.rb, line 47 def paragraph text "\n%s\n" % text end
postprocess(full_document)
click to toggle source
# File lib/md2dw/dokuwiki_renderer.rb, line 123 def postprocess full_document full_document.gsub!(/%_s_%(.*?)%_s_%/, '<del>\1</del>') # Strike full_document.gsub!(/%_b_%(.*?)%_b_%/, '**\1**') # Bold full_document.gsub!(/%_i_%(.*?)%_i_%/, '//\1//') # Italic full_document.gsub!(/%_x_%(.*?)%_x_%/, '<sup>\1</sup>') # Superscript full_document.gsub!(/%_q_%(.*?)%_q_%/, '<q>\1</q>') # Cite # Fix tables full_document = full_document.lines.map do |line| if line =~ /\^ \| \| (.+) \| \| \^$/ "^ %s ^\n" % $1.gsub(' || ', ' ^ ') elsif line =~ /^\| \| (.+) \| \|$/ "| %s |\n" % $1.gsub(' || ', ' | ') else line end end.join.strip full_document end
preprocess(full_document)
click to toggle source
# File lib/md2dw/dokuwiki_renderer.rb, line 104 def preprocess full_document full_document.gsub!(/(\b|[^\\])??~~([^~].*?)~~/, '\1%_s_%\2%_s_%') # Strike full_document.gsub!(/(\b|[^\\])??\*\*([^*].*?)\*\*/, '\1%_b_%\2%_b_%') # Bold full_document.gsub!(/(\b|[^\\])??\*([^*].*?)\*/, '\1%_i_%\2%_i_%') # Italic full_document.gsub!(/<sup>(.*?)<\/sup>/, '%_x_%\1%_x_%') # Superscript full_document.gsub!(/<cite>(.*?)<\/cite>/, '%_q_%\1%_q_%') # Cite # Fix tables full_document = full_document.lines.map do |line| if line =~ /\^\| (.*?) \|$/ "%s\n" % $1 else line end end.join.strip full_document end
quote(text)
click to toggle source
# File lib/md2dw/dokuwiki_renderer.rb, line 9 def quote text text end
raw_html(raw_html)
click to toggle source
# File lib/md2dw/dokuwiki_renderer.rb, line 84 def raw_html raw_html '<html>%s</html>' % raw_html end
strikethrough(text)
click to toggle source
# File lib/md2dw/dokuwiki_renderer.rb, line 88 def strikethrough text '<del>%s</del>' % text end
superscript(text)
click to toggle source
# File lib/md2dw/dokuwiki_renderer.rb, line 92 def superscript text '<sup>%s</sup>' % text end
table(header, body)
click to toggle source
# File lib/md2dw/dokuwiki_renderer.rb, line 51 def table header, body "\n^ %s ^\n%s\n" % [ header.strip, body.strip ] end
table_cell(content, alignment)
click to toggle source
# File lib/md2dw/dokuwiki_renderer.rb, line 59 def table_cell content, alignment '| %s |' % content.strip end
table_row(content)
click to toggle source
# File lib/md2dw/dokuwiki_renderer.rb, line 55 def table_row content "| %s |\n" % content.strip end