Sha256: 03015fb86355f072e3cde35369540cc21b6376ab8d6c69704622d44a58bebc01

Contents?: true

Size: 1.57 KB

Versions: 40

Compression:

Stored size: 1.57 KB

Contents

module Slideshow
  module TextileEngines

  def redcloth_java_fix_escape_nonascii( txt )
    txt.chars.map{ |x| x.size > 1 ? "&##{x.unpack("U*")};" : x }.join
  end

  def redcloth_java_fix_escape_nonascii_exclude_pre( txt )

    buf  = ""
    from = 0
 
    while (pos = txt.index( /<pre.*?>.*?<\/pre>/m, from ))
      # add text before pre block escaped
      buf << redcloth_java_fix_escape_nonascii( txt[ from, pos-from] )
     
      # add pre block unescaped (otherwise html entities get escaped twice)
      from = Regexp.last_match.end(0)
      buf << txt[pos, from-pos]
    end
    buf << redcloth_java_fix_escape_nonascii( txt[from, txt.length-from] )
   
    buf
  end 


  def textile_to_html( content )    
    puts "  Converting Textile-text (#{content.length} bytes) to HTML..."
    
    # JRuby workaround for RedCloth 4 multi-byte character bug
    #  see http://jgarber.lighthouseapp.com/projects/13054/tickets/149-redcloth-4-doesnt-support-multi-bytes-content
    # basically convert non-ascii chars (>127) to html entities
    
    if RedCloth::EXTENSION_LANGUAGE == "Java"
      puts "  Patching RedCloth for Java; converting non-Ascii/multi-byte chars to HTML-entities..." 
      content = redcloth_java_fix_escape_nonascii_exclude_pre( content )
    end
    
    # turn off hard line breaks
    # turn off span caps (see http://rubybook.ca/2008/08/16/redcloth)
    red = RedCloth.new( content, [:no_span_caps] )
    red.hard_breaks = false
    content = red.to_html
  end

end   # module TextileEngines
end # module Slideshow

class Slideshow::Gen
  include Slideshow::TextileEngines
end

Version data entries

40 entries across 40 versions & 1 rubygems

Version Path
slideshow-2.2.0 lib/slideshow/markup/textile.rb
slideshow-2.1.0 lib/slideshow/markup/textile.rb
slideshow-2.0.1 lib/slideshow/markup/textile.rb
slideshow-2.0.0 lib/slideshow/markup/textile.rb
slideshow-1.2.5 lib/slideshow/markup/textile.rb
slideshow-1.2.4 lib/slideshow/markup/textile.rb
slideshow-1.2.3 lib/slideshow/markup/textile.rb
slideshow-1.2.2 lib/slideshow/markup/textile.rb
slideshow-1.2.1 lib/slideshow/markup/textile.rb
slideshow-1.2.0 lib/slideshow/markup/textile.rb
slideshow-1.2.0.beta5 lib/slideshow/markup/textile.rb
slideshow-1.2.0.beta4 lib/slideshow/markup/textile.rb
slideshow-1.2.0.beta3 lib/slideshow/markup/textile.rb
slideshow-1.2.0.beta2 lib/slideshow/markup/textile.rb
slideshow-1.2.0.beta1 lib/slideshow/markup/textile.rb
slideshow-1.1.0 lib/slideshow/markup/textile.rb
slideshow-1.1.0.beta8 lib/slideshow/markup/textile.rb
slideshow-1.1.0.beta7 lib/slideshow/markup/textile.rb
slideshow-1.1.0.beta6 lib/slideshow/markup/textile.rb
slideshow-1.1.0.beta5 lib/slideshow/markup/textile.rb