Class: Gollum::Filter::Tags
- Inherits:
-
Gollum::Filter
- Object
- Gollum::Filter
- Gollum::Filter::Tags
- Defined in:
- lib/gollum-lib/filter/tags.rb
Overview
Render all tags (things in double-square-brackets). This one’s a biggie.
Constant Summary
Constants inherited from Gollum::Filter
Instance Attribute Summary
Attributes inherited from Gollum::Filter
Instance Method Summary collapse
-
#extract(data) ⇒ Object
Extract all tags into the tagmap and replace with placeholders.
-
#process(rendered_data) ⇒ Object
Process all text nodes from the doc and replace the placeholders with the final markup.
Methods inherited from Gollum::Filter
Methods included from Helpers
#path_to_link_text, #trim_leading_slashes
Constructor Details
This class inherits a constructor from Gollum::Filter
Instance Method Details
#extract(data) ⇒ Object
Extract all tags into the tagmap and replace with placeholders.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/gollum-lib/filter/tags.rb', line 6 def extract(data) data.gsub!(/(.?)\[\[(.+?)\]\]([^\[]?)/) do if Regexp.last_match[1] == "'" && Regexp.last_match[3] != "'" "[[#{Regexp.last_match[2]}]]#{Regexp.last_match[3]}" elsif Regexp.last_match[2].include?('][') if Regexp.last_match[2][0..4] == 'file:' pre = Regexp.last_match[1] post = Regexp.last_match[3] parts = Regexp.last_match[2].split('][') parts[0][0..4] = "" link = "#{parts[1]}|#{parts[0].sub(/\.org/, '')}" id = register_tag(link) "#{pre}#{id}#{post}" else Regexp.last_match[0] end else id = register_tag(Regexp.last_match[2]) "#{Regexp.last_match[1]}#{id}#{Regexp.last_match[3]}" end end data end |
#process(rendered_data) ⇒ Object
Process all text nodes from the doc and replace the placeholders with the final markup.
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/gollum-lib/filter/tags.rb', line 32 def process(rendered_data) doc = Nokogiri::HTML::DocumentFragment.parse(rendered_data) doc.traverse do |node| if node.text? then content = node.content content.gsub!(%r{#{open_pattern}[a-f0-9]+#{close_pattern}}) do |id| if (tag = @map[id]) then if is_preformatted?(node) then "[[#{tag}]]" else process_tag(tag).gsub('%2f', '/') end end end node.replace(content) if content != node.content end end doc.to_html end |