diff --git a/lib/isodoc/presentation_function/section.rb b/lib/isodoc/presentation_function/section.rb
index 6dfc058b..b78a229f 100644
--- a/lib/isodoc/presentation_function/section.rb
+++ b/lib/isodoc/presentation_function/section.rb
@@ -1,24 +1,8 @@
require_relative "refs"
+require_relative "title"
module IsoDoc
class PresentationXMLConvert < ::IsoDoc::Convert
- def middle_title(docxml)
- s = docxml.at(ns("//sections")) or return
- t = @meta.get[:doctitle]
- t.nil? || t.empty? and return
- s.add_first_child "
#{t}
"
- end
-
- def missing_title(docxml)
- docxml.xpath(ns("//definitions[not(./title)]")).each do |d|
- # should only be happening for subclauses
- d.add_first_child "#{@i18n.symbols}"
- end
- docxml.xpath(ns("//foreword[not(./title)]")).each do |d|
- d.add_first_child "#{@i18n.foreword}"
- end
- end
-
def clause(docxml)
docxml.xpath(ns("//clause | //terms | //definitions | //references | " \
"//introduction | //foreword | //preface/abstract | " \
@@ -57,24 +41,6 @@ def clause1(elem)
t = elem.at(ns("./fmt-title")) and t["depth"] = level
end
- def floattitle(docxml)
- p = "//clause | //annex | //appendix | //introduction | //foreword | " \
- "//preface/abstract | //acknowledgements | //terms | " \
- "//definitions | //references | //colophon | //indexsect"
- docxml.xpath(ns(p)).each { |f| floattitle1(f) }
- # top-level
- docxml.xpath(ns("//sections | //preface | //colophon"))
- .each { |f| floattitle1(f) }
- end
-
- # TODO not currently doing anything with the @depth attribute of floating-title
- def floattitle1(elem)
- elem.xpath(ns(".//floating-title")).each do |p|
- p.name = "p"
- p["type"] = "floating-title"
- end
- end
-
def annex(docxml)
docxml.xpath(ns("//annex")).each do |f|
@xrefs.klass.single_term_clause?(f) and single_term_clause_retitle(f)
@@ -134,19 +100,6 @@ def display_order_xpath(docxml, xpath, idx)
idx
end
- def preceding_floating_titles(node, idx)
- out = node.xpath("./preceding-sibling::*")
- .reverse.each_with_object([]) do |p, m|
- %w(note admonition p).include?(p.name) or break m
- m << p
- end
- out.reject { |c| c["displayorder"] }.reverse_each do |c|
- c["displayorder"] = idx
- idx += 1
- end
- idx
- end
-
def display_order(docxml)
i = 0
d = @xrefs.clause_order(docxml)
@@ -160,27 +113,6 @@ def display_order(docxml)
end
end
- def clausetitle(docxml)
- cjk_extended_title(docxml)
- end
-
- def cjk_search
- lang = %w(zh ja ko).map { |x| "@language = '#{x}'" }.join(" or ")
- %(Hans Hant Jpan Hang Kore).include?(@script) and
- lang += " or not(@language)"
- lang
- end
-
- def cjk_extended_title(doc)
- l = cjk_search
- doc.xpath(ns("//bibdata/title[#{l}] | //floating-title[#{l}] | " \
- "//fmt-title[@depth = '1' or not(@depth)][#{l}]")).each do |t|
- t.text.size < 4 or next
- t.elements.empty? or next # can't be bothered
- t.children = @i18n.cjk_extend(t.text)
- end
- end
-
def preface_rearrange(doc)
preface_move(doc.at(ns("//preface/abstract")),
%w(foreword introduction clause acknowledgements), doc)
@@ -214,41 +146,11 @@ def preface_move1(clause, preface, float, prev, xpath)
end
end
- def preceding_floats(clause)
- ret = []
- p = clause
- while prev = p.previous_element
- if prev.name == "floating-title"
- ret << prev
- p = prev
- else break end
- end
- ret
- end
-
def rearrange_clauses(docxml)
preface_rearrange(docxml) # feeds toc_title
toc_title(docxml)
end
- def toc_title(docxml)
- docxml.at(ns("//preface/clause[@type = 'toc']")) and return
- ins = toc_title_insert_pt(docxml) or return
- id = UUIDTools::UUID.random_create.to_s
- ins.previous = <<~CLAUSE
- #{@i18n.table_of_contents}
- CLAUSE
- end
-
- def toc_title_insert_pt(docxml)
- ins = docxml.at(ns("//preface")) ||
- docxml.at(ns("//sections | //annex | //bibliography"))
- &.before(" ")
- &.previous_element or return nil
- ins.children.empty? and ins << " "
- ins.children.first
- end
-
def toc(docxml)
toc_refs(docxml)
end
diff --git a/lib/isodoc/presentation_function/title.rb b/lib/isodoc/presentation_function/title.rb
new file mode 100644
index 00000000..9e7ce868
--- /dev/null
+++ b/lib/isodoc/presentation_function/title.rb
@@ -0,0 +1,107 @@
+require_relative "refs"
+
+module IsoDoc
+ class PresentationXMLConvert < ::IsoDoc::Convert
+ def middle_title(docxml)
+ s = docxml.at(ns("//sections")) or return
+ t = @meta.get[:doctitle]
+ t.nil? || t.empty? and return
+ s.add_first_child "#{t}
"
+ end
+
+ def missing_title(docxml)
+ docxml.xpath(ns("//definitions[not(./title)]")).each do |d|
+ # should only be happening for subclauses
+ d.add_first_child "#{@i18n.symbols}"
+ end
+ docxml.xpath(ns("//foreword[not(./title)]")).each do |d|
+ d.add_first_child "#{@i18n.foreword}"
+ end
+ end
+
+ def floattitle(docxml)
+ p = "//clause | //annex | //appendix | //introduction | //foreword | " \
+ "//preface/abstract | //acknowledgements | //terms | " \
+ "//definitions | //references | //colophon | //indexsect"
+ docxml.xpath(ns(p)).each { |f| floattitle1(f) }
+ # top-level
+ docxml.xpath(ns("//sections | //preface | //colophon"))
+ .each { |f| floattitle1(f) }
+ end
+
+ # TODO not currently doing anything with the @depth attribute of floating-title
+ def floattitle1(elem)
+ elem.xpath(ns(".//floating-title")).each do |p|
+ p.name = "p"
+ p["type"] = "floating-title"
+ end
+ end
+
+ def preceding_floating_titles(node, idx)
+ out = node.xpath("./preceding-sibling::*")
+ .reverse.each_with_object([]) do |p, m|
+ %w(note admonition p).include?(p.name) or break m
+ m << p
+ end
+ out.reject { |c| c["displayorder"] }.reverse_each do |c|
+ c["displayorder"] = idx
+ idx += 1
+ end
+ idx
+ end
+
+ def clausetitle(docxml)
+ cjk_extended_title(docxml)
+ end
+
+ def cjk_search
+ lang = %w(zh ja ko).map { |x| "@language = '#{x}'" }.join(" or ")
+ %(Hans Hant Jpan Hang Kore).include?(@script) and
+ lang += " or not(@language)"
+ lang
+ end
+
+ def cjk_extended_title(doc)
+ l = cjk_search
+ doc.xpath(ns("//bibdata/title[#{l}] | //floating-title[#{l}] | " \
+ "//fmt-title[@depth = '1' or not(@depth)][#{l}]"))
+ .each do |t|
+ t.text.size < 4 or next
+ t.traverse do |n|
+ n.text? or next
+ n.replace(@i18n.cjk_extend(n.text))
+ end
+ end
+ end
+
+ def preceding_floats(clause)
+ ret = []
+ p = clause
+ while prev = p.previous_element
+ if prev.name == "floating-title"
+ ret << prev
+ p = prev
+ else break end
+ end
+ ret
+ end
+
+ def toc_title(docxml)
+ docxml.at(ns("//preface/clause[@type = 'toc']")) and return
+ ins = toc_title_insert_pt(docxml) or return
+ id = UUIDTools::UUID.random_create.to_s
+ ins.previous = <<~CLAUSE
+ #{@i18n.table_of_contents}
+ CLAUSE
+ end
+
+ def toc_title_insert_pt(docxml)
+ ins = docxml.at(ns("//preface")) ||
+ docxml.at(ns("//sections | //annex | //bibliography"))
+ &.before(" ")
+ &.previous_element or return nil
+ ins.children.empty? and ins << " "
+ ins.children.first
+ end
+ end
+end
diff --git a/spec/isodoc/i18n_spec.rb b/spec/isodoc/i18n_spec.rb
index 66ab9c5e..5f9df8ec 100644
--- a/spec/isodoc/i18n_spec.rb
+++ b/spec/isodoc/i18n_spec.rb
@@ -1315,51 +1315,96 @@
INPUT
presxml = <<~OUTPUT
-
-
- zh
-
-
-
-
-
- 版 權
-
-
- 版權聲明
-
-
- 版 權
-
-
-
-
-
- 目 次
-
- 樣 板
-
- 解 題
-
-
- 文件序言
- This is a preamble
-
- 介紹性陳述
-
- 簡 介
-
- 引言部分
-
- 附則
+
+
+ zh
+
+
+
+
+
+ 版權
+
+
+ 版 權
+
+
+
+
+ 版權聲明
+
+
+ 版權聲明
+
+
+
+
+ 版權
+
+
+ 版 權
+
+
+
+
+
+
+
+ 目 次
-
-
- Ad
-
-
-
-
+ 樣 板
+
+ 解題
+
+
+ 解 題
+
+
+
+
+ 文件序言
+
+
+ 文件序言
+
+
+ This is a preamble
+
+ 介紹性陳述
+
+ 簡介
+
+
+ 簡 介
+
+
+
+ 引言部分
+
+
+ 引言部分
+
+
+
+ 附則
+
+
+ 附則
+
+
+
+
+
+ Ad
+
+
+ Ad
+
+
+
+
+
+
OUTPUT
expect(Xml::C14n.format(strip_guid(IsoDoc::PresentationXMLConvert
.new(presxml_options).convert("test", input, true)