-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
deal with XML when doing CJK extend on titles: #617
- Loading branch information
Showing
3 changed files
with
197 additions
and
143 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 "<p class='zzSTDTitle1'>#{t}</p>" | ||
end | ||
|
||
def missing_title(docxml) | ||
docxml.xpath(ns("//definitions[not(./title)]")).each do |d| | ||
# should only be happening for subclauses | ||
d.add_first_child "<title>#{@i18n.symbols}</title>" | ||
end | ||
docxml.xpath(ns("//foreword[not(./title)]")).each do |d| | ||
d.add_first_child "<title>#{@i18n.foreword}</title>" | ||
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 | ||
<clause type = 'toc' id='_#{id}'><fmt-title depth='1'>#{@i18n.table_of_contents}</fmt-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 | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters