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

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

Instance Method Summary collapse

Instance Method Details

#definition_list(delimiter = '::') ⇒ Object



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

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

#dlist_definitionObject



114
115
116
117
# File 'lib/coradoc/asciidoc/parser/list.rb', line 114

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

#dlist_delimiterObject



104
105
106
107
# File 'lib/coradoc/asciidoc/parser/list.rb', line 104

def dlist_delimiter
  (str('::') | str(':::') | str('::::') | str(';;')
  ).as(:delimiter)
end

#dlist_item(delimiter) ⇒ Object



119
120
121
122
123
124
125
126
# File 'lib/coradoc/asciidoc/parser/list.rb', line 119

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

#dlist_term(_delimiter) ⇒ Object



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

def dlist_term(_delimiter)
  match("[^\n:]").repeat(1) # >> empty_line.repeat(0)
                 .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



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

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
52
53
54
# File 'lib/coradoc/asciidoc/parser/list.rb', line 42

def olist_marker(nesting_level = 1)
  # Don't match table cell format specs like ".2+^.^|"
  # Table cells have format: [colspan][.rowspan][halign][valign][style][*]|
  # If we see a format spec pattern followed by "|", it's a table cell, not a list
  line_start? >>
    str('.' * nesting_level) >>
    str('.').absent? >>
    # Don't match if followed by table cell format spec
    # Pattern: digits, dots, plus, alignment chars (^<>), style letters, then |
    (
      (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



86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/coradoc/asciidoc/parser/list.rb', line 86

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



77
78
79
80
81
82
83
84
# File 'lib/coradoc/asciidoc/parser/list.rb', line 77

def ulist_marker(nesting_level = 1)
  # Don't match table delimiters like "|==="
  line_start? >>
    str('*' * nesting_level) >>
    str('*').absent? >>
    # Don't match if followed by "===" (table delimiter)
    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