Sha256: f5913349f77873d867eafb88f6af2a1c7bb91304ffe2b2ae44091a376724ec15

Contents?: true

Size: 888 Bytes

Versions: 6

Compression:

Stored size: 888 Bytes

Contents

# encoding: UTF-8

require 'kramdown'

module Spontaneous::Field
  class Markdown < Base
    has_editor

    def outputs
      [:html]
    end

    def generate_html(input, site)
      input.to_html
    end

    def preprocess(input, site)
      # convert lines ending with newlines into a <br/>
      # as official Markdown syntax isn't suitable for
      # casual users
      # code taken from:
      # http://github.github.com/github-flavored-markdown/
      output = input.gsub(/^[\w\<][^\n]*\n+/) do |x|
        x =~ /\n{2}/ ? x : (x.strip!; x << "  \n")
      end

      # prevent foo_bar_baz from ending up with an italic word in the middle
      output.gsub!(/(^(?! {4}|\t)\w+_\w+_\w[\w_]*)/) do |x|
        x.gsub('_', '\_') if x.split('').sort.to_s[0..1] == '__'
      end
      Kramdown::Document.new(output)
    end

    self.register(:markdown, :markup, :richtext)
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
spontaneous-0.2.0.beta10 lib/spontaneous/field/markdown.rb
spontaneous-0.2.0.beta9 lib/spontaneous/field/markdown.rb
spontaneous-0.2.0.beta8 lib/spontaneous/field/markdown.rb
spontaneous-0.2.0.beta7 lib/spontaneous/field/markdown.rb
spontaneous-0.2.0.beta6 lib/spontaneous/field/markdown.rb
spontaneous-0.2.0.beta5 lib/spontaneous/field/markdown.rb