Sha256: d26cc8ce60214b58b5e367572bc4adfa2216123d37bb4ee06a8436d2ea5b8fd1
Contents?: true
Size: 939 Bytes
Versions: 1
Compression:
Stored size: 939 Bytes
Contents
# encoding: UTF-8 require 'kramdown' module Spontaneous module FieldTypes class MarkdownField < Field def outputs [:html] end def generate_html(input) input.to_html end def preprocess(input) # 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 end MarkdownField.register(:markdown, :text, :richtext) end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
spontaneous-0.1.0.alpha1 | lib/spontaneous/field_types/markdown_field.rb |