Class: RedQuilt::Inline::Builder

Inherits:
Object
  • Object
show all
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. process_emphasis — CommonMark spec 6.2 algorithm pairs up
   delimiter stack entries into EMPHASIS / STRONG nodes.

Defined Under Namespace

Classes: Bracket, Delimiter

Constant Summary collapse

SAFE_SCHEMES =
%w[http https mailto ftp tel ssh].freeze
%w[javascript vbscript data].freeze

Instance Method Summary collapse

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.



39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/red_quilt/inline/builder.rb', line 39

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)
end

Instance Method Details

#build(parent_id, tokens) ⇒ Object



54
55
56
57
58
59
60
61
62
# File 'lib/red_quilt/inline/builder.rb', line 54

def build(parent_id, tokens)
  @parent_id = parent_id
  @tokens = tokens
  @delimiter_stack = []
  @bracket_stack = []
  @provisional_nodes = {}
  linear_pass
  process_emphasis(@delimiter_stack)
end