-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
use Asciidoc for termdef boilerplate: metanorma/metanorma-iec#339
- Loading branch information
Showing
6 changed files
with
248 additions
and
121 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
gem "isodoc", git: "https://github.com/metanorma/isodoc", branch: "fix/yaml-no-xml" |
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
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,106 @@ | ||
module Metanorma | ||
module Standoc | ||
module Cleanup | ||
def external_terms_boilerplate(sources) | ||
e = @i18n.external_terms_boilerplate | ||
e.gsub(/%(?=\p{P}|\p{Z}|$)/, sources || "???") | ||
end | ||
|
||
def internal_external_terms_boilerplate(sources) | ||
e = @i18n.internal_external_terms_boilerplate | ||
e.gsub(/%(?=\p{P}|\p{Z}|$)/, sources || "??") | ||
end | ||
|
||
def boilerplate_snippet_convert(adoc) | ||
ret = boilerplate_xml_cleanup(adoc2xml(adoc, backend.to_sym)) | ||
@i18n.l10n(ret.children.to_xml, @lang, @script) | ||
end | ||
|
||
def term_defs_boilerplate(div, source, term, _preface, isodoc) | ||
verify_term_defs_source(source) | ||
a = @i18n.term_def_boilerplate and | ||
div.next = boilerplate_snippet_convert(a) | ||
a = if source.empty? && term.nil? then @i18n.no_terms_boilerplate | ||
else term_defs_boilerplate_cont(source, term, isodoc) | ||
end | ||
a and div.next = boilerplate_snippet_convert(a) | ||
end | ||
|
||
def verify_term_defs_source(source) | ||
source.each do |s| | ||
@anchors[s["bibitemid"]] or | ||
@log.add("Crossreferences", nil, | ||
"term source #{s['bibitemid']} not referenced", | ||
severity: 1) | ||
end | ||
end | ||
|
||
def term_defs_boilerplate_cont(src, term, isodoc) | ||
sources = isodoc.sentence_join(src.map do |s| | ||
%{<<#{s['bibitemid']}>>} | ||
end) | ||
if src.empty? then @i18n.internal_terms_boilerplate | ||
elsif term.nil? then external_terms_boilerplate(sources) | ||
else | ||
internal_external_terms_boilerplate(sources) | ||
end | ||
end | ||
|
||
TERM_CLAUSE = | ||
"//sections//terms[not(.//ancestor::clause[@type = 'terms'])] | " \ | ||
"//sections/clause[descendant::terms][@type = 'terms'] | " \ | ||
"//sections/clause[not(@type = 'terms')]//terms".freeze | ||
|
||
def termdef_boilerplate_cleanup(xmldoc) | ||
# termdef_remove_initial_paras(xmldoc) | ||
end | ||
|
||
def termdef_remove_initial_paras(xmldoc) | ||
xmldoc.xpath("//terms/p | //terms/ul").each(&:remove) | ||
end | ||
|
||
def termdef_boilerplate_insert(xmldoc, isodoc, once = false) | ||
if once | ||
f = termdef_boilerplate_insert_location(xmldoc) and | ||
termdef_boilerplate_insert1(f, xmldoc, isodoc) | ||
else | ||
xmldoc.xpath(self.class::TERM_CLAUSE).each do |f| | ||
termdef_boilerplate_insert1(f, xmldoc, isodoc) | ||
end | ||
end | ||
end | ||
|
||
def termdef_boilerplate_insert_location(xmldoc) | ||
f = xmldoc.at(self.class::TERM_CLAUSE) | ||
root = xmldoc.at("//sections/terms | //sections/clause[@type = 'terms']") | ||
if f && root && f["id"] != root["id"] | ||
f = termdef_boilerplate_climb_up(f, root) | ||
elsif !f && root then f = root | ||
end | ||
f | ||
end | ||
|
||
def termdef_boilerplate_climb_up(clause, container) | ||
container.at(".//*[@id = '#{clause['id']}']") or return clause | ||
while (n = clause.parent) | ||
n.at(".//definitions") and break | ||
clause = n | ||
n["id"] == container["id"] and break | ||
end | ||
clause | ||
end | ||
|
||
def termdef_boilerplate_insert1(sect, xmldoc, isodoc) | ||
ins = sect.at("./title") | ||
if (ins2 = sect.at("./clause[@type = 'boilerplate'] | " \ | ||
"./note[@type = 'boilerplate']")) | ||
ins2.text.strip.downcase == "(default)" or return | ||
ins2.children = " " | ||
ins = ins2.children.first | ||
end | ||
term_defs_boilerplate(ins, xmldoc.xpath(".//termdocsource"), | ||
sect.at(".//term"), sect.at(".//p"), isodoc) | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.