Module: RedQuilt::CodeBlock
- Defined in:
- lib/red_quilt/code_block.rb
Overview
Fenced and indented code blocks (CommonMark 4.4 / 4.5). The module functions detect a code-block start; the nested Parser builds the arena node, mirroring the List / Blockquote split (detection used by the block dispatch, construction by a cached collaborator).
Defined Under Namespace
Classes: Parser
Class Method Summary collapse
-
.fenced_start(text) ⇒ Object
Detects a fenced code opener.
-
.indented_line?(text) ⇒ Boolean
True when ‘text` is an indented code line: 4+ columns of leading whitespace (tabs expand to a 4-column tab stop).
Class Method Details
.fenced_start(text) ⇒ Object
Detects a fenced code opener. Returns a Hash describing the fence ({ char:, count:, info:, indent: }) or nil.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/red_quilt/code_block.rb', line 13 def fenced_start(text) match = /\A( {0,3})(`{3,}|~{3,})[ \t]*(.*?)\s*\z/.match(text) return unless match info = match[3] # CommonMark: a backtick-style fence cannot have backticks in its # info string (they'd be ambiguous with the fence itself). return if match[2].start_with?("`") && info.include?("`") { char: match[2][0], count: match[2].length, info: ReferenceDefinition.unescape_text(info), indent: match[1].length, } end |
.indented_line?(text) ⇒ Boolean
True when ‘text` is an indented code line: 4+ columns of leading whitespace (tabs expand to a 4-column tab stop).
32 33 34 |
# File 'lib/red_quilt/code_block.rb', line 32 def indented_line?(text) Indentation.leading_columns(text) >= 4 end |