Sha256: 07f5c9b4aef61ea6dd17615bc3e927a14dc678a97b75c9f384f03cd3f92fd18d

Contents?: true

Size: 1.28 KB

Versions: 1

Compression:

Stored size: 1.28 KB

Contents

#Encoding: UTF-8
module Caramelize
  class Wikka2Markdown
    
    # take an input stream and convert all wikka syntax to markdown syntax
    def run body
      body = body.dup
      body.gsub!(/(======)(.*?)(======)/ ) {|s| '# ' + $2 } #h1
      body.gsub!(/(=====)(.*?)(=====)/) {|s| '## ' + $2 }   #h2
      body.gsub!(/(====)(.*?)(====)/) {|s| '### ' + $2 }   #h3
      body.gsub!(/(===)(.*?)(===)/) {|s| '#### ' + $2 }   #h4
  
      body.gsub!(/(\*\*)(.*?)(\*\*)/) {|s| '**' + $2 + '**' }   #bold
      body.gsub!(/(\/\/)(.*?)(\/\/)/) {|s| '_' + $2 + '_' }   #italic
      #str.gsub!(/(===)(.*?)(===)/) {|s| '`' + $2 + '`'}   #code
      body.gsub!(/(__)(.*?)(__)/) {|s| '<u>' + $2 + '</u>'}   #underline
      body.gsub!(/(---)/, '  ')   #forced linebreak
      
      #body.gsub!(/(.*?)(\n\t-)(.*?)/) {|s| $1 + $3 }   #list
      
      body.gsub!(/(\t-)(.*)/, '*\2')    # unordered list
      body.gsub!(/(~-)(.*)/, '*\2')     # unordered list
      # TODO ordered lists

      # TODO images: ({{image)(url\=?)?(.*)(}})

      #str.gsub!(/(----)/) {|s| '~~~~'}   #seperator


      body.gsub!(/(\[\[)(\w+)\s(.+?)(\]\])/, '[[\3|\2]]')
      #body.gsub!(/\[\[(\w+)\s(.+)\]\]/, ' [[\1 | \2]] ')
      
      
      # TODO more syntax conversion for links and images
      
      body
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
caramelize-0.2.0 lib/caramelize/filters/wikka_to_markdown.rb