Module: Asciidoctor::Rfc::V3::Lists

Included in:
Converter
Defined in:
lib/asciidoctor/rfc/v3/lists.rb

Constant Summary collapse

OLIST_TYPES =
Hash.new("1").merge(
  arabic:     "1",
  # decimal:    "1", # not supported
  loweralpha: "a",
  # lowergreek: "lower-greek", # not supported
  lowerroman: "i",
  upperalpha: "A",
  upperroman: "I",
).freeze

Instance Method Summary collapse

Instance Method Details

#dlist(node) ⇒ Object

Syntax:

[[id]]
[horizontal,compact] (optional)
A:: B
C:: D


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
161
162
163
164
165
166
167
168
169
170
171
172
173
# File 'lib/asciidoctor/rfc/v3/lists.rb', line 136

def dlist(node)
  result = []

  result << noko do |xml|
    dl_attributes = {
      anchor: node.id,
      hanging: ("true" if node.style == "horizontal"),
      spacing: ("compact" if node.style == "compact"),
    }

    xml.dl **attr_code(dl_attributes) do |xml_dl|
      node.items.each do |terms, dd|
        terms.each_with_index do |dt, idx|
          xml_dl.dt { |xml_dt| xml_dt << dt.text }
          if idx < terms.size - 1
            xml_dl.dd
          end
        end

        if dd.nil?
          xml_dl.dd
        else
          xml_dl.dd do |xml_dd|
            if dd.blocks?
              if dd.text?
                xml_dd.t { |t| t << dd.text }
              end
              xml_dd << dd.content
            else
              xml_dd << dd.text
            end
          end
        end
      end
    end
  end
  result
end

#olist(node) ⇒ Object

Syntax:

[[id]]
[start=n,group=n,spacing=normal|compact] (optional)
. A
. B


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
127
128
129
# File 'lib/asciidoctor/rfc/v3/lists.rb', line 96

def olist(node)
  result = []

  result << noko do |xml|
    type = OLIST_TYPES[node.style.to_sym]
    type = node.attr("format") unless node.attr("format").nil?
    ol_attributes = {
      anchor: node.id,
      start: node.attr("start"),
      group: node.attr("group"),
      type: type,
      spacing: ("compact" if node.style == "compact") || node.attr("spacing"),
    }

    xml.ol **attr_code(ol_attributes) do |xml_ol|
      node.items.each do |item|
        li_attributes = {
          anchor: item.id,
        }
        xml_ol.li **attr_code(li_attributes) do |xml_li|
          if item.blocks?
            xml_li.t do |t|
              t << item.text
            end
            xml_li << item.content
          else
            xml_li << item.text
          end
        end
      end
    end
  end
  result
end

#ulist(node) ⇒ Object

Syntax:

[[id]]
[empty=true,spacing=compact|normal] (optional)
* A
* B


48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/asciidoctor/rfc/v3/lists.rb', line 48

def ulist(node)
  result = []

  result << noko do |xml|
    ul_attributes = {
      anchor: node.id,
      empty: node.attr("empty"),
      spacing: node.attr("spacing"),
    }

    xml.ul **attr_code(ul_attributes) do |xml_ul|
      node.items.each do |item|
        li_attributes = {
          anchor: item.id,
        }

        xml_ul.li **attr_code(li_attributes) do |xml_li|
          if item.blocks?
            xml_li.t do |t|
              t << item.text
            end
            xml_li << item.content
          else
            xml_li << item.text
          end
        end
      end
    end
  end

  result
end