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

#setup_textile_engineObject



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

def setup_textile_engine
  return if @textile_engine_setup
  logger.debug 'require redcloth  -- load textile library'
  require 'redcloth'          # default textile library
  @textile_engine_setup = true
rescue LoadError
  puts "You're missing a library required for Textile to Hypertext conversion. Please run:"
  puts "   $ gem install RedCloth"
  #  check: raise exception instead of exit e.g
  #  raise FatalException.new( 'Missing library dependency: RedCloth' )
  exit 1
end

#textile_to_html(content) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/slideshow/markup/textile.rb', line 41

def textile_to_html( content )
  
  setup_textile_engine()   # optinal lib; extra; load only textile lib if used (soft dependency)
  
  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