Class: Redmine::WikiFormatting::Textile::Formatter
- Includes:
- ActionView::Helpers::TagHelper, LinksHelper
- Defined in:
- lib/redmine/wiki_formatting/textile/formatter.rb
Constant Summary collapse
- RULES =
auto_link rule after textile rules so that it doesn't break !image_url! tags
[:textile, :block_markdown_rule, :inline_auto_link, :inline_auto_mailto, :inline_restore_redmine_links]
Constants included from LinksHelper
Constants inherited from RedCloth3
RedCloth3::DEFAULT_RULES, RedCloth3::VERSION
Instance Attribute Summary
Attributes inherited from RedCloth3
#filter_html, #filter_styles, #hard_breaks, #lite_mode, #no_span_caps, #rules
Instance Method Summary collapse
- #extract_sections(index) ⇒ Object
- #get_section(index) ⇒ Object
-
#initialize(*args) ⇒ Formatter
constructor
A new instance of Formatter.
- #to_html(*rules) ⇒ Object
- #update_section(index, update, hash = nil) ⇒ Object
Methods included from LinksHelper
#auto_link!, #auto_mailto!, #restore_redmine_links
Methods included from Helpers::URL
Methods included from Diffable
#diff, #patch, #replacenextlarger, #reverse_hash
Constructor Details
#initialize(*args) ⇒ Formatter
Returns a new instance of Formatter
35 36 37 38 39 40 |
# File 'lib/redmine/wiki_formatting/textile/formatter.rb', line 35 def initialize(*args) super self.hard_breaks=true self.no_span_caps=true self.filter_styles=false end |
Instance Method Details
#extract_sections(index) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/redmine/wiki_formatting/textile/formatter.rb', line 62 def extract_sections(index) @pre_list = [] text = self.dup text, false, false before = '' s = '' after = '' i = 0 l = 1 started = false ended = false text.scan(/(((?:.*?)(\A|\r?\n\s*\r?\n))(h(\d+)(#{A}#{C})\.(?::(\S+))?[ \t](.*?)$)|.*)/m).each do |all, content, lf, heading, level| if heading.nil? if ended after << all elsif started s << all else before << all end break end i += 1 if ended after << all elsif i == index l = level.to_i before << content s << heading started = true elsif i > index s << content if level.to_i > l s << heading else after << heading ended = true end else before << all end end sections = [before.strip, s.strip, after.strip] sections.each {|section| section} sections end |
#get_section(index) ⇒ Object
47 48 49 50 51 |
# File 'lib/redmine/wiki_formatting/textile/formatter.rb', line 47 def get_section(index) section = extract_sections(index)[1] hash = Digest::MD5.hexdigest(section) return section, hash end |
#to_html(*rules) ⇒ Object
42 43 44 45 |
# File 'lib/redmine/wiki_formatting/textile/formatter.rb', line 42 def to_html(*rules) @toc = [] super(*RULES).to_s end |
#update_section(index, update, hash = nil) ⇒ Object
53 54 55 56 57 58 59 60 |
# File 'lib/redmine/wiki_formatting/textile/formatter.rb', line 53 def update_section(index, update, hash=nil) t = extract_sections(index) if hash.present? && hash != Digest::MD5.hexdigest(t[1]) raise Redmine::WikiFormatting::StaleSectionError end t[1] = update unless t[1].blank? t.reject(&:blank?).join "\n\n" end |