Module: RubyBBCode

Includes:
Tags
Defined in:
lib/ruby-bbcode.rb,
lib/tags/tags.rb,
lib/ruby-bbcode/bbtree.rb,
lib/ruby-bbcode/version.rb,
lib/ruby-bbcode/tag_info.rb,
lib/ruby-bbcode/tag_node.rb,
lib/ruby-bbcode/tag_sifter.rb,
lib/ruby-bbcode/tag_collection.rb

Overview

RubyBBCode adds support for BBCode to Ruby. The BBCode is parsed by a parser before converted to HTML, allowing to convert nested BBCode tags in strings to their correct HTML equivalent. THe used parser also checks whether the BBCode is valid and gives errors for incorrect BBCode texts.

Defined Under Namespace

Modules: Tags Classes: BBTree, TagCollection, TagInfo, TagNode, TagSifter

Constant Summary collapse

VERSION =

Version of RubyBBCode

Follows semantic versioning: semver.org/

"1.0.0"

Class Method Summary collapse

Methods included from Tags

tag_list

Class Method Details

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

This method converts the given text (with BBCode tags) into a HTML representation The escape_html parameter (default: true) escapes HTML tags that were present in the given text and therefore blocking (mallicious) HTML in the original text The additional_tags parameter is used to add additional BBCode tags that should be accepted The method paramter determines whether the tags parameter needs to be used to blacklist (when set to :disable) or whitelist (when not set to :disable) the list of BBCode tags



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/ruby-bbcode.rb', line 18

def self.to_html(text, escape_html = true, additional_tags = {}, method = :disable, *tags)
  text = text.clone

  use_tags = determine_applicable_tags(additional_tags, method, *tags)

  @tag_sifter = TagSifter.new(text, use_tags, escape_html)

  @tag_sifter.process_text

  if @tag_sifter.invalid?
    raise @tag_sifter.errors.join(', ')   # We cannot convert to HTML if the BBCode is not valid!
  else
    @tag_sifter.bbtree.to_html(use_tags)
  end

end

.validity_check(text, additional_tags = {}) ⇒ Object

Returns true when valid, else returns array with error(s)



36
37
38
39
40
41
42
# File 'lib/ruby-bbcode.rb', line 36

def self.validity_check(text, additional_tags = {})
  @tag_sifter = TagSifter.new(text, @@tags.merge(additional_tags))

  @tag_sifter.process_text
  return @tag_sifter.errors if @tag_sifter.invalid?
  true
end