Module: Asciidoctor::Standoc::Lists

Included in:
Converter
Defined in:
lib/asciidoctor/standoc/lists.rb

Instance Method Summary collapse

Instance Method Details

#colist(node) ⇒ Object



106
107
108
109
110
111
112
113
114
# File 'lib/asciidoctor/standoc/lists.rb', line 106

def colist(node)
  noko do |xml|
    node.items.each_with_index do |item, i|
      xml.annotation **attr_code(id: i + 1) do |xml_li|
        xml_li.p { |p| p << item.text }
      end
    end
  end.join("\n")
end

#dd(dd, xml_dl) ⇒ Object



78
79
80
81
82
83
84
85
86
87
# File 'lib/asciidoctor/standoc/lists.rb', line 78

def dd(dd, xml_dl)
  if dd.nil?
    xml_dl.dd
    return
  end
  xml_dl.dd do |xml_dd|
    xml_dd.p { |t| t << dd.text } if dd.text?
    xml_dd << dd.content if dd.blocks?
  end
end

#dl_attrs(node) ⇒ Object



89
90
91
92
93
# File 'lib/asciidoctor/standoc/lists.rb', line 89

def dl_attrs(node)
  attr_code(keep_attrs(node).
            merge(id: Metanorma::Utils::anchor_or_uuid(node),
                  key: node.option?("key") ? "true" : nil))
end

#dlist(node) ⇒ Object



95
96
97
98
99
100
101
102
103
104
# File 'lib/asciidoctor/standoc/lists.rb', line 95

def dlist(node)
  noko do |xml|
    xml.dl **dl_attrs(node) do |xml_dl|
      node.items.each do |terms, dd|
        dt(terms, xml_dl)
        dd(dd, xml_dl)
      end
    end
  end.join("\n")
end

#dt(terms, xml_dl) ⇒ Object



69
70
71
72
73
74
75
76
# File 'lib/asciidoctor/standoc/lists.rb', line 69

def dt(terms, xml_dl)
  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
end

#li(xml_ul, item) ⇒ Object



4
5
6
7
8
9
10
11
12
13
# File 'lib/asciidoctor/standoc/lists.rb', line 4

def li(xml_ul, item)
  xml_ul.li do |xml_li|
    if item.blocks?
      xml_li.p(**id_attr(item)) { |t| t << item.text }
      xml_li << item.content
    else
      xml_li.p(**id_attr(item)) { |p| p << item.text }
    end
  end
end

#ol_attrs(node) ⇒ Object



56
57
58
59
# File 'lib/asciidoctor/standoc/lists.rb', line 56

def ol_attrs(node)
  attr_code(keep_attrs(node).merge(id: Metanorma::Utils::anchor_or_uuid(node),
                                   type: olist_style(node.style)))
end

#olist(node) ⇒ Object



61
62
63
64
65
66
67
# File 'lib/asciidoctor/standoc/lists.rb', line 61

def olist(node)
  noko do |xml|
    xml.ol **ol_attrs(node) do |xml_ol|
      node.items.each { |item| li(xml_ol, item) }
    end
  end.join("\n")
end

#olist_style(style) ⇒ Object



48
49
50
51
52
53
54
# File 'lib/asciidoctor/standoc/lists.rb', line 48

def olist_style(style)
  return "alphabet" if style == "loweralpha"
  return "roman" if style == "lowerroman"
  return "roman_upper" if style == "upperroman"
  return "alphabet_upper" if style == "upperalpha"
  style
end

#ul_attrs(node) ⇒ Object



26
27
28
# File 'lib/asciidoctor/standoc/lists.rb', line 26

def ul_attrs(node)
  attr_code(id_attr(node).merge(keep_attrs(node)))
end

#ul_li(xml_ul, item) ⇒ Object



15
16
17
18
19
20
21
22
23
24
# File 'lib/asciidoctor/standoc/lists.rb', line 15

def ul_li(xml_ul, item)
  xml_ul.li **ul_li_attrs(item) do |xml_li|
    if item.blocks?
      xml_li.p(**id_attr(item)) { |t| t << item.text }
      xml_li << item.content
    else
      xml_li.p(**id_attr(item)) { |p| p << item.text }
    end
  end
end

#ul_li_attrs(node) ⇒ Object



30
31
32
33
34
35
# File 'lib/asciidoctor/standoc/lists.rb', line 30

def ul_li_attrs(node)
  attr_code(
    uncheckedcheckbox: node.attr?("checkbox") ? !node.attr?("checked") : nil,
    checkedcheckbox: node.attr?("checkbox") ? node.attr?("checked") : nil,
  )
end

#ulist(node) ⇒ Object



37
38
39
40
41
42
43
44
45
46
# File 'lib/asciidoctor/standoc/lists.rb', line 37

def ulist(node)
  return reference(node) if in_norm_ref? || in_biblio?
  noko do |xml|
    xml.ul **ul_attrs(node) do |xml_ul|
      node.items.each do |item|
        ul_li(xml_ul, item)
      end
    end
  end.join("\n")
end