lib/isodoc/presentation_function/section.rb in isodoc-2.5.3 vs lib/isodoc/presentation_function/section.rb in isodoc-2.5.4
- old
+ new
@@ -122,12 +122,106 @@
i = display_order_xpath(docxml, @xrefs.klass.bibliography_xpath, i)
i = display_order_xpath(docxml, "//indexsect", i)
display_order_xpath(docxml, "//colophon/*", i)
end
- def clausetitle(docxml); 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(docxml)
+ l = cjk_search
+ docxml.xpath(ns("//bibdata/title[#{l}] | //floating-title[#{l}] | " \
+ "//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)
+ preface_move(doc.at(ns("//preface/foreword")),
+ %w(introduction clause acknowledgements), doc)
+ preface_move(doc.at(ns("//preface/introduction")),
+ %w(clause acknowledgements), doc)
+ preface_move(doc.at(ns("//preface/acknowledgements")),
+ %w(), doc)
+ end
+
+ def preface_move(clause, after, _doc)
+ clause or return
+ preface = clause.parent
+ float = preceding_floats(clause)
+ prev = nil
+ xpath = after.map { |n| "./self::xmlns:#{n}" }.join(" | ")
+ xpath.empty? and xpath = "./self::*[not(following-sibling::*)]"
+ preface_move1(clause, preface, float, prev, xpath)
+ end
+
+ def preface_move1(clause, preface, float, prev, xpath)
+ preface.elements.each do |x|
+ ((x.name == "floating-title" || x.at(xpath)) &&
+ xpath != "./self::*[not(following-sibling::*)]") or prev = x
+ # after.include?(x.name) or next
+ x.at(xpath) or next
+ clause == prev and break
+ prev ||= preface.children.first
+ float << clause
+ float.each { |n| prev.next = n }
+ break
+ 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
+ <clause type = 'toc' id='_#{id}'><title depth='1'>#{@i18n.table_of_contents}</title></clause>
+ CLAUSE
+ end
+
+ def toc_title_insert_pt(docxml)
+ ins = docxml.at(ns("//preface")) ||
+ docxml.at(ns("//sections | //annex | //bibliography"))
+ &.before("<preface> </preface>")
+ &.previous_element or return nil
+ ins.children.empty? and ins << " "
+ ins.children.first
+ end
+
def toc(docxml)
+ toc_refs(docxml)
+ end
+
+ def toc_refs(docxml)
docxml.xpath(ns("//toc//xref[text()]")).each do |x|
lbl = @xrefs.anchor(x["target"], :label) or next
x.children.first.previous = "#{lbl}<tab/>"
end
end