Class: Gollum::Filter::CriticMarkup
- Inherits:
-
Gollum::Filter
- Object
- Gollum::Filter
- Gollum::Filter::CriticMarkup
- Defined in:
- lib/gollum-lib/filter/critic_markup.rb
Overview
CriticMarkup
Render CriticMarkup
Constant Summary collapse
- ADDITION_PATTERN =
Patterns inspired by github.com/DivineDominion/criticmarkup.tmbundle/blob/master/Syntaxes/criticmarkup.tmLanguage All patterns use multiline matching (m flag) Logic inspired by github.com/CriticMarkup/CriticMarkup-toolkit/blob/master/CLI/criticParser_CLI.py
%r|{\+\+(?<content>.*?)\+\+[ \t]*(\[(.*?)\])?[ \t]*\}|m
- DELETION_PATTERN =
%r|{--(?<content>.*?)--[ \t]*(\[(.*?)\])?[ \t]*\}|m
- SUBSTITUTION_PATTERN =
%r|{~~(?<oldcontent>.*?)~>(?<newcontent>.*?)~~}|m
- HIGHLIGHT_PATTERN =
%r|{\=\=(?<content>.*?)[ \t]*(\[(.*?)\])?[ \t]*\=\=\}{>>(?<comment>.*?)<<}|m
- COMMENT_PATTERN =
%r|{>>(?<content>.*?)<<}|m
Constants inherited from Gollum::Filter
Instance Attribute Summary
Attributes inherited from Gollum::Filter
Instance Method Summary collapse
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
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/gollum-lib/filter/critic_markup.rb', line 19 def extract(data) data.gsub! ADDITION_PATTERN do content = $~[:content] placeholder = generate_placeholder("#{content}#{@map.size}") # Is there a new paragraph followed by new text if content.start_with?("\n\n") && content != "\n\n" html = "\n\n<ins class='critic break'> </ins>\n\n<ins>#{content.gsub('\n', ' ')}</ins>" # Is the addition just a single new paragraph elsif content == "\n\n" html = "\n\n<ins class='critic break'> </ins>\n\n" # Is it added text followed by a new paragraph? elsif content.end_with?("\n\n") && content != "\n\n" html = "<ins>#{content.gsub('\n', ' ')}</ins>\n\n<ins class='critic break'> </ins>\n\n" else html = "<ins>#{content.gsub('\n', ' ')}</ins>" end @map[placeholder] = html placeholder end data.gsub! DELETION_PATTERN do content = $~[:content] placeholder = generate_placeholder("#{content}#{@map.size}") if content == "\n\n" html = "<del> </del>" else html = "<del>#{content.gsub('\n\n', ' ')}</del>" end @map[placeholder] = html placeholder end data.gsub! SUBSTITUTION_PATTERN do oldcontent = $~[:oldcontent] newcontent = $~[:newcontent] placeholder = generate_placeholder("#{oldcontent}#{newcontent}#{@map.size}") html = "<del>#{oldcontent}</del><ins>#{newcontent}</ins>" @map[placeholder] = html placeholder end data.gsub! HIGHLIGHT_PATTERN do content = $~[:content] comment = $~[:comment] placeholder = generate_placeholder("#{content}#{@map.size}") html = "<mark>#{content}</mark><span class='critic comment'>#{comment}</span>" @map[placeholder] = html placeholder end data.gsub! COMMENT_PATTERN do content = $~[:content] placeholder = generate_placeholder("#{content}#{@map.size}") html = "<span class='critic comment'>#{content}</span>" @map[placeholder] = html placeholder end data end |
#process(data) ⇒ Object
80 81 82 83 84 85 |
# File 'lib/gollum-lib/filter/critic_markup.rb', line 80 def process(data) data.gsub! process_pattern do @map[$~[:placeholder]] end data end |