Module: Coradoc::AsciiDoc::Parser::List

Defined in:
lib/coradoc/asciidoc/parser/list.rb

Instance Method Summary collapse

Instance Method Details

#definition_list(_delimiter = nil) ⇒ Object



32
33
34
35
36
# File 'lib/coradoc/asciidoc/parser/list.rb', line 32

def definition_list(_delimiter = nil)
  (attribute_list >> newline).maybe >>
    dlist_item.repeat(1).as(:definition_list) >>
    dlist_item.absent?
end

#dlist_definitionObject



117
118
119
120
# File 'lib/coradoc/asciidoc/parser/list.rb', line 117

def dlist_definition
  text
    .as(:definition) >> line_ending >> empty_line.repeat(0)
end

#dlist_delimiterObject



100
101
102
103
104
105
106
107
108
# File 'lib/coradoc/asciidoc/parser/list.rb', line 100

def dlist_delimiter
  (
    (str(':::::') >> match(':').absent?) |
    (str('::::') >> match(':').absent?) |
    (str(':::') >> match(':').absent?) |
    (str('::') >> match(':').absent?) |
    str(';;')
  ).as(:delimiter)
end

#dlist_item(_delimiter = nil) ⇒ Object



122
123
124
125
126
127
128
129
# File 'lib/coradoc/asciidoc/parser/list.rb', line 122

def dlist_item(_delimiter = nil)
  (((dlist_term.as(:terms).repeat(1) >> line_ending >>
    empty_line.repeat(0)).repeat(1) >>
    dlist_definition) |
    (dlist_term.repeat(1, 1).as(:terms) >> space >>
      dlist_definition)
  ).as(:definition_list_item)
end

#dlist_term(_delimiter = nil) ⇒ Object



110
111
112
113
114
115
# File 'lib/coradoc/asciidoc/parser/list.rb', line 110

def dlist_term(_delimiter = nil)
  term_chars =
    (dlist_delimiter.absent? >> match("[^\n]")).repeat(1)
                                               .as(:text)
  (element_id_inline.maybe >> term_chars).as(:dlist_term) >> dlist_delimiter
end

#list(nesting_level = 1) ⇒ Object



8
9
10
11
12
13
14
# File 'lib/coradoc/asciidoc/parser/list.rb', line 8

def list(nesting_level = 1)
  (
  unordered_list(nesting_level) |
     ordered_list(nesting_level) |
     definition_list
).as(:list)
end

#list_continuationObject



16
17
18
# File 'lib/coradoc/asciidoc/parser/list.rb', line 16

def list_continuation
  line_start? >> str("+\n")
end

#list_marker(nesting_level = 1) ⇒ Object



38
39
40
# File 'lib/coradoc/asciidoc/parser/list.rb', line 38

def list_marker(nesting_level = 1)
  olist_marker(nesting_level) | ulist_marker(nesting_level)
end

#olist_item(nesting_level = 1) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/coradoc/asciidoc/parser/list.rb', line 53

def olist_item(nesting_level = 1)
  item = olist_marker(nesting_level).as(:marker) >>
         match("\n").absent? >> space >> text_line(true, unguarded: true)
  # >>
  # (list_continuation.present? >> list_continuation >>
  # paragraph #| example_block(n_deep: 1)
  # ).repeat(0).as(:attached)

  att = (list_continuation.present? >>
          list_continuation >>
          (admonition_line | paragraph | block) # (n_deep: 1))
        ).repeat(0).as(:attached)
  item >>= att.maybe

  if nesting_level <= 4
    item >>= (list_marker(nesting_level + 1).present? >>
           list(nesting_level + 1)).repeat(0).as(:nested) # ).maybe
  end
  olist_marker(nesting_level).present? >> item.as(:list_item)
end

#olist_marker(nesting_level = 1) ⇒ Object



42
43
44
45
46
47
48
49
50
51
# File 'lib/coradoc/asciidoc/parser/list.rb', line 42

def olist_marker(nesting_level = 1)
  # Don't match table cell format specs like ".2+^.^|"
  line_start? >>
    (nesting_level > 1 ? literal_space.maybe : str('')) >>
    str('.' * nesting_level) >>
    str('.').absent? >>
    (
      (match['0-9.<>^'] | str('+')).repeat(0, 3) >> str('|')
    ).absent?
end

#ordered_list(nesting_level = 1) ⇒ Object



20
21
22
23
24
# File 'lib/coradoc/asciidoc/parser/list.rb', line 20

def ordered_list(nesting_level = 1)
  attrs = (attribute_list >> newline).maybe
  r = olist_item(nesting_level)
  attrs >> olist_item(nesting_level).present? >> r.repeat(1).as(:ordered)
end

#ulist_item(nesting_level = 1) ⇒ Object



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/coradoc/asciidoc/parser/list.rb', line 82

def ulist_item(nesting_level = 1)
  item = ulist_marker(nesting_level).as(:marker) >>
         str(' [[[').absent? >>
         match("\n").absent? >> space >> text_line(true, unguarded: true)

  att = (list_continuation.present? >>
          list_continuation >>
          (admonition_line | paragraph | block) # (n_deep: 1))
        ).repeat(0).as(:attached)
  item >>= att.maybe

  if nesting_level <= 4
    item >>= (list_marker(nesting_level + 1).present? >>
           list(nesting_level + 1)).repeat(0).as(:nested) # ).maybe
  end
  ulist_marker(nesting_level).present? >> item.as(:list_item)
end

#ulist_marker(nesting_level = 1) ⇒ Object



74
75
76
77
78
79
80
# File 'lib/coradoc/asciidoc/parser/list.rb', line 74

def ulist_marker(nesting_level = 1)
  line_start? >>
    (nesting_level > 1 ? literal_space.maybe : str('')) >>
    str('*' * nesting_level) >>
    str('*').absent? >>
    str('===').absent?
end

#unordered_list(nesting_level = 1) ⇒ Object



26
27
28
29
30
# File 'lib/coradoc/asciidoc/parser/list.rb', line 26

def unordered_list(nesting_level = 1)
  attrs = (attribute_list >> newline).maybe
  r = ulist_item(nesting_level)
  attrs >> r.repeat(1).as(:unordered)
end