Class: Asciidoctor::Rouge::CalloutsSubstitutor
- Inherits:
-
Object
- Object
- Asciidoctor::Rouge::CalloutsSubstitutor
- Defined in:
- lib/asciidoctor/rouge/callouts_substitutor.rb
Overview
A substitutor for processing callouts inside a source listing block.
Instance Attribute Summary collapse
Class Method Summary collapse
-
.create(node) ⇒ CalloutsSubstitutor
A callouts substitutor for the given node.
Instance Method Summary collapse
-
#convert_line(line_num) ⇒ String
Converts the extracted callout markers for the specified line.
-
#extract(text) ⇒ String
Extracts and stashes callout markers from the given text for reinsertion after processing.
Instance Attribute Details
#callouts ⇒ Hash<Integer, Array<Integer>> (readonly)
13 14 15 |
# File 'lib/asciidoctor/rouge/callouts_substitutor.rb', line 13 def callouts @callouts end |
Class Method Details
.create(node) ⇒ CalloutsSubstitutor
Returns a callouts substitutor for the given node.
17 18 19 |
# File 'lib/asciidoctor/rouge/callouts_substitutor.rb', line 17 def self.create(node) new(node) end |
Instance Method Details
#convert_line(line_num) ⇒ String
Converts the extracted callout markers for the specified line.
51 52 53 54 55 56 57 |
# File 'lib/asciidoctor/rouge/callouts_substitutor.rb', line 51 def convert_line(line_num) return '' unless @callouts.key? line_num @callouts[line_num] .map { |num| convert_callout(num) } .join(' ') end |
#extract(text) ⇒ String
Extracts and stashes callout markers from the given text for reinsertion after processing.
This should be used prior passing the source to a code highlighter.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/asciidoctor/rouge/callouts_substitutor.rb', line 28 def extract(text) escape_char = ::Asciidoctor::Substitutors::RS @callouts.clear text.each_line.with_index(1).map { |line, ln| line.gsub(@callout_rx) do match = $LAST_MATCH_INFO if match[1] == escape_char # We have to use sub since we aren't sure it's the first char. match[0].sub(escape_char, '') else (@callouts[ln] ||= []) << match[3].to_i nil end end }.join end |