class Rwiki::Utils::TextileHelper
Constants
- CODE_REGEXP
RedCloth for extracting code blocks
- HEADER_REGEXP
Regexp for extracting an article headers
Attributes
content[R]
processed_content[R]
Public Class Methods
new(content)
click to toggle source
# File lib/rwiki/utils/textile_helper.rb, line 14 def initialize(content) @content = content.clone @processed_content = content.clone end
Public Instance Methods
parsed_content()
click to toggle source
# File lib/rwiki/utils/textile_helper.rb, line 19 def parsed_content process_coderay! process_toc! RedCloth.new(processed_content).to_html end
parsed_toc()
click to toggle source
# File lib/rwiki/utils/textile_helper.rb, line 26 def parsed_toc RedCloth.new(textile_toc).to_html end
textile_toc()
click to toggle source
# File lib/rwiki/utils/textile_helper.rb, line 30 def textile_toc toc_items = [] content.gsub(HEADER_REGEXP) do number = $~[:number].to_i name = $~[:name].strip anchor = sanitize_anchor_name(name) toc_items << ('#' * number) + %Q{ "#{name}":##{anchor}} end toc_items.join("\n") end
Protected Instance Methods
process_coderay!()
click to toggle source
Execute syntax highlight for the <code> blocks
# File lib/rwiki/utils/textile_helper.rb, line 46 def process_coderay! processed_content.gsub!(CODE_REGEXP) do code = ($~[:code] || '').strip lang = $~[:lang] "<notextile>#{CodeRay.scan(code, lang).html.div(:css => :class)}</notextile>" end end
process_toc!()
click to toggle source
Add anchors to the article headers
# File lib/rwiki/utils/textile_helper.rb, line 55 def process_toc! processed_content.gsub!(HEADER_REGEXP) do number = $~[:number].to_i name = $~[:name].strip %Q{\nh#{number}. <a name="#{sanitize_anchor_name(name)}">#{name}</a>} end end
sanitize_anchor_name(name)
click to toggle source
# File lib/rwiki/utils/textile_helper.rb, line 64 def sanitize_anchor_name(name) URI.escape name.gsub(/\s/, '-') end