Module: BBRuby

Defined in:
lib/bb-ruby/bb-ruby.rb

Overview

overwrite process_tags method, because original one doesn’t work with nested tags(like citation)‘ also mark returned string as html_safe

Class Method Summary collapse

Class Method Details

.process_tags(text, tags_alternative_definition = {}, escape_html = true, method = :disable, *tags) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/bb-ruby/bb-ruby.rb', line 6

def process_tags(text, tags_alternative_definition={}, escape_html=true, method=:disable, *tags)
  text = text.dup

  # escape "<, >, &" to remove any html
  if escape_html
    text.gsub!('&', '&amp;')
    text.gsub!('<', '&lt;')
    text.gsub!('>', '&gt;')
  end

  tags_definition = @@tags.merge(tags_alternative_definition)

  # parse bbcode tags
  case method
    when :enable
      tags_definition.each_value do |t|
        if tags.include?(t[4])
          while text.gsub!(t[0], t[1]) do
            #nothing
          end
        end
      end
    when :disable
      # this works nicely because the default is disable and the default set of tags is [] (so none disabled) :)
      tags_definition.each_value do |t|
        unless tags.include?(t[4])
          while text.gsub!(t[0], t[1]) do
            #nothing
          end
        end
      end
  end

  text
end

.to_html_with_formatting_with_html_safe(text, tags_alternative_definition = {}, escape_html = true, method = :disable, *tags) ⇒ Object



49
50
51
52
# File 'lib/bb-ruby/bb-ruby.rb', line 49

def to_html_with_formatting_with_html_safe(text, tags_alternative_definition={}, escape_html=true, method=:disable, *tags)
  text = to_html_with_formatting_without_html_safe(text, tags_alternative_definition, escape_html, method, *tags)
  text.respond_to?(:html_safe) ? text.html_safe : text
end

.to_html_with_html_safe(text, tags_alternative_definition = {}, escape_html = true, method = :disable, *tags) ⇒ Object



42
43
44
45
# File 'lib/bb-ruby/bb-ruby.rb', line 42

def to_html_with_html_safe(text, tags_alternative_definition={}, escape_html=true, method=:disable, *tags)
  text = to_html_without_html_safe(text, tags_alternative_definition, escape_html, method, *tags)
  text.respond_to?(:html_safe) ? text.html_safe : text
end