Module: Coradoc::AsciiDoc::Parser::Block
- Defined in:
- lib/coradoc/asciidoc/parser/block.rb
Instance Method Summary collapse
-
#block(n_deep = 3) ⇒ Object
AsciiDoc Block Delimiter Patterns: - “4+” means 4 or more identical characters - “2+” means 2 or more identical characters.
- #block_content(n_deep = 3) ⇒ Object
-
#block_delimiter ⇒ Object
Block delimiter: 4+ identical characters (or 2 for open block) Used by paragraph.rb to reject lines that look like block delimiters.
-
#block_style(n_deep = 3, delimiter = '*', repeater = 4, type = nil, verbatim: false) ⇒ Object
Block style parser with variable delimiter length.
-
#block_style_exact(n_deep = 3, delimiter = '-', exact_chars = 2, type = nil) ⇒ Object
Block style parser with EXACT delimiter length (for open blocks) Open blocks use exactly 2 dashes and cannot nest within themselves.
- #block_title ⇒ Object
- #block_type(type) ⇒ Object
- #example_block(n_deep) ⇒ Object
-
#open_block(n_deep) ⇒ Object
Open block: exactly 2 dashes (cannot nest within itself).
- #pass_block(n_deep) ⇒ Object
- #quote_block(n_deep) ⇒ Object
- #sidebar_block(n_deep) ⇒ Object
- #source_block(n_deep) ⇒ Object
Instance Method Details
#block(n_deep = 3) ⇒ Object
AsciiDoc Block Delimiter Patterns:
-
“4+” means 4 or more identical characters
-
“2+” means 2 or more identical characters
Block types by delimiter character:
-
“=” (4+): Example block (====, =====, etc.)
-
“-” (4+): Source/listing block (—-, —–, etc.)
-
“-” (2): Open block (–)
-
“_” (4+): Quote block (__, _, etc.)
-
“*” (4+): Sidebar block (****, *****, etc.)
-
“+” (4+): Pass block (++++, +++++, etc.)
-
“.” (4+): Literal block (.…, .…., etc.)
Table delimiters:
-
“|===” defines table boundaries
-
“|” separates cells within the table
24 25 26 27 28 29 30 31 |
# File 'lib/coradoc/asciidoc/parser/block.rb', line 24 def block(n_deep = 3) (example_block(n_deep) | (n_deep) | source_block(n_deep) | quote_block(n_deep) | pass_block(n_deep) | open_block(n_deep)).as(:block) end |
#block_content(n_deep = 3) ⇒ Object
68 69 70 71 72 73 74 75 |
# File 'lib/coradoc/asciidoc/parser/block.rb', line 68 def block_content(n_deep = 3) c = block_image c |= block(n_deep - 1) if n_deep.positive? c |= list c |= text_line(false, unguarded: true) c |= empty_line.as(:line_break) c.repeat(1) end |
#block_delimiter ⇒ Object
Block delimiter: 4+ identical characters (or 2 for open block) Used by paragraph.rb to reject lines that look like block delimiters. NOTE: repeat(4,) means 4 or more (not exactly 4)
80 81 82 83 84 85 86 87 88 89 |
# File 'lib/coradoc/asciidoc/parser/block.rb', line 80 def block_delimiter line_start? >> ((str('*') | str('=') | str('_') | str('+') | str('-')).repeat(4) | # 4+ characters for most blocks str('-').repeat(2, 2)) >> # Exactly 2 for open block newline end |
#block_style(n_deep = 3, delimiter = '*', repeater = 4, type = nil, verbatim: false) ⇒ Object
Block style parser with variable delimiter length
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/coradoc/asciidoc/parser/block.rb', line 96 def block_style(n_deep = 3, delimiter = '*', repeater = 4, type = nil, verbatim: false) capture_key = :"delimit_#{delimiter}_#{n_deep}" current_delimiter = str(delimiter).repeat(repeater).capture(capture_key) closing_delimiter = dynamic do |_s, c| str(c.captures[capture_key].to_s.strip) end block_content_with_closing = dynamic do |_s, c| delim_str = c.captures[capture_key].to_s.strip closing_pattern = str(delim_str) >> newline content = block_image content |= block(n_deep - 1) if n_deep.positive? content |= list content |= text_line(false, unguarded: true, verbatim: verbatim) content |= empty_line.as(:line_break) (closing_pattern.absent? >> content).repeat(1) end block_header >> line_start? >> current_delimiter.as(:delimiter) >> newline >> if type == :pass (text_line(false, unguarded: true, verbatim: verbatim) | empty_line.as(:line_break)).repeat(1).as(:lines) else block_content_with_closing.as(:lines) end >> line_start? >> closing_delimiter >> newline end |
#block_style_exact(n_deep = 3, delimiter = '-', exact_chars = 2, type = nil) ⇒ Object
Block style parser with EXACT delimiter length (for open blocks) Open blocks use exactly 2 dashes and cannot nest within themselves
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
# File 'lib/coradoc/asciidoc/parser/block.rb', line 130 def block_style_exact(n_deep = 3, delimiter = '-', exact_chars = 2, type = nil) capture_key = :"delimit_#{delimiter}_exact_#{exact_chars}_#{n_deep}" current_delimiter = str(delimiter).repeat(exact_chars, exact_chars).capture(capture_key) closing_delimiter = dynamic do |_s, c| str(c.captures[capture_key].to_s.strip) end block_content_with_closing = dynamic do |_s, c| delim_str = c.captures[capture_key].to_s.strip closing_pattern = str(delim_str) >> newline content = block_image content |= block(n_deep - 1) if n_deep.positive? content |= list content |= text_line(false, unguarded: true) content |= empty_line.as(:line_break) (closing_pattern.absent? >> content).repeat(1) end block_header >> line_start? >> current_delimiter.as(:delimiter) >> newline >> if type == :pass (text_line(false, unguarded: true) | empty_line.as(:line_break)).repeat(1).as(:lines) else block_content_with_closing.as(:lines) end >> line_start? >> closing_delimiter >> newline end |
#block_title ⇒ Object
58 59 60 |
# File 'lib/coradoc/asciidoc/parser/block.rb', line 58 def block_title str('.') >> space.absent? >> text.as(:title) >> newline end |
#block_type(type) ⇒ Object
62 63 64 65 66 |
# File 'lib/coradoc/asciidoc/parser/block.rb', line 62 def block_type(type) (line_start? >> str('[') >> str('[').absent? >> str(type).as(:type) >> str(']')) >> newline # | end |
#example_block(n_deep) ⇒ Object
33 34 35 |
# File 'lib/coradoc/asciidoc/parser/block.rb', line 33 def example_block(n_deep) block_style(n_deep, '=', 4) end |
#open_block(n_deep) ⇒ Object
Open block: exactly 2 dashes (cannot nest within itself)
54 55 56 |
# File 'lib/coradoc/asciidoc/parser/block.rb', line 54 def open_block(n_deep) block_style_exact(n_deep, '-', 2) end |
#pass_block(n_deep) ⇒ Object
37 38 39 |
# File 'lib/coradoc/asciidoc/parser/block.rb', line 37 def pass_block(n_deep) block_style(n_deep, '+', 4, :pass) end |
#quote_block(n_deep) ⇒ Object
41 42 43 |
# File 'lib/coradoc/asciidoc/parser/block.rb', line 41 def quote_block(n_deep) block_style(n_deep, '_', 4) end |
#sidebar_block(n_deep) ⇒ Object
45 46 47 |
# File 'lib/coradoc/asciidoc/parser/block.rb', line 45 def (n_deep) block_style(n_deep, '*', 4) end |
#source_block(n_deep) ⇒ Object
49 50 51 |
# File 'lib/coradoc/asciidoc/parser/block.rb', line 49 def source_block(n_deep) block_style(n_deep, '-', 4, verbatim: true) end |