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]
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
Methods included from Helpers::URL
Methods inherited from String
Methods included from CoreExtensions::String::Inflections
Methods included from CoreExtensions::String::Conversions
Methods included from Diffable
#diff, #patch, #replacenextlarger, #reverse_hash
Constructor Details
#initialize(*args) ⇒ Formatter
Returns a new instance of Formatter
34 35 36 37 38 39 |
# File 'lib/redmine/wiki_formatting/textile/formatter.rb', line 34 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
61 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 |
# File 'lib/redmine/wiki_formatting/textile/formatter.rb', line 61 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
46 47 48 49 50 |
# File 'lib/redmine/wiki_formatting/textile/formatter.rb', line 46 def get_section(index) section = extract_sections(index)[1] hash = Digest::MD5.hexdigest(section) return section, hash end |
#to_html(*rules) ⇒ Object
41 42 43 44 |
# File 'lib/redmine/wiki_formatting/textile/formatter.rb', line 41 def to_html(*rules) @toc = [] super(*RULES).to_s end |
#update_section(index, update, hash = nil) ⇒ Object
52 53 54 55 56 57 58 59 |
# File 'lib/redmine/wiki_formatting/textile/formatter.rb', line 52 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 |