Module: RedQuilt::FootnoteDefinition
- Defined in:
- lib/red_quilt/footnote_definition.rb
Overview
GitHub-style footnote definitions: ‘[^label]: content`. `match` handles the opener line; `Parser` (a cached BlockParser collaborator, like List::Parser) collects the optionally-indented, multi-paragraph continuation and parses it into a FOOTNOTE_DEFINITION node. Label normalization is shared with link reference definitions.
NOTE: ReferenceDefinition’s REF_DEF_RE also matches ‘[^label]:` (treating `^label` as an ordinary label), so the block dispatch must try this matcher BEFORE the reference-definition branch when footnotes are on.
Defined Under Namespace
Classes: Parser
Constant Summary collapse
- RE =
Up to 3 spaces of indent, then ‘[^label]:`. The label is non-empty and contains no whitespace or `]` (GFM rule).
/\A {0,3}\[\^([^\]\s]+)\]:(.*)\z/m
Class Method Summary collapse
-
.match(text) ⇒ Object
Returns { label:, content_start:, content: } for a footnote-definition opener, or nil.
Class Method Details
.match(text) ⇒ Object
Returns { label:, content_start:, content: } for a footnote-definition opener, or nil. ‘content_start` is the byte offset (within `text`) where the content begins, after `]:` and an optional single separating space/tab; `content` is that text (possibly empty).
24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/red_quilt/footnote_definition.rb', line 24 def match(text) m = RE.match(text) return nil unless m rest = m[2] lead = rest.match?(/\A[ \t]/) ? 1 : 0 { label: m[1], content_start: text.bytesize - rest.bytesize + lead, content: lead.zero? ? rest : rest[lead..], } end |