Class: Coradoc::AsciiDoc::Transform::CalloutMerger
- Inherits:
-
Object
- Object
- Coradoc::AsciiDoc::Transform::CalloutMerger
- Defined in:
- lib/coradoc/asciidoc/transform/callout_merger.rb
Overview
Post-processing pass that merges AsciiDoc callout annotation paragraphs into the verbatim block they annotate.
AsciiDoc callouts look like:
[source,ruby]
----
get '/hi' do <1>
----
<1> Returns hello world
The parser emits the source block and the annotation as two independent children. The CoreModel representation should attach the annotation to the block as a typed Callout, so downstream serializers can render them appropriately for each format.
Single responsibility: take a flat list of transformed CoreModel children, return a flat list with ‘<N>` paragraphs adjacent to a SourceBlock / ListingBlock folded into that block’s ‘callouts`. Anything else is passed through untouched.
Constant Summary collapse
- ANNOTATION_LINE =
/<(\d+)>\s*(.*?)\s*\z/- ANNOTATION_SPLIT =
/(?=<\d+>)/
Class Method Summary collapse
Instance Method Summary collapse
-
#merge(children) ⇒ Object
Walks the input children left-to-right.
Class Method Details
.call(children) ⇒ Object
31 32 33 |
# File 'lib/coradoc/asciidoc/transform/callout_merger.rb', line 31 def call(children) new.merge(Array(children)) end |
Instance Method Details
#merge(children) ⇒ Object
Walks the input children left-to-right. When a paragraph whose content is composed entirely of ‘<N> text` lines follows a verbatim block (SourceBlock or ListingBlock), each `<N>` line becomes a Callout attached to that block instead of a separate paragraph.
Annotations that do not follow a verbatim block are preserved verbatim — they may be legitimate prose.
44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/coradoc/asciidoc/transform/callout_merger.rb', line 44 def merge(children) children.each.with_object([]) do |child, result| annotations = extract_annotations(child) target = annotations && preceding_verbatim_block(result) if target target.callouts.concat(annotations) else result << child end end end |