Module: Coradoc::Parser::Asciidoc::Block
- Included in:
- Base
- Defined in:
- lib/coradoc/parser/asciidoc/block.rb
Instance Method Summary collapse
- #block(n_deep = 3) ⇒ Object
- #block_content(n_deep = 3) ⇒ Object
- #block_delimiter ⇒ Object
- #block_style(n_deep = 3, delimiter = "*", repeater = 4, type = nil) ⇒ Object
- #block_title ⇒ Object
- #block_type(type) ⇒ Object
- #element_attributes ⇒ Object
- #example_block(n_deep) ⇒ Object
- #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
5 6 7 8 9 10 11 |
# File 'lib/coradoc/parser/asciidoc/block.rb', line 5 def block(n_deep = 3) (example_block(n_deep) | (n_deep) | source_block(n_deep) | quote_block(n_deep) | pass_block(n_deep)).as(:block) end |
#block_content(n_deep = 3) ⇒ Object
43 44 45 46 47 48 49 50 |
# File 'lib/coradoc/parser/asciidoc/block.rb', line 43 def block_content(n_deep = 3) c = block_image | list | text_line | empty_line.as(:line_break) c = c | block(n_deep - 1) if n_deep.positive? c.repeat(1) end |
#block_delimiter ⇒ Object
52 53 54 55 56 57 58 59 60 61 |
# File 'lib/coradoc/parser/asciidoc/block.rb', line 52 def block_delimiter line_start? >> ((str("*") | str("=") | str("_") | str("+") | str("-")).repeat(4) | str("-").repeat(2, 2)) >> newline end |
#block_style(n_deep = 3, delimiter = "*", repeater = 4, type = nil) ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/coradoc/parser/asciidoc/block.rb', line 73 def block_style(n_deep = 3, delimiter = "*", repeater = 4, type = nil) current_delimiter = str(delimiter).repeat(repeater).capture(:delimit) closing_delimiter = dynamic do |_s, c| str(c.captures[:delimit].to_s.strip) end element_attributes >> (line_start? >> attribute_list >> newline).maybe >> line_start? >> current_delimiter.as(:delimiter) >> newline >> if type == :pass (text_line | empty_line.as(:line_break)).repeat(1).as(:lines) else (closing_delimiter >> newline).absent? >> block_content(n_deep - 1).as(:lines) end >> line_start? >> closing_delimiter >> newline end |
#block_title ⇒ Object
33 34 35 |
# File 'lib/coradoc/parser/asciidoc/block.rb', line 33 def block_title str(".") >> space.absent? >> text.as(:title) >> newline end |
#block_type(type) ⇒ Object
37 38 39 40 41 |
# File 'lib/coradoc/parser/asciidoc/block.rb', line 37 def block_type(type) (line_start? >> str("[") >> str("[").absent? >> str(type).as(:type) >> str("]")) >> newline # | end |
#element_attributes ⇒ Object
63 64 65 66 67 68 69 70 71 |
# File 'lib/coradoc/parser/asciidoc/block.rb', line 63 def element_attributes block_title.maybe >> element_id.maybe >> (attribute_list >> newline).maybe >> block_title.maybe >> newline.maybe >> (attribute_list >> newline).maybe >> element_id.maybe end |
#example_block(n_deep) ⇒ Object
13 14 15 |
# File 'lib/coradoc/parser/asciidoc/block.rb', line 13 def example_block(n_deep) block_style(n_deep, "=") end |
#pass_block(n_deep) ⇒ Object
17 18 19 |
# File 'lib/coradoc/parser/asciidoc/block.rb', line 17 def pass_block(n_deep) block_style(n_deep, "+", 4, :pass) end |
#quote_block(n_deep) ⇒ Object
21 22 23 |
# File 'lib/coradoc/parser/asciidoc/block.rb', line 21 def quote_block(n_deep) block_style(n_deep, "_") end |
#sidebar_block(n_deep) ⇒ Object
25 26 27 |
# File 'lib/coradoc/parser/asciidoc/block.rb', line 25 def (n_deep) block_style(n_deep, "*") end |
#source_block(n_deep) ⇒ Object
29 30 31 |
# File 'lib/coradoc/parser/asciidoc/block.rb', line 29 def source_block(n_deep) block_style(n_deep, "-", 2) end |