class Caramelize::Wikka2Markdown
Attributes
source_body[R]
Public Class Methods
new(source_body)
click to toggle source
# File lib/caramelize/filters/wikka_to_markdown.rb, line 5 def initialize(source_body) @source_body = source_body end
Public Instance Methods
replace_code_block()
click to toggle source
# File lib/caramelize/filters/wikka_to_markdown.rb, line 57 def replace_code_block target_body.gsub!(/^%%\s(.*?)%%\s?/m) do $1.gsub(/^/, ' ') end end
replace_formatting()
click to toggle source
# File lib/caramelize/filters/wikka_to_markdown.rb, line 31 def replace_formatting target_body.gsub!(/(\*\*)(.*?)(\*\*)/) {|s| '**' + $2 + '**' } #bold target_body.gsub!(/(\/\/)(.*?)(\/\/)/, '*\2*') #italic target_body.gsub!(/(__)(.*?)(__)/) {|s| '<u>' + $2 + '</u>'} #underline target_body.gsub!(/(---)/, ' ') #forced linebreak end
replace_headlines()
click to toggle source
# File lib/caramelize/filters/wikka_to_markdown.rb, line 23 def replace_headlines target_body.gsub!(/(======)(.*?)(======)/ ) {|s| '# ' + $2 } #h1 target_body.gsub!(/(=====)(.*?)(=====)/) {|s| '## ' + $2 } #h2 target_body.gsub!(/(====)(.*?)(====)/) {|s| '### ' + $2 } #h3 target_body.gsub!(/(===)(.*?)(===)/) {|s| '#### ' + $2 } #h4 target_body.gsub!(/(==)(.*?)(==)/) {|s| '##### ' + $2 } #h5 end
replace_links()
click to toggle source
# File lib/caramelize/filters/wikka_to_markdown.rb, line 51 def replace_links target_body.gsub!(/[\[]{2}((\w+):[\S][^\| ]*)[\| ](.*)[\]]{2}/, '[\3](\1)') target_body.gsub!(/[\[]{2}((\w+):.*)[\]]{2}/, '<\1>') end
replace_lists()
click to toggle source
# File lib/caramelize/filters/wikka_to_markdown.rb, line 38 def replace_lists target_body.gsub!(/(\t-\s?)(.*)/, '* \2') # unordered list target_body.gsub!(/(~-\s?)(.*)/, '* \2') # unordered list target_body.gsub!(/( -\s?)(.*)/, '* \2') # unordered list target_body.gsub!(/(~1\)\s?)(.*)/, '1. \2') # unordered list # TODO ordered lists end
replace_wiki_links()
click to toggle source
# File lib/caramelize/filters/wikka_to_markdown.rb, line 47 def replace_wiki_links target_body.gsub!(/[\[]{2}(\w+)[\s|](.+?)[\]]{2}/, '[[\2|\1]]') end
run()
click to toggle source
# File lib/caramelize/filters/wikka_to_markdown.rb, line 9 def run # TODO images: ({{image)(url\=?)?(.*)(}}) # markdown:  replace_headlines replace_formatting replace_lists replace_wiki_links replace_links replace_code_block target_body end
target_body()
click to toggle source
# File lib/caramelize/filters/wikka_to_markdown.rb, line 63 def target_body @target_body ||= source_body.dup end