isodoc 1.7.4 → 1.7.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,133 +1,144 @@
1
- module IsoDoc::WordFunction
2
- module Postprocess
3
- def word_preface(docxml)
4
- word_cover(docxml) if @wordcoverpage
5
- word_intro(docxml, @wordToClevels) if @wordintropage
6
- end
1
+ module IsoDoc
2
+ module WordFunction
3
+ module Postprocess
4
+ def word_preface(docxml)
5
+ word_cover(docxml) if @wordcoverpage
6
+ word_intro(docxml, @wordToClevels) if @wordintropage
7
+ end
7
8
 
8
- def word_cover(docxml)
9
- cover = File.read(@wordcoverpage, encoding: "UTF-8")
10
- cover = populate_template(cover, :word)
11
- coverxml = to_word_xhtml_fragment(cover)
12
- docxml.at('//div[@class="WordSection1"]').children.first.previous =
13
- coverxml.to_xml(encoding: "US-ASCII")
14
- end
9
+ def word_cover(docxml)
10
+ cover = File.read(@wordcoverpage, encoding: "UTF-8")
11
+ cover = populate_template(cover, :word)
12
+ coverxml = to_word_xhtml_fragment(cover)
13
+ docxml.at('//div[@class="WordSection1"]').children.first.previous =
14
+ coverxml.to_xml(encoding: "US-ASCII")
15
+ end
15
16
 
16
- def word_intro(docxml, level)
17
- intro = insert_toc(File.read(@wordintropage, encoding: "UTF-8"),
18
- docxml, level)
19
- intro = populate_template(intro, :word)
20
- introxml = to_word_xhtml_fragment(intro)
21
- docxml.at('//div[@class="WordSection2"]').children.first.previous =
22
- introxml.to_xml(encoding: "US-ASCII")
23
- end
17
+ def word_intro(docxml, level)
18
+ intro = insert_toc(File.read(@wordintropage, encoding: "UTF-8"),
19
+ docxml, level)
20
+ intro = populate_template(intro, :word)
21
+ introxml = to_word_xhtml_fragment(intro)
22
+ docxml.at('//div[@class="WordSection2"]').children.first.previous =
23
+ introxml.to_xml(encoding: "US-ASCII")
24
+ end
24
25
 
25
- def insert_toc(intro, docxml, level)
26
- intro.sub(/WORDTOC/, make_WordToC(docxml, level))
27
- end
26
+ def insert_toc(intro, docxml, level)
27
+ intro.sub(/WORDTOC/, make_WordToC(docxml, level))
28
+ end
28
29
 
29
- def word_toc_entry(toclevel, heading)
30
- bookmark = bookmarkid # Random.rand(1000000000)
31
- <<~TOC
32
- <p class="MsoToc#{toclevel}"><span class="MsoHyperlink"><span
33
- lang="EN-GB" style='mso-no-proof:yes'>
34
- <a href="#_Toc#{bookmark}">#{heading}<span lang="EN-GB"
35
- class="MsoTocTextSpan">
36
- <span style='mso-tab-count:1 dotted'>. </span>
37
- </span><span lang="EN-GB" class="MsoTocTextSpan">
38
- <span style='mso-element:field-begin'></span></span>
39
- <span lang="EN-GB"
40
- class="MsoTocTextSpan"> PAGEREF _Toc#{bookmark} \\h </span>
41
- <span lang="EN-GB" class="MsoTocTextSpan"><span
42
- style='mso-element:field-separator'></span></span><span
43
- lang="EN-GB" class="MsoTocTextSpan">1</span>
30
+ def word_toc_entry(toclevel, heading)
31
+ bookmark = bookmarkid # Random.rand(1000000000)
32
+ <<~TOC
33
+ <p class="MsoToc#{toclevel}"><span class="MsoHyperlink"><span
34
+ lang="EN-GB" style='mso-no-proof:yes'>
35
+ <a href="#_Toc#{bookmark}">#{heading}<span lang="EN-GB"
36
+ class="MsoTocTextSpan">
37
+ <span style='mso-tab-count:1 dotted'>. </span>
38
+ </span><span lang="EN-GB" class="MsoTocTextSpan">
39
+ <span style='mso-element:field-begin'></span></span>
44
40
  <span lang="EN-GB"
45
- class="MsoTocTextSpan"></span><span
46
- lang="EN-GB" class="MsoTocTextSpan"><span
47
- style='mso-element:field-end'></span></span></a></span></span></p>
41
+ class="MsoTocTextSpan"> PAGEREF _Toc#{bookmark} \\h </span>
42
+ <span lang="EN-GB" class="MsoTocTextSpan"><span
43
+ style='mso-element:field-separator'></span></span><span
44
+ lang="EN-GB" class="MsoTocTextSpan">1</span>
45
+ <span lang="EN-GB"
46
+ class="MsoTocTextSpan"></span><span
47
+ lang="EN-GB" class="MsoTocTextSpan"><span
48
+ style='mso-element:field-end'></span></span></a></span></span></p>
48
49
 
49
- TOC
50
- end
50
+ TOC
51
+ end
51
52
 
52
- def word_toc_preface(level)
53
- <<~TOC.freeze
54
- <span lang="EN-GB"><span
55
- style='mso-element:field-begin'></span><span
56
- style='mso-spacerun:yes'>&#xA0;</span>TOC
57
- \\o &quot;1-#{level}&quot; \\h \\z \\u <span
58
- style='mso-element:field-separator'></span></span>
53
+ def word_toc_preface(level)
54
+ <<~TOC.freeze
55
+ <span lang="EN-GB"><span
56
+ style='mso-element:field-begin'></span><span
57
+ style='mso-spacerun:yes'>&#xA0;</span>TOC
58
+ \\o &quot;1-#{level}&quot; \\h \\z \\u <span
59
+ style='mso-element:field-separator'></span></span>
60
+ TOC
61
+ end
62
+
63
+ WORD_TOC_SUFFIX1 = <<~TOC.freeze
64
+ <p class="MsoToc1"><span lang="EN-GB"><span
65
+ style='mso-element:field-end'></span></span><span
66
+ lang="EN-GB"><o:p>&nbsp;</o:p></span></p>
59
67
  TOC
60
- end
61
68
 
62
- WORD_TOC_SUFFIX1 = <<~TOC.freeze
63
- <p class="MsoToc1"><span lang="EN-GB"><span
64
- style='mso-element:field-end'></span></span><span
65
- lang="EN-GB"><o:p>&nbsp;</o:p></span></p>
66
- TOC
67
-
68
- def make_WordToC(docxml, level)
69
- toc = ""
70
- #docxml.xpath("//h1 | //h2[not(ancestor::*[@class = 'Section3'])]").
71
- xpath = (1..level).each.map { |i| "//h#{i}" }.join (" | ")
72
- docxml.xpath(xpath).each do |h|
73
- toc += word_toc_entry(h.name[1].to_i, header_strip(h))
69
+ def make_WordToC(docxml, level)
70
+ toc = ""
71
+ # docxml.xpath("//h1 | //h2[not(ancestor::*[@class = 'Section3'])]").
72
+ xpath = (1..level).each.map { |i| "//h#{i}" }.join (" | ")
73
+ docxml.xpath(xpath).each do |h|
74
+ toc += word_toc_entry(h.name[1].to_i, header_strip(h))
75
+ end
76
+ toc.sub(/(<p class="MsoToc1">)/,
77
+ %{\\1#{word_toc_preface(level)}}) + WORD_TOC_SUFFIX1
74
78
  end
75
- toc.sub(/(<p class="MsoToc1">)/,
76
- %{\\1#{word_toc_preface(level)}}) + WORD_TOC_SUFFIX1
77
- end
78
79
 
79
- def authority_cleanup1(docxml, klass)
80
- dest = docxml.at("//div[@id = 'boilerplate-#{klass}-destination']")
81
- auth = docxml.at("//div[@id = 'boilerplate-#{klass}' or @class = 'boilerplate-#{klass}']")
82
- auth&.xpath(".//h1[not(text())] | .//h2[not(text())]")&.each { |h| h.remove }
83
- auth&.xpath(".//h1 | .//h2")&.each do |h|
84
- h.name = "p"
85
- h["class"] = "TitlePageSubhead"
80
+ def authority_cleanup1(docxml, klass)
81
+ dest = docxml.at("//div[@id = 'boilerplate-#{klass}-destination']")
82
+ auth = docxml.at("//div[@id = 'boilerplate-#{klass}' "\
83
+ "or @class = 'boilerplate-#{klass}']")
84
+ auth&.xpath(".//h1[not(text())] | .//h2[not(text())]")&.each(&:remove)
85
+ auth&.xpath(".//h1 | .//h2")&.each do |h|
86
+ h.name = "p"
87
+ h["class"] = "TitlePageSubhead"
88
+ end
89
+ dest and auth and dest.replace(auth.remove)
86
90
  end
87
- dest and auth and dest.replace(auth.remove)
88
- end
89
91
 
90
- def authority_cleanup(docxml)
91
- %w(copyright license legal feedback).each do |t|
92
- authority_cleanup1(docxml, t)
92
+ def authority_cleanup(docxml)
93
+ %w(copyright license legal feedback).each do |t|
94
+ authority_cleanup1(docxml, t)
95
+ end
93
96
  end
94
- end
95
97
 
96
- def generate_header(filename, _dir)
97
- return nil unless @header
98
- template = IsoDoc::Common.liquid(File.read(@header, encoding: "UTF-8"))
99
- meta = @meta.get.merge(@labels ? { labels: @labels } : {}).merge(@meta.labels ? { labels: @meta.labels } : {})
100
- meta[:filename] = filename
101
- params = meta.map { |k, v| [k.to_s, v] }.to_h
102
- Tempfile.open(%w(header html), :encoding => "utf-8") do |f|
103
- f.write(template.render(params))
104
- f
98
+ def generate_header(filename, _dir)
99
+ return nil unless @header
100
+
101
+ template = IsoDoc::Common.liquid(File.read(@header, encoding: "UTF-8"))
102
+ meta = @meta.get.merge(@labels ? { labels: @labels } : {})
103
+ .merge(@meta.labels ? { labels: @meta.labels } : {})
104
+ meta[:filename] = filename
105
+ params = meta.transform_keys(&:to_s)
106
+ Tempfile.open(%w(header html), encoding: "utf-8") do |f|
107
+ f.write(template.render(params))
108
+ f
109
+ end
105
110
  end
106
- end
107
111
 
108
- def word_section_breaks(docxml)
109
- @landscapestyle = ""
110
- word_section_breaks1(docxml, "WordSection2")
111
- word_section_breaks1(docxml, "WordSection3")
112
- word_remove_pb_before_annex(docxml)
113
- docxml.xpath("//br[@orientation]").each { |br| br.delete("orientation") }
114
- end
112
+ def word_section_breaks(docxml)
113
+ @landscapestyle = ""
114
+ word_section_breaks1(docxml, "WordSection2")
115
+ word_section_breaks1(docxml, "WordSection3")
116
+ word_remove_pb_before_annex(docxml)
117
+ docxml.xpath("//br[@orientation]").each do |br|
118
+ br.delete("orientation")
119
+ end
120
+ end
115
121
 
116
- def word_section_breaks1(docxml, sect)
117
- docxml.xpath("//div[@class = '#{sect}']//br[@orientation]").reverse.
118
- each_with_index do |br, i|
119
- @landscapestyle += "\ndiv.#{sect}_#{i} {page:#{sect}#{br["orientation"] == "landscape" ? "L" : "P"};}\n"
120
- split_at_section_break(docxml, sect, br, i)
122
+ def word_section_breaks1(docxml, sect)
123
+ docxml.xpath("//div[@class = '#{sect}']//br[@orientation]").reverse
124
+ .each_with_index do |br, i|
125
+ @landscapestyle +=
126
+ "\ndiv.#{sect}_#{i} {page:#{sect}"\
127
+ "#{br['orientation'] == 'landscape' ? 'L' : 'P'};}\n"
128
+ split_at_section_break(docxml, sect, br, i)
129
+ end
121
130
  end
122
- end
123
131
 
124
- def split_at_section_break(docxml, sect, br, i)
125
- move = br.parent.xpath("following::node()") &
126
- br.document.xpath("//div[@class = '#{sect}']//*")
127
- ins = docxml.at("//div[@class = '#{sect}']").after("<div class='#{sect}_#{i}'/>").next_element
128
- move.each do |m|
129
- next if m.at("./ancestor::div[@class = '#{sect}_#{i}']")
130
- ins << m.remove
132
+ def split_at_section_break(docxml, sect, brk, idx)
133
+ move = brk.parent.xpath("following::node()") &
134
+ brk.document.xpath("//div[@class = '#{sect}']//*")
135
+ ins = docxml.at("//div[@class = '#{sect}']")
136
+ .after("<div class='#{sect}_#{idx}'/>").next_element
137
+ move.each do |m|
138
+ next if m.at("./ancestor::div[@class = '#{sect}_#{idx}']")
139
+
140
+ ins << m.remove
141
+ end
131
142
  end
132
143
  end
133
144
  end
@@ -1,198 +1,201 @@
1
1
  require_relative "xref_gen_seq"
2
2
 
3
- module IsoDoc::XrefGen
4
- module Blocks
5
- NUMBERED_BLOCKS = %w(termnote termexample note example requirement
6
- recommendation permission figure table formula admonition sourcecode).freeze
7
-
8
- def amend_preprocess(xmldoc)
9
- xmldoc.xpath(ns("//amend[newcontent]")).each do |a|
10
- autonum = amend_autonums(a)
11
- NUMBERED_BLOCKS.each do |b|
12
- a.xpath(ns("./newcontent//#{b}")).each_with_index do |e, i|
13
- autonum[b] && i.zero? and e["number"] = autonum[b]
14
- !autonum[b] and e["unnumbered"] = "true"
3
+ module IsoDoc
4
+ module XrefGen
5
+ module Blocks
6
+ NUMBERED_BLOCKS = %w(termnote termexample note example requirement
7
+ recommendation permission figure table formula
8
+ admonition sourcecode).freeze
9
+
10
+ def amend_preprocess(xmldoc)
11
+ xmldoc.xpath(ns("//amend[newcontent]")).each do |a|
12
+ autonum = amend_autonums(a)
13
+ NUMBERED_BLOCKS.each do |b|
14
+ a.xpath(ns("./newcontent//#{b}")).each_with_index do |e, i|
15
+ autonum[b] && i.zero? and e["number"] = autonum[b]
16
+ !autonum[b] and e["unnumbered"] = "true"
17
+ end
15
18
  end
16
19
  end
17
20
  end
18
- end
19
21
 
20
- def amend_autonums(amend)
21
- autonum = {}
22
- amend.xpath(ns("./autonumber")).each do |n|
23
- autonum[n["type"]] = n.text
22
+ def amend_autonums(amend)
23
+ autonum = {}
24
+ amend.xpath(ns("./autonumber")).each do |n|
25
+ autonum[n["type"]] = n.text
26
+ end
27
+ autonum
24
28
  end
25
- autonum
26
- end
27
-
28
- def termnote_label(note)
29
- @labels["termnote"].gsub(/%/, note.to_s)
30
- end
31
29
 
32
- def increment_label(elems, node, counter, increment = true)
33
- return "" if elems.size == 1 && !node["number"]
30
+ def termnote_label(note)
31
+ @labels["termnote"].gsub(/%/, note.to_s)
32
+ end
34
33
 
35
- counter.increment(node) if increment
36
- " #{counter.print}"
37
- end
34
+ def increment_label(elems, node, counter, increment = true)
35
+ return "" if elems.size == 1 && !node["number"]
38
36
 
39
- def termnote_anchor_names(docxml)
40
- docxml.xpath(ns("//term[descendant::termnote]")).each do |t|
41
- c = Counter.new
42
- t.xpath(ns(".//termnote")).each do |n|
43
- next if n["id"].nil? || n["id"].empty?
37
+ counter.increment(node) if increment
38
+ " #{counter.print}"
39
+ end
44
40
 
45
- c.increment(n)
46
- @anchors[n["id"]] =
47
- { label: termnote_label(c.print), type: "termnote", value: c.print,
48
- xref: l10n("#{anchor(t['id'], :xref)}, "\
49
- "#{@labels['note_xref']} #{c.print}") }
41
+ def termnote_anchor_names(docxml)
42
+ docxml.xpath(ns("//term[descendant::termnote]")).each do |t|
43
+ c = Counter.new
44
+ t.xpath(ns(".//termnote")).each do |n|
45
+ next if n["id"].nil? || n["id"].empty?
46
+
47
+ c.increment(n)
48
+ @anchors[n["id"]] =
49
+ { label: termnote_label(c.print), type: "termnote", value: c.print,
50
+ xref: l10n("#{anchor(t['id'], :xref)}, "\
51
+ "#{@labels['note_xref']} #{c.print}") }
52
+ end
50
53
  end
51
54
  end
52
- end
53
55
 
54
- def termexample_anchor_names(docxml)
55
- docxml.xpath(ns("//term[descendant::termexample]")).each do |t|
56
- examples = t.xpath(ns(".//termexample"))
57
- c = Counter.new
58
- examples.each do |n|
59
- next if n["id"].nil? || n["id"].empty?
60
-
61
- c.increment(n)
62
- idx = increment_label(examples, n, c, false)
63
- @anchors[n["id"]] =
64
- { type: "termexample", label: idx, value: c.print,
65
- xref: l10n("#{anchor(t['id'], :xref)}, "\
66
- "#{@labels['example_xref']} #{c.print}") }
56
+ def termexample_anchor_names(docxml)
57
+ docxml.xpath(ns("//term[descendant::termexample]")).each do |t|
58
+ examples = t.xpath(ns(".//termexample"))
59
+ c = Counter.new
60
+ examples.each do |n|
61
+ next if n["id"].nil? || n["id"].empty?
62
+
63
+ c.increment(n)
64
+ idx = increment_label(examples, n, c, false)
65
+ @anchors[n["id"]] =
66
+ { type: "termexample", label: idx, value: c.print,
67
+ xref: l10n("#{anchor(t['id'], :xref)}, "\
68
+ "#{@labels['example_xref']} #{c.print}") }
69
+ end
67
70
  end
68
71
  end
69
- end
70
72
 
71
- SECTIONS_XPATH =
72
- "//foreword | //introduction | //acknowledgements | //preface/clause | "\
73
- "//preface/terms | preface/definitions | preface/references | "\
74
- "//sections/terms | //annex | "\
75
- "//sections/clause | //sections/definitions | "\
76
- "//bibliography/references | //bibliography/clause".freeze
73
+ SECTIONS_XPATH =
74
+ "//foreword | //introduction | //acknowledgements | "\
75
+ "//preface/terms | preface/definitions | preface/references | "\
76
+ "//preface/clause | //sections/terms | //annex | "\
77
+ "//sections/clause | //sections/definitions | "\
78
+ "//bibliography/references | //bibliography/clause".freeze
77
79
 
78
- def sections_xpath
79
- SECTIONS_XPATH
80
- end
80
+ def sections_xpath
81
+ SECTIONS_XPATH
82
+ end
81
83
 
82
- CHILD_NOTES_XPATH =
83
- "./*[not(self::xmlns:clause) and not(self::xmlns:appendix) and "\
84
- "not(self::xmlns:terms) and not(self::xmlns:definitions)]//xmlns:note | "\
85
- "./xmlns:note".freeze
84
+ CHILD_NOTES_XPATH =
85
+ "./*[not(self::xmlns:clause) and not(self::xmlns:appendix) and "\
86
+ "not(self::xmlns:terms) and not(self::xmlns:definitions)]//xmlns:note | "\
87
+ "./xmlns:note".freeze
86
88
 
87
- def note_anchor_names(sections)
88
- sections.each do |s|
89
- c = Counter.new
90
- (notes = s.xpath(CHILD_NOTES_XPATH)).each do |n|
91
- next if @anchors[n["id"]] || n["id"].nil? || n["id"].empty?
89
+ def note_anchor_names(sections)
90
+ sections.each do |s|
91
+ c = Counter.new
92
+ (notes = s.xpath(CHILD_NOTES_XPATH)).each do |n|
93
+ next if @anchors[n["id"]] || n["id"].nil? || n["id"].empty?
92
94
 
93
- @anchors[n["id"]] =
94
- anchor_struct(increment_label(notes, n, c), n,
95
- @labels["note_xref"], "note", false)
95
+ @anchors[n["id"]] =
96
+ anchor_struct(increment_label(notes, n, c), n,
97
+ @labels["note_xref"], "note", false)
98
+ end
99
+ note_anchor_names(s.xpath(ns(CHILD_SECTIONS)))
96
100
  end
97
- note_anchor_names(s.xpath(ns(CHILD_SECTIONS)))
98
101
  end
99
- end
100
102
 
101
- CHILD_EXAMPLES_XPATH =
102
- "./*[not(self::xmlns:clause) and not(self::xmlns:appendix) and "\
103
- "not(self::xmlns:terms) and not(self::xmlns:definitions)]//"\
104
- "xmlns:example | ./xmlns:example".freeze
103
+ CHILD_EXAMPLES_XPATH =
104
+ "./*[not(self::xmlns:clause) and not(self::xmlns:appendix) and "\
105
+ "not(self::xmlns:terms) and not(self::xmlns:definitions)]//"\
106
+ "xmlns:example | ./xmlns:example".freeze
105
107
 
106
- CHILD_SECTIONS = "./clause | ./appendix | ./terms | ./definitions | "\
107
- "./references".freeze
108
+ CHILD_SECTIONS = "./clause | ./appendix | ./terms | ./definitions | "\
109
+ "./references".freeze
108
110
 
109
- def example_anchor_names(sections)
110
- sections.each do |s|
111
- c = Counter.new
112
- (notes = s.xpath(CHILD_EXAMPLES_XPATH)).each do |n|
113
- next if @anchors[n["id"]] || n["id"].nil? || n["id"].empty?
111
+ def example_anchor_names(sections)
112
+ sections.each do |s|
113
+ c = Counter.new
114
+ (notes = s.xpath(CHILD_EXAMPLES_XPATH)).each do |n|
115
+ next if @anchors[n["id"]] || n["id"].nil? || n["id"].empty?
114
116
 
115
- @anchors[n["id"]] =
116
- anchor_struct(increment_label(notes, n, c), n,
117
- @labels["example_xref"], "example", n["unnumbered"])
117
+ @anchors[n["id"]] =
118
+ anchor_struct(increment_label(notes, n, c), n,
119
+ @labels["example_xref"], "example", n["unnumbered"])
120
+ end
121
+ example_anchor_names(s.xpath(ns(CHILD_SECTIONS)))
118
122
  end
119
- example_anchor_names(s.xpath(ns(CHILD_SECTIONS)))
120
123
  end
121
- end
122
-
123
- def list_anchor_names(sections)
124
- sections.each do |s|
125
- notes = s.xpath(ns(".//ol")) - s.xpath(ns(".//clause//ol")) -
126
- s.xpath(ns(".//appendix//ol")) - s.xpath(ns(".//ol//ol"))
127
- c = Counter.new
128
- notes.each do |n|
129
- next if n["id"].nil? || n["id"].empty?
130
124
 
131
- @anchors[n["id"]] = anchor_struct(increment_label(notes, n, c), n,
132
- @labels["list"], "list", false)
133
- list_item_anchor_names(n, @anchors[n["id"]], 1, "", notes.size != 1)
125
+ def list_anchor_names(sections)
126
+ sections.each do |s|
127
+ notes = s.xpath(ns(".//ol")) - s.xpath(ns(".//clause//ol")) -
128
+ s.xpath(ns(".//appendix//ol")) - s.xpath(ns(".//ol//ol"))
129
+ c = Counter.new
130
+ notes.each do |n|
131
+ next if n["id"].nil? || n["id"].empty?
132
+
133
+ @anchors[n["id"]] = anchor_struct(increment_label(notes, n, c), n,
134
+ @labels["list"], "list", false)
135
+ list_item_anchor_names(n, @anchors[n["id"]], 1, "", notes.size != 1)
136
+ end
137
+ list_anchor_names(s.xpath(ns(CHILD_SECTIONS)))
134
138
  end
135
- list_anchor_names(s.xpath(ns(CHILD_SECTIONS)))
136
139
  end
137
- end
138
140
 
139
- def list_item_anchor_names(list, list_anchor, depth, prev_label, refer_list)
140
- c = Counter.new(list["start"] ? list["start"].to_i - 1 : 0)
141
- list.xpath(ns("./li")).each do |li|
142
- label = c.increment(li).listlabel(list, depth)
143
- label = "#{prev_label}.#{label}" unless prev_label.empty?
144
- label = "#{list_anchor[:xref]} #{label}" if refer_list
145
- li["id"] and @anchors[li["id"]] =
146
- { xref: "#{label})", type: "listitem",
147
- container: list_anchor[:container] }
148
- li.xpath(ns("./ol")).each do |ol|
149
- list_item_anchor_names(ol, list_anchor, depth + 1, label, false)
141
+ def list_item_anchor_names(list, list_anchor, depth, prev_label, refer_list)
142
+ c = Counter.new(list["start"] ? list["start"].to_i - 1 : 0)
143
+ list.xpath(ns("./li")).each do |li|
144
+ label = c.increment(li).listlabel(list, depth)
145
+ label = "#{prev_label}.#{label}" unless prev_label.empty?
146
+ label = "#{list_anchor[:xref]} #{label}" if refer_list
147
+ li["id"] and @anchors[li["id"]] =
148
+ { xref: "#{label})", type: "listitem",
149
+ container: list_anchor[:container] }
150
+ li.xpath(ns("./ol")).each do |ol|
151
+ list_item_anchor_names(ol, list_anchor, depth + 1, label, false)
152
+ end
150
153
  end
151
154
  end
152
- end
153
155
 
154
- def deflist_anchor_names(sections)
155
- sections.each do |s|
156
- notes = s.xpath(ns(".//dl")) - s.xpath(ns(".//clause//dl")) -
157
- s.xpath(ns(".//appendix//dl")) - s.xpath(ns(".//dl//dl"))
158
- c = Counter.new
159
- notes.each do |n|
160
- next if n["id"].nil? || n["id"].empty?
161
-
162
- @anchors[n["id"]] =
163
- anchor_struct(increment_label(notes, n, c), n,
164
- @labels["deflist"], "deflist", false)
165
- deflist_term_anchor_names(n, @anchors[n["id"]])
156
+ def deflist_anchor_names(sections)
157
+ sections.each do |s|
158
+ notes = s.xpath(ns(".//dl")) - s.xpath(ns(".//clause//dl")) -
159
+ s.xpath(ns(".//appendix//dl")) - s.xpath(ns(".//dl//dl"))
160
+ c = Counter.new
161
+ notes.each do |n|
162
+ next if n["id"].nil? || n["id"].empty?
163
+
164
+ @anchors[n["id"]] =
165
+ anchor_struct(increment_label(notes, n, c), n,
166
+ @labels["deflist"], "deflist", false)
167
+ deflist_term_anchor_names(n, @anchors[n["id"]])
168
+ end
169
+ deflist_anchor_names(s.xpath(ns(CHILD_SECTIONS)))
166
170
  end
167
- deflist_anchor_names(s.xpath(ns(CHILD_SECTIONS)))
168
171
  end
169
- end
170
172
 
171
- def deflist_term_anchor_names(list, list_anchor)
172
- list.xpath(ns("./dt")).each do |li|
173
- label = li.text
174
- label = l10n("#{list_anchor[:xref]}: #{label}")
175
- li["id"] and @anchors[li["id"]] =
176
- { xref: label, type: "deflistitem",
177
- container: list_anchor[:container] }
178
- li.xpath(ns("./dl")).each do |dl|
179
- deflist_term_anchor_names(dl, list_anchor)
173
+ def deflist_term_anchor_names(list, list_anchor)
174
+ list.xpath(ns("./dt")).each do |li|
175
+ label = li.text
176
+ label = l10n("#{list_anchor[:xref]}: #{label}")
177
+ li["id"] and @anchors[li["id"]] =
178
+ { xref: label, type: "deflistitem",
179
+ container: list_anchor[:container] }
180
+ li.xpath(ns("./dl")).each do |dl|
181
+ deflist_term_anchor_names(dl, list_anchor)
182
+ end
180
183
  end
181
184
  end
182
- end
183
185
 
184
- def bookmark_anchor_names(docxml)
185
- docxml.xpath(ns(".//bookmark")).each do |n|
186
- next if n["id"].nil? || n["id"].empty?
186
+ def bookmark_anchor_names(docxml)
187
+ docxml.xpath(ns(".//bookmark")).each do |n|
188
+ next if n["id"].nil? || n["id"].empty?
187
189
 
188
- parent = nil
189
- n.ancestors.each do |a|
190
- next unless a["id"] && parent = @anchors.dig(a["id"], :xref)
190
+ parent = nil
191
+ n.ancestors.each do |a|
192
+ next unless a["id"] && parent = @anchors.dig(a["id"], :xref)
191
193
 
192
- break
194
+ break
195
+ end
196
+ @anchors[n["id"]] = { type: "bookmark", label: nil, value: nil,
197
+ xref: parent || "???" }
193
198
  end
194
- @anchors[n["id"]] = { type: "bookmark", label: nil, value: nil,
195
- xref: parent || "???" }
196
199
  end
197
200
  end
198
201
  end