Sha256: fcc16897229f106e5f7fdbaaa4cdd52c0cd391899f5a3d8775dc3455b3c5c8b1

Contents?: true

Size: 1.7 KB

Versions: 7

Compression:

Stored size: 1.7 KB

Contents

#require 'rubygems'
#require 'kramdown'
require 'bluecloth'

module Typedown
  class Document < String
    def initialize text = nil
      super ""
      self << text if text
    end

    def to_markdown
      text = self

      # Translate '! headings' to '# headings'
      text.gsub!(/^! /, "# ")
      text.gsub!(/^!! /, "## ")
      text.gsub!(/^!!! /, "### ")
      text.gsub!(/^!!!! /, "#### ")
      text.gsub!(/^!!!!! /, "##### ")
      text.gsub!(/^!!!!!! /, "###### ")

      # Dialogue dashes
      text.gsub!(/^-\.? /, "&#8213; ")
      text.gsub!(/\s-\.? /, " &#8213; ")

      # Insert placeholders around lead in
      text.gsub!(/^\. (( *[^\n].+\n)*)/, "! x!\\1!x-!\n")
      # Remove placeholders while using them to remove whitespace
      text.gsub!(/^! x!\s*/, "**")
      text.gsub!(/\s*!x-!$/, "**")


      # Insert placeholders around lead in
      text.gsub!(/^\/\/\. (( *[^\n].+\n)*)/, "! x!\\1!x-!\n")
      # Remove placeholders while using them to remove whitespace
      text.gsub!(/^! x!\s*/, "**")
      text.gsub!(/\s*!x-!$/, "**")


      # Insert placeholders around lead in
      text.gsub!(/^\/\. (( *[^\n].+\n)*)/, "! x!\\1!x-!\n")
      # Remove placeholders while using them to remove whitespace
      text.gsub!(/^! x!\s*/, "*")
      text.gsub!(/\s*!x-!$/, "*")

      # Slash for _
      text.gsub!(/(\s)\/(\S+)\/(\s)[\.\,\?\!]?/, "\\1_\\2_\\3")
      text.gsub!(/(\s)\/\/(\S+)\/\/[\.\,\?\!]?(\s)/, "\\1__\\2__\\3")
      text.gsub!(/(\s)\/\/\/(\S+)\/\/\/[\.\,\?\!]?(\s)/, "\\1___\\2___\\3")
      text
    end


    def to_html
      #kramdown = Kramdown::Document.new to_markdown
      #kramdown.to_html
      bluecloth = BlueCloth::new( to_markdown )
      bluecloth.to_html
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
typedown-0.0.8 lib/typedown/document.rb
typedown-0.0.7 lib/typedown/document.rb
typedown-0.0.6 lib/typedown/document.rb
typedown-0.0.5 lib/typedown/document.rb
typedown-0.0.4 lib/typedown/document.rb
typedown-0.0.3 lib/typedown/document.rb
typedown-0.0.2 lib/typedown/document.rb