Class: HTMLPipeline::HighlightFilter
- Inherits:
-
NodeFilter
- Object
- NodeFilter
- HTMLPipeline::HighlightFilter
- Defined in:
- lib/html/pipeline/highlight/filter.rb
Constant Summary collapse
- DEFAULT_IGNORED_ANCESTOR_TAGS =
%w[pre code a style script].freeze
- DEFAULT_CLASS_NAME =
'highlight'
Instance Method Summary collapse
- #apply_filter(content) ⇒ Object
- #handle_text_chunk(text) ⇒ Object
- #selector ⇒ Object
- #validate ⇒ Object
Instance Method Details
#apply_filter(content) ⇒ Object
16 17 18 19 20 21 22 23 24 |
# File 'lib/html/pipeline/highlight/filter.rb', line 16 def apply_filter(content) content.gsub(context[:highlight_pattern]) do |text| if converter converter.call(Regexp.last_match) else %(<span class="#{class_name}">#{ERB::Util.html_escape(text)}</span>) end end end |
#handle_text_chunk(text) ⇒ Object
12 13 14 |
# File 'lib/html/pipeline/highlight/filter.rb', line 12 def handle_text_chunk(text) text.replace(apply_filter(text.to_s), as: :html) end |
#selector ⇒ Object
8 9 10 |
# File 'lib/html/pipeline/highlight/filter.rb', line 8 def selector Selma::Selector.new(match_text_within: "*", ignore_text_within: DEFAULT_IGNORED_ANCESTOR_TAGS) end |
#validate ⇒ Object
26 27 28 |
# File 'lib/html/pipeline/highlight/filter.rb', line 26 def validate needs(:highlight_pattern) end |