Class: RedQuilt::Inline::Builder
- Inherits:
-
Object
- Object
- RedQuilt::Inline::Builder
- Defined in:
- lib/red_quilt/inline/builder.rb
Overview
Consumes a token stream produced by Lexer and adds inline nodes to the arena under parent_id.
Processing happens in two phases:
1. linear_pass — code spans, brackets (link/image), autolinks,
HTML, simple inlines. Emphasis delimiter runs are added as
provisional TEXT nodes and pushed onto a delimiter stack.
2. EmphasisResolver#resolve — CommonMark spec 6.2 algorithm pairs
up delimiter stack entries into EMPHASIS / STRONG nodes
(delegated to Inline::EmphasisResolver).
Defined Under Namespace
Classes: Bracket
Instance Method Summary collapse
- #build(parent_id, tokens) ⇒ Object
-
#initialize(arena, source, references, track_source: true, diagnostics: nil, footnotes: nil) ⇒ Builder
constructor
track_source: when true, arena nodes carry the byte ranges supplied by the lexer.
Constructor Details
#initialize(arena, source, references, track_source: true, diagnostics: nil, footnotes: nil) ⇒ Builder
track_source: when true, arena nodes carry the byte ranges supplied by the lexer. When false (used for inputs whose source has been materialized into a separate string, e.g. transformed blockquote lines), source_start/source_len are not recorded; in that mode every text node carries its content in str1 so Arena#text still works.
diagnostics: an optional Array the builder appends warnings to (unsafe URL schemes, missing references, …). The caller — usually InlinePass — is expected to forward Document#diagnostics here.
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/red_quilt/inline/builder.rb', line 27 def initialize(arena, source, references, track_source: true, diagnostics: nil, footnotes: nil) @arena = arena @source = source # Binary view of the source for String#byteindex hot paths: # byteindex on a UTF-8 string raises when the byte offset falls # inside a multibyte sequence; the binary view treats every byte # as its own character. @source_b = source.b @references = references @track_source = track_source @diagnostics = diagnostics @footnotes = footnotes @link_scanner = LinkScanner.new(source) @emphasis = EmphasisResolver.new(arena, track_source: track_source) end |
Instance Method Details
#build(parent_id, tokens) ⇒ Object
43 44 45 46 47 48 49 50 51 |
# File 'lib/red_quilt/inline/builder.rb', line 43 def build(parent_id, tokens) @parent_id = parent_id @tokens = tokens @delimiter_stack = [] @bracket_stack = [] @provisional_nodes = {} linear_pass @emphasis.resolve(@delimiter_stack, @provisional_nodes) end |