Module: Asciidoctor::ISO::Lists

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

Instance Method Summary collapse

Instance Method Details

#biblio_ref(node) ⇒ Object



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/asciidoctor/iso/lists.rb', line 74

def biblio_ref(node)
  noko do |xml|
    node.items.each do |item|
      matched = %r{^<ref\sanchor="(?<anchor>[^"]+)">
      \[ISO\s(?<code>[0-9-]+)(:(?<year>[0-9]+))?\]</ref>,?\s
      (?<text>.*)$}.match item.text
      matched2 = %r{^<ref\sanchor="(?<anchor>[^"]+)">
      \[ISO\s(?<code>[0-9-]+):--\]</ref>,?\s?
      <fn>(?<fn>[^\]]+)</fn>,?\s?(?<text>.*)$}.match item.text
      if matched2.nil?
        if matched.nil?
          xml.reference do |t|
            t.p { |p| p << ref_normalise(item.text) }
          end
        else
          isorefmatches(xml, matched)
        end
      else
        isorefmatches2(xml, matched2)
      end
    end
  end.join
end

#colist(node) ⇒ Object



145
146
147
148
149
150
151
152
153
154
155
# File 'lib/asciidoctor/iso/lists.rb', line 145

def colist(node)
  noko do |xml|
    xml.colist **attr_code(anchor: node.id) do |xml_ul|
      node.items.each_with_index do |item, i|
        xml_ul.annotation **attr_code(id: i + 1) do |xml_li|
          xml_li << item.text
        end
      end
    end
  end.join
end

#dlist(node) ⇒ Object



115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# File 'lib/asciidoctor/iso/lists.rb', line 115

def dlist(node)
  noko do |xml|
    xml.dl **attr_code(anchor: node.id) 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.p { |t| t << dd.text }
              end
              xml_dd << dd.content
            else
              xml_dd.p { |t| t << dd.text }
            end
          end
        end
      end
    end
  end.join
end

#isorefmatches(xml, matched) ⇒ Object



24
25
26
27
28
29
30
31
32
33
# File 'lib/asciidoctor/iso/lists.rb', line 24

def isorefmatches(xml, matched)
  ref_attributes = {
    anchor: matched[:anchor],
  }
  xml.iso_ref_title **attr_code(ref_attributes) do |t|
    t.isocode matched[:code]
    t.isodate matched[:year] if matched[:year]
    t.isotitle { |i| i << ref_normalise(matched[:text]) }
  end
end

#isorefmatches2(xml, matched2) ⇒ Object



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

def isorefmatches2(xml, matched2)
  ref_attributes = {
    anchor: matched2[:anchor],
  }
  xml.iso_ref_title **attr_code(ref_attributes) do |t|
    t.isocode matched2[:code]
    t.isodate "--"
    t.date_footnote matched2[:fn]
    t.isotitle { |i| i << ref_normalise(matched2[:text]) }
  end
end

#norm_ref(node) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/asciidoctor/iso/lists.rb', line 52

def norm_ref(node)
  noko do |xml|
    node.items.each do |item|
      matched = %r{^<ref\sanchor="(?<anchor>[^"]+)">
      \[ISO\s(?<code>[0-9-]+)(:(?<year>[0-9]+))?\]</ref>,?\s
      (?<text>.*)$}x.match item.text
      matched2 = %r{^<ref\sanchor="(?<anchor>[^"]+)">
      \[ISO\s(?<code>[0-9-]+):--\]</ref>,?\s?
      <fn>(?<fn>[^\]]+)</fn>,?\s?(?<text>.*)$}x.match item.text
      if matched2.nil?
        if matched.nil?
          warn %(asciidoctor: WARNING (#{current_location(node)}): normative reference not in expected format: #{item.text})
        else
          isorefmatches(xml, matched)
        end
      else
        isorefmatches2(xml, matched2)
      end
    end
  end.join
end

#olist(node) ⇒ Object



98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/asciidoctor/iso/lists.rb', line 98

def olist(node)
  noko do |xml|
    xml.ol **attr_code(anchor: node.id, type: node.style) do |xml_ol|
      node.items.each do |item|
        xml_ol.li **attr_code(anchor: item.id) do |xml_li|
          if item.blocks?
            xml_li.p { |t| t << item.text }
            xml_li << item.content
          else
            xml_li.p { |p| p << item.text }
          end
        end
      end
    end
  end.join
end

#ref_normalise(ref) ⇒ Object



47
48
49
50
# File 'lib/asciidoctor/iso/lists.rb', line 47

def ref_normalise(ref)
  ref.gsub(/&#8201;&#8212;&#8201;/, " -- ").
    gsub(/&amp;amp;/, "&amp;")
end

#ulist(node) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/asciidoctor/iso/lists.rb', line 5

def ulist(node)
  return norm_ref(node) if $norm_ref
  return biblio_ref(node) if $biblio
  noko do |xml|
    xml.ul **attr_code(anchor: node.id) do |xml_ul|
      node.items.each do |item|
        xml_ul.li **attr_code(anchor: item.id) do |xml_li|
          if item.blocks?
            xml_li.p { |t| t << item.text }
            xml_li << item.content
          else
            xml_li.p { |p| p << item.text }
          end
        end
      end
    end
  end.join
end