Module: Slideshow::TextileEngines

Included in:
Gen
Defined in:
lib/slideshow/markup/textile.rb

Instance Method Summary collapse

Instance Method Details

#redcloth_java_fix_escape_nonascii(txt) ⇒ Object



4
5
6
# File 'lib/slideshow/markup/textile.rb', line 4

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

#redcloth_java_fix_escape_nonascii_exclude_pre(txt) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/slideshow/markup/textile.rb', line 8

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

#textile_to_html(content) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/slideshow/markup/textile.rb', line 27

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