Class: Banzai::Filter::GollumTagsFilter

Inherits:
HTML::Pipeline::Filter
  • Object
show all
Includes:
ActionView::Helpers::TagHelper
Defined in:
lib/banzai/filter/gollum_tags_filter.rb

Overview

HTML Filter for parsing Gollum's tags in HTML. It's only parses the following tags:

Based on Gollum::Filter::Tags

Note: the table of contents tag is now handled by TableOfContentsTagFilter

Context options:

:wiki [Wiki] (required) - Current wiki instance.

Constant Summary collapse

TAGS_PATTERN =

Pattern to match tags content that should be parsed in HTML.

Gollum's tags have been made to resemble the tags of other markups, especially MediaWiki. The basic syntax is:

[tag]

Some tags will accept attributes which are separated by pipe symbols.Some attributes must precede the tag and some must follow it:

[prefix-attribute|tag]
[tag|suffix-attribute]

See github.com/gollum/gollum/wiki

Rubular: rubular.com/r/7dQnE5CUCH

/\[\[(.+?)\]\]/.freeze
ALLOWED_IMAGE_EXTENSIONS =

Pattern to match allowed image extensions

/.+(jpg|png|gif|svg|bmp)\z/i.freeze
IGNORED_ANCESTOR_TAGS =

Do not perform linking inside these tags.

%w(pre code tt).to_set

Instance Method Summary collapse

Instance Method Details

#callObject


62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/banzai/filter/gollum_tags_filter.rb', line 62

def call
  doc.search(".//text()").each do |node|
    next if has_ancestor?(node, IGNORED_ANCESTOR_TAGS)
    next unless node.content =~ TAGS_PATTERN

    html = process_tag(Regexp.last_match(1))

    node.replace(html) if html && html != node.content
  end

  doc
end