Module: Coradoc::Parser::Asciidoc::Section

Included in:
Base
Defined in:
lib/coradoc/parser/asciidoc/section.rb

Instance Method Summary collapse

Instance Method Details

#contentsObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/coradoc/parser/asciidoc/section.rb', line 5

def contents
  (
    bib_entry |
    block_image |
    tag |
    comment_block |
    comment_line |
    include_directive |
    admonition_line |
    block |
    table.as(:table) |
    # highlight.as(:highlight) |
    # glossaries.as(:glossaries) |
    paragraph |
    list |
    empty_line.as(:line_break)
  ).repeat(1)
end

#section(level = 2) ⇒ Object

section



47
48
49
50
51
52
53
54
55
56
57
# File 'lib/coradoc/parser/asciidoc/section.rb', line 47

def section(level = 2)
  r = section_block(level)
  if level < 8
    r = r >> section(level + 1).as(:section).repeat(0).as(:sections)
  end
  if level == 2
    r.as(:section)
  else
    r
  end
end

#section_block(level = 2) ⇒ Object



24
25
26
27
28
29
30
31
32
# File 'lib/coradoc/parser/asciidoc/section.rb', line 24

def section_block(level = 2)
  return nil if level > 8

  (attribute_list >> newline).maybe >>
    element_id.maybe >>
    (attribute_list >> newline).maybe >>
    section_title(level).as(:title) >>
    contents.as(:contents).maybe
end

#section_prefixObject



34
35
36
# File 'lib/coradoc/parser/asciidoc/section.rb', line 34

def section_prefix
  (line_start? >> match("^[=]") >> str("=").repeat(0) >> match('[^\n]'))
end

#section_title(level = 2, max_level = 8) ⇒ Object

Heading



39
40
41
42
43
44
# File 'lib/coradoc/parser/asciidoc/section.rb', line 39

def section_title(level = 2, max_level = 8)
  line_start? >>
    match("=").repeat(level, max_level).as(:level) >>
    str("=").absent? >>
    space? >> text.as(:text) >> endline.as(:line_break)
end