Class: Redmine::WikiFormatting::Textile::Formatter
- Includes:
- ActionView::Helpers::TagHelper, LinksHelper, SectionHelper
- 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
-
#initialize(*args) ⇒ Formatter
constructor
A new instance of Formatter.
- #to_html(*rules) ⇒ Object
Methods included from SectionHelper
Methods included from LinksHelper
#auto_link!, #auto_mailto!, #restore_redmine_links
Methods included from Helpers::URL
#uri_with_link_safe_scheme?, #uri_with_safe_scheme?
Methods included from StringArrayDiff::Diffable
#diff, #patch, #replacenextlarger, #reverse_hash
Methods included from CoreExt::String::Inflections
Methods included from CoreExt::String::Conversions
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
47 48 49 50 51 52 53 54 55 56 57 58 59 60 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 |
# File 'lib/redmine/wiki_formatting/textile/formatter.rb', line 47 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](.*?)$)|.*)/mo).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 |
#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 |