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

Context options:

:project_wiki (required) - Current project wiki.

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

%r{\[\[(.+?)\]\]}.freeze
ALLOWED_IMAGE_EXTENSIONS =

Pattern to match allowed image extensions

%r{.+(jpg|png|gif|svg|bmp)\z}i.freeze

Instance Method Summary collapse

Instance Method Details

#callObject


59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/banzai/filter/gollum_tags_filter.rb', line 59

def call
  search_text_nodes(doc).each do |node|
    # A Gollum ToC tag is `[[_TOC_]]`, but due to MarkdownFilter running
    # before this one, it will be converted into `[[<em>TOC</em>]]`, so it
    # needs special-case handling
    if toc_tag?(node)
      process_toc_tag(node)
    else
      content = node.content

      next unless content =~ TAGS_PATTERN

      html = process_tag($1)

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

  doc
end