Class: IsoDoc::PresentationXMLConvert
- Inherits:
-
Convert
show all
- Defined in:
- lib/isodoc/presentation_xml_convert.rb,
lib/isodoc/presentation_function/math.rb,
lib/isodoc/presentation_function/refs.rb,
lib/isodoc/presentation_function/block.rb,
lib/isodoc/presentation_function/erefs.rb,
lib/isodoc/presentation_function/image.rb,
lib/isodoc/presentation_function/terms.rb,
lib/isodoc/presentation_function/xrefs.rb,
lib/isodoc/presentation_function/inline.rb,
lib/isodoc/presentation_function/bibdata.rb,
lib/isodoc/presentation_function/section.rb,
lib/isodoc/presentation_function/sourcecode.rb
Constant Summary
collapse
- MATHML =
{ "m" => "http://www.w3.org/1998/Math/MathML" }.freeze
- REQS =
%w(requirement recommendation permission).freeze
- SVG =
{ "m" => "http://www.w3.org/2000/svg" }.freeze
Function::Utils::CLAUSE_ANCESTOR, Function::Utils::DOCTYPE_HDR, Function::Utils::HUGESTRICT, Function::Utils::NOTE_CONTAINER_ANCESTOR
Function::Table::SW
Function::Section::TERM_CLAUSE
Function::References::SKIP_DOC1, Function::References::SKIP_DOCID
Function::Lists::OL_STYLE
Function::Cleanup::FIGURE_WITH_FOOTNOTES
Function::Blocks::EXAMPLE_TBL_ATTR, Function::Blocks::EXAMPLE_TD_ATTR
Instance Attribute Summary
Attributes inherited from Convert
#i18n, #meta, #options, #reqt_models, #requirements_processor, #xrefs
Instance Method Summary
collapse
-
#address_precompose(bib) ⇒ Object
-
#address_precompose1(addr) ⇒ Object
-
#admonition(docxml) ⇒ Object
-
#admonition1(elem) ⇒ Object
-
#admonition_numbered1(elem) ⇒ Object
-
#amend(docxml) ⇒ Object
we use this to eliminate the semantic amend blocks from rendering.
-
#amend1(elem) ⇒ Object
-
#anchor_id_postproc(node) ⇒ Object
-
#anchor_id_postprocess(node) ⇒ Object
-
#anchor_linkend(node, linkend) ⇒ Object
-
#anchor_linkend1(node) ⇒ Object
-
#anchor_value(id) ⇒ Object
-
#anchor_xref(node, target) ⇒ Object
-
#anchor_xref_full(num, title) ⇒ Object
-
#annex(docxml) ⇒ Object
-
#annex1(elem) ⇒ Object
-
#asciimath_dup(node) ⇒ Object
-
#bibdata(docxml) ⇒ Object
-
#bibdata_current(docxml) ⇒ Object
-
#bibdata_i18n(bib) ⇒ Object
-
#bibitem(xml, renderings) ⇒ Object
-
#biblio_ref_entry_code(ordinal, ids, _id, standard, datefn, _bib) ⇒ Object
if ids is just a number, only use that ([1] Non-Standard) else, use both ordinal, as prefix, and ids.
-
#bibliography_bibitem_number(docxml) ⇒ Object
-
#bibliography_bibitem_number1(bibitem, idx) ⇒ Object
-
#bibliography_bibitem_number_insert_pt(bibitem) ⇒ Object
-
#bibliography_bibitem_number_skip(bibitem) ⇒ Object
-
#bibliography_bibitem_tag(docxml) ⇒ Object
-
#bibliography_bibitem_tag1(ref, idx, norm) ⇒ Object
-
#bibrender(xml, renderings) ⇒ Object
-
#bibrender_formattedref(formattedref, xml) ⇒ Object
-
#bibrender_relaton(xml, renderings) ⇒ Object
-
#bibrenderer ⇒ Object
-
#blank?(elem) ⇒ Boolean
-
#block(docxml) ⇒ Object
-
#block_delim ⇒ Object
-
#cache_dataimage(uri) ⇒ Object
-
#can_conflate_eref_rendering?(refs) ⇒ Boolean
-
#can_conflate_xref_rendering?(locs) ⇒ Boolean
-
#capitalise_xref(node, linkend, label) ⇒ Object
-
#capitalise_xref1(node, linkend) ⇒ Object
-
#citestyle ⇒ Object
-
#clause(docxml) ⇒ Object
-
#clause1(elem) ⇒ Object
-
#clausetitle(docxml) ⇒ Object
-
#combine_conflated_xref_locations(locs) ⇒ Object
-
#combine_conflated_xref_locations_container(locs, ret) ⇒ Object
-
#combine_conn(list) ⇒ Object
-
#combine_xref_locations(node) ⇒ Object
-
#concept(docxml) ⇒ Object
-
#concept1(node) ⇒ Object
-
#concept1_linkmention(ref, renderterm, opts) ⇒ Object
-
#concept1_ref(_node, ref, opts) ⇒ Object
-
#concept1_ref_content(ref) ⇒ Object
-
#concept1_style(node, opts) ⇒ Object
-
#concept_render(node, defaults) ⇒ Object
-
#concept_render_init(node, defaults) ⇒ Object
-
#conversions(docxml) ⇒ Object
-
#convert1(docxml, _filename, _dir) ⇒ Object
-
#custom_css(docxml) ⇒ Object
-
#date_note_process(bib) ⇒ Object
strip any fns in docidentifier before they are extracted for rendering.
-
#decorate_fraction_part(fract, locale) ⇒ Object
-
#designation(docxml) ⇒ Object
-
#designation1(desgn) ⇒ Object
-
#designation_annotate(desgn, name) ⇒ Object
-
#designation_boldface(desgn) ⇒ Object
-
#designation_field(desgn, name) ⇒ Object
-
#designation_grammar(grammar) ⇒ Object
-
#designation_localization(desgn, name) ⇒ Object
-
#designation_pronunciation(desgn, name) ⇒ Object
-
#display_order(docxml) ⇒ Object
-
#display_order_at(docxml, xpath, idx) ⇒ Object
-
#display_order_xpath(docxml, xpath, idx) ⇒ Object
-
#docid_prefixes(docxml) ⇒ Object
-
#edition_translate(bibdata) ⇒ Object
does not allow %Spellout and %Ordinal in the ordinal expression to be mixed.
-
#edition_translate1(num) ⇒ Object
-
#embedable_semantic_xml(xml) ⇒ Object
-
#embedable_semantic_xml_attributes(xml) ⇒ Object
-
#embedable_semantic_xml_tags(xml) ⇒ Object
-
#emf_encode(img) ⇒ Object
-
#emf_to_svg(img) ⇒ Object
-
#eps2svg(img) ⇒ Object
-
#eps_to_svg(node) ⇒ Object
-
#eps_to_svg_uri(node) ⇒ Object
-
#eps_to_svg_uri_convert(node) ⇒ Object
-
#eref(docxml) ⇒ Object
-
#eref_localities(refs, target, node) ⇒ Object
-
#eref_localities0(ref, _idx, target, node) ⇒ Object
-
#eref_localities1(opt) ⇒ Object
def eref_localities1(target, type, from, upto, node, lang = “en”).
-
#eref_localities1_zh(opt) ⇒ Object
def eref_localities1_zh(_target, type, from, upto, node).
-
#eref_localities_conflated(refs, target, node) ⇒ Object
-
#eref_locality_delimiter(ref) ⇒ Object
-
#eref_locality_populate(type, node, number) ⇒ Object
-
#eref_locality_stack(ref, idx, target, node) ⇒ Object
-
#eref_locality_stack1(ref, target, node, ret) ⇒ Object
-
#eref_locality_stacks(refs, target, node) ⇒ Object
-
#erefstack1(elem) ⇒ Object
-
#example(docxml) ⇒ Object
-
#example1(elem) ⇒ Object
-
#expand_citeas(text) ⇒ Object
-
#figure(docxml) ⇒ Object
-
#figure1(elem) ⇒ Object
-
#figure_label(elem) ⇒ Object
-
#floattitle(docxml) ⇒ Object
-
#floattitle1(elem) ⇒ Object
-
#fonts_metadata(xmldoc) ⇒ Object
-
#formula(docxml) ⇒ Object
-
#formula1(elem) ⇒ Object
-
#formula_where(dlist) ⇒ Object
-
#gather_xref_locations(node) ⇒ Object
-
#get_linkend(node) ⇒ Object
-
#hash_translate(bibdata, hash, xpath, lang = @lang) ⇒ Object
-
#hidden_items(docxml) ⇒ Object
-
#i18n_chain_boolean(value, entry) ⇒ Object
-
#i18n_safe(key) ⇒ Object
-
#i18n_tag(key, value) ⇒ Object
-
#i8n_name(hash, pref) ⇒ Object
-
#i8n_name1(hash, pref) ⇒ Object
-
#ident_fn(bib) ⇒ Object
-
#identifier(docxml) ⇒ Object
-
#imageconvert(docxml) ⇒ Object
-
#imgfile_suffix(uri, suffix) ⇒ Object
-
#index(docxml) ⇒ Object
-
#initialize(options) ⇒ PresentationXMLConvert
constructor
A new instance of PresentationXMLConvert.
-
#inkscape_convert(uri, file, option) ⇒ Object
-
#inkscape_installed? ⇒ Boolean
-
#inline(docxml) ⇒ Object
-
#insert_biblio_tag(bib, ordinal, biblio, standard) ⇒ Object
-
#loc2xref(entry) ⇒ Object
-
#locality_delimiter(_loc) ⇒ Object
-
#localize_maths(node, locale) ⇒ Object
symbols is merged into TwitterCldr::DataReaders::NumberDataReader.new(locale).symbols.
-
#localized_number(num, locale, precision) ⇒ Object
By itself twitter-cldr does not support fraction part digits grouping and custom delimeter, will decorate fraction part manually.
-
#localized_number1(num, locale, precision) ⇒ Object
-
#lower2cap(text) ⇒ Object
-
#mathml(docxml) ⇒ Object
-
#mathml1(node, locale) ⇒ Object
-
#mathml_number_to_number(node) ⇒ Object
-
#mathml_style_inherit(node) ⇒ Object
-
#merge_preferred_eligible?(first, second) ⇒ Boolean
-
#merge_second_preferred(term) ⇒ Object
-
#merge_second_preferred1(pref, second) ⇒ Object
-
#metanorma_extension_insert_pt(xml) ⇒ Object
-
#multidef(elem) ⇒ Object
-
#non_locality_elems(node) ⇒ Object
-
#norm_ref_entry_code(_ordinal, idents, _ids, _standard, datefn, _bib) ⇒ Object
-
#note(docxml) ⇒ Object
-
#note1(elem) ⇒ Object
-
#ol(docxml) ⇒ Object
-
#ol1(elem) ⇒ Object
-
#ol_depth(node) ⇒ Object
We don’t really want users to specify type of ordered list; we will use by default a fixed hierarchy as practiced by ISO (though not fully spelled out): a) 1) i) A) I).
-
#origin(docxml) ⇒ Object
-
#parse_localize_number ⇒ Object
-
#permission(docxml) ⇒ Object
-
#postprocess(result, filename, _dir) ⇒ Object
-
#prefix_bracketed_ref(text) ⇒ Object
-
#prefix_container(container, linkend, node, _target) ⇒ Object
-
#prefix_container?(container, node) ⇒ Boolean
-
#prefix_name(node, delim, number, elem) ⇒ Object
-
#prep_for_rendering(bib) ⇒ Object
-
#presmeta(name, value) ⇒ Object
-
#quotesource(docxml) ⇒ Object
-
#recommendation(docxml) ⇒ Object
-
#recommendation1(elem, type) ⇒ Object
-
#references(docxml) ⇒ Object
-
#references_render(docxml) ⇒ Object
-
#related(docxml) ⇒ Object
-
#related1(node) ⇒ Object
-
#requirement(docxml) ⇒ Object
-
#requirement_render(docxml) ⇒ Object
-
#requirement_render1(node) ⇒ Object
-
#requirement_render_preprocessing(docxml) ⇒ Object
-
#resolve_comma_connectives(locs) ⇒ Object
-
#resolve_comma_connectives1(locs, locs1, add) ⇒ Object
-
#resolve_eref_connectives(locs) ⇒ Object
-
#resolve_to_connectives(locs) ⇒ Object
-
#section(docxml) ⇒ Object
parse annex after term, references, to deal with single-term and single-ref annexes.
-
#semantic_xml_insert(xml) ⇒ Object
-
#single_term_clause_retitle(elem) ⇒ Object
-
#single_term_clause_unnest(elem) ⇒ Object
-
#source_highlight(elem) ⇒ Object
-
#source_label(elem) ⇒ Object
-
#source_lex(elem) ⇒ Object
-
#source_remove_annotations(ret, elem) ⇒ Object
-
#source_remove_markup(elem) ⇒ Object
-
#source_restore_callouts(code, callouts) ⇒ Object
-
#source_restore_callouts_table(table, callouts) ⇒ Object
-
#source_restore_markup(wrapper, markup) ⇒ Object
-
#source_restore_markup_table(wrapper, markup) ⇒ Object
-
#sourcecode(docxml) ⇒ Object
-
#sourcecode1(elem) ⇒ Object
-
#sourcecode_table_to_elem(elem, tokens) ⇒ Object
-
#sourcehighlighter ⇒ Object
-
#sourcehighlighter_css(docxml) ⇒ Object
-
#svg_emf_double(img) ⇒ Object
-
#svg_extract(elem) ⇒ Object
-
#svg_prep(img) ⇒ Object
-
#svg_to_emf(node) ⇒ Object
-
#svg_to_emf_uri(node) ⇒ Object
-
#svg_to_emf_uri_convert(node) ⇒ Object
-
#svg_wrap(elem) ⇒ Object
-
#svgmap_extract(elem) ⇒ Object
-
#table(docxml) ⇒ Object
-
#table1(elem) ⇒ Object
-
#tag_translate(tag, lang, value) ⇒ Object
-
#term(docxml) ⇒ Object
-
#term1(elem) ⇒ Object
-
#termdefinition(docxml) ⇒ Object
-
#termdefinition1(elem) ⇒ Object
-
#termexample(docxml) ⇒ Object
-
#termnote(docxml) ⇒ Object
-
#termnote1(elem) ⇒ Object
-
#terms(docxml) ⇒ Object
-
#termsource(docxml) ⇒ Object
-
#termsource1(elem) ⇒ Object
-
#termsource_modification(mod) ⇒ Object
-
#to_xml_file(result, filename) ⇒ Object
-
#toc(docxml) ⇒ Object
-
#toc_metadata(docxml) ⇒ Object
-
#trim_hash(hash) ⇒ Object
-
#trim_hash1(hash) ⇒ Object
-
#twitter_cldr_localiser ⇒ Object
-
#twitter_cldr_localiser_symbols ⇒ Object
-
#twitter_cldr_reader(locale) ⇒ Object
-
#unnest_linkend(node) ⇒ Object
so not <origin bibitemid=“ISO7301” citeas=“ISO 7301”> <locality type=“section”><reference>3.1</reference></locality></origin>.
-
#unwrap_definition(elem) ⇒ Object
-
#variant(docxml) ⇒ Object
-
#variant1(node) ⇒ Object
-
#xref(docxml) ⇒ Object
-
#xref1(node) ⇒ Object
-
#xref_empty?(node) ⇒ Boolean
Methods inherited from Convert
#bibitem_lookup, #convert, #convert_i18n_init, #convert_init, #convert_scss, #default_file_locations, #default_fonts, #fonts_options, #generate_css, #html_doc_path, #i18n_init, #init_arrangement, #init_covers, #init_fonts, #init_i18n, #init_locations, #init_processing, #init_rendering, #init_stylesheets, #init_toc, #l10n, #localpath, #metadata_init, #middle_clause, #options_preprocess, #populate_css, #precompiled_style_or_original, #scss_fontheader, #target_pdf, #tmpfilesdir_suffix, #tmpimagedir_suffix, #toc_init, #xref_init
Methods included from ClassUtils
#case_strict, #case_strict1, #case_with_markup, #date_range, #liquid, #nearest_block_parent, #ns, #start_of_sentence, #to_xml
#attr_code, #cleanup_entities, #date_range, #emf?, #empty2nil, #eps?, #external_path, #extract_delims, #from_xhtml, #get_clause_id, #get_note_container_id, #header_strip, #header_strip_elem?, #image_localfile, #insert_tab, #labelled_ancestor, #liquid, #noko, #ns, #numeric_escapes, #populate_template, #save_dataimage, #save_svg, #sentence_join, #start_of_sentence, #to_xhtml, #to_xhtml_fragment, #to_xhtml_prep, #to_xml
#body_attr, #boilerplate, #define_head, #info, #init_dir, #init_file, #make_body, #make_body1, #make_body2, #make_body3, #middle, #note?, #parse, #rel_tmpimagedir, #set_termdomain, #tmpimagedir
#admitted_term_parse, #definition_parse, #deprecated_term_parse, #modification_parse, #para_then_remainder, #term_parse, #termdef_parse, #termdocsource_parse, #termnote_delim, #termnote_parse, #termref_parse
#colgroup, #make_tr_attr, #make_tr_attr_style, #table_attrs, #table_parse, #table_parse_core, #table_title_parse, #tbody_parse, #tcaption, #tfoot_parse, #thead_parse, #tr_parse
#abstract, #acknowledgements, #annex_attrs, #annex_name, #clause_attrs, #clause_name, #clause_parse, #clause_parse_subtitle, #clause_parse_title, #clause_parse_title1, #clause_title_depth, #clausedelim, #clausedelimspace, #colophon, #copyright_parse, #feedback_parse, #foreword, #inline_header_title, #introduction, #is_clause?, #legal_parse, #license_parse, #preceding_floating_titles, #preface, #preface_block, #scope, #single_term_clause?, #symbols_abbrevs, #symbols_parse, #terms_defs, #terms_parse, #variant_title
#bibitem_ref_code, #biblio_list, #bibliography, #bibliography_parse, #bibliography_xpath, #bracket_if_num, #docid_l10n, #docid_prefix, #implicit_reference, #iso_bibitem_entry_attrs, #nonstd_bibitem, #norm_ref, #norm_ref_xpath, #omit_docid_prefix, #pref_ref_code, #reference_format, #render_identifier, #standard?, #std_bibitem_entry, #unbracket, #unbracket1
#dl_attrs, #dl_parse, #dl_parse1, #dt_dd?, #dt_parse, #li_parse, #list_title_parse, #ol_attrs, #ol_parse, #ol_style, #ul_attrs, #ul_parse
#add_parse, #asciimath_parse, #bookmark_parse, #br_parse, #callout_parse, #del_parse, #em_parse, #eref_parse, #eref_target, #eref_url, #error_parse, #hr_parse, #image_parse, #image_title_parse, #index_parse, #index_xref_parse, #keyword_parse, #latexmath_parse, #link_parse, #location_parse, #mathml_parse, #no_locality_parse, #origin_parse, #page_break, #pagebreak_parse, #section_break, #smallcap_parse, #span_parse, #stem_parse, #strike_parse, #strong_parse, #sub_parse, #suffix_url, #sup_parse, #termrefelem_parse, #text_parse, #tt_parse, #underline_parse, #xref_parse
#form_parse, #input_parse, #label_parse, #option_parse, #select_parse, #text_input, #textarea_parse
#admonition_cleanup, #break_up_long_strings, #break_up_long_strings1, #cleanup, #example_cleanup, #figure_aside_process, #figure_cleanup, #figure_get_or_make_dl, #footnote_cleanup, #footnote_reference_format, #inline_header_cleanup, #merge_fnref_into_fn_text, #new_fullcolspan_row, #passthrough_cleanup, #remove_bottom_border, #symbols_cleanup, #table_cleanup, #table_footnote_cleanup, #table_footnote_cleanup_propagate, #table_footnote_reference_format, #table_get_or_make_tfoot, #table_long_strings_cleanup, #table_note_cleanup, #textcleanup
#admonition_attrs, #admonition_class, #admonition_name, #admonition_name_parse, #admonition_parse, #annotation_parse, #div_parse, #example_div_attr, #example_div_parse, #example_label, #example_parse, #example_table_attr, #example_table_parse, #figure_attrs, #figure_key, #figure_name_parse, #figure_parse, #figure_parse1, #formula_attrs, #formula_parse, #formula_parse1, #keep_style, #middle_admonitions, #middle_title, #note_attrs, #note_delim, #note_p_parse, #note_parse, #note_parse1, #para_attrs, #para_class, #para_parse, #passthrough_parse, #permission_parse, #pre_parse, #pseudocode_attrs, #pseudocode_parse, #quote_attribution, #quote_parse, #recommendation_name, #recommendation_parse, #recommendation_parse1, #reqt_attrs, #requirement_parse, #sourcecode_attrs, #sourcecode_name_parse, #sourcecode_parse, #sourcecode_parse1, #svg_parse, #toc_parse
Constructor Details
Returns a new instance of PresentationXMLConvert.
12
13
14
15
16
|
# File 'lib/isodoc/presentation_xml_convert.rb', line 12
def initialize(options)
@format = :presentation
@suffix = "presentation.xml"
super
end
|
Instance Method Details
#address_precompose(bib) ⇒ Object
31
32
33
34
35
36
37
38
|
# File 'lib/isodoc/presentation_function/bibdata.rb', line 31
def address_precompose(bib)
bib.xpath(ns("//bibdata//address")).each do |b|
next if b.at(ns("./formattedAddress"))
x = address_precompose1(b)
b.children = "<formattedAddress>#{x}</formattedAddress>"
end
end
|
#address_precompose1(addr) ⇒ Object
57
58
59
60
61
62
63
64
65
|
# File 'lib/isodoc/presentation_function/bibdata.rb', line 57
def address_precompose1(addr)
ret = []
addr.xpath(ns("./street")).each { |s| ret << to_xml(s.children) }
a = addr.at(ns("./city")) and ret << to_xml(a.children)
addr.xpath(ns("./state")).each { |s| ret << to_xml(s.children) }
a = addr.at(ns("./country")) and ret << to_xml(a.children)
a = addr.at(ns("./postcode")) and ret[-1] += " #{to_xml a.children}"
ret.join("<br/>")
end
|
#admonition(docxml) ⇒ Object
73
74
75
|
# File 'lib/isodoc/presentation_function/block.rb', line 73
def admonition(docxml)
docxml.xpath(ns("//admonition")).each { |f| admonition1(f) }
end
|
#admonition1(elem) ⇒ Object
77
78
79
80
81
82
83
84
|
# File 'lib/isodoc/presentation_function/block.rb', line 77
def admonition1(elem)
if elem["type"] == "box"
admonition_numbered1(elem)
else
elem["notag"] == "true" || elem.at(ns("./name")) and return
prefix_name(elem, "", @i18n.admonition[elem["type"]]&.upcase, "name")
end
end
|
#admonition_numbered1(elem) ⇒ Object
86
87
88
89
90
|
# File 'lib/isodoc/presentation_function/block.rb', line 86
def admonition_numbered1(elem)
elem["unnumbered"] && !elem.at(ns("./name")) and return
n = @xrefs.anchor(elem["id"], :label, false)
prefix_name(elem, block_delim, l10n("#{@i18n.box} #{n}"), "name")
end
|
#amend(docxml) ⇒ Object
we use this to eliminate the semantic amend blocks from rendering
129
130
131
|
# File 'lib/isodoc/presentation_function/block.rb', line 129
def amend(docxml)
docxml.xpath(ns("//amend")).each { |f| amend1(f) }
end
|
#amend1(elem) ⇒ Object
133
134
135
136
137
138
|
# File 'lib/isodoc/presentation_function/block.rb', line 133
def amend1(elem)
elem.xpath(ns("./autonumber")).each(&:remove)
elem.xpath(ns("./newcontent")).each { |a| a.name = "quote" }
elem.xpath(ns("./description")).each { |a| a.replace(a.children) }
elem.replace(elem.children)
end
|
#anchor_id_postproc(node) ⇒ Object
26
27
28
|
# File 'lib/isodoc/presentation_function/xrefs.rb', line 26
def anchor_id_postproc(node)
node["target"]
end
|
#anchor_id_postprocess(node) ⇒ Object
39
|
# File 'lib/isodoc/presentation_function/inline.rb', line 39
def anchor_id_postprocess(node); end
|
#anchor_linkend(node, linkend) ⇒ Object
12
13
14
15
16
17
18
19
20
21
22
23
24
|
# File 'lib/isodoc/presentation_function/xrefs.rb', line 12
def anchor_linkend(node, linkend)
node["style"] == "id" and
return anchor_id_postproc(node)
node["citeas"].nil? && node["bibitemid"] and
return @xrefs.anchor(node["bibitemid"], :xref) || "???"
node.at(ns("./location")) and
return combine_xref_locations(node) || "???"
node["target"] && node["droploc"] and
return anchor_value(node["target"]) || "???"
node["target"] && !/.#./.match(node["target"]) and
return anchor_linkend1(node) || "???"
linkend || "???"
end
|
#anchor_linkend1(node) ⇒ Object
30
31
32
33
34
35
36
|
# File 'lib/isodoc/presentation_function/xrefs.rb', line 30
def anchor_linkend1(node)
linkend = anchor_xref(node, node["target"])
container = @xrefs.anchor(node["target"], :container, false)
prefix_container?(container, node) and
linkend = prefix_container(container, linkend, node, node["target"])
capitalise_xref(node, linkend, anchor_value(node["target"]))
end
|
#anchor_value(id) ⇒ Object
7
8
9
10
|
# File 'lib/isodoc/presentation_function/xrefs.rb', line 7
def anchor_value(id)
@xrefs.anchor(id, :value) || @xrefs.anchor(id, :label) ||
@xrefs.anchor(id, :xref)
end
|
#anchor_xref(node, target) ⇒ Object
38
39
40
41
42
43
44
45
46
47
48
|
# File 'lib/isodoc/presentation_function/xrefs.rb', line 38
def anchor_xref(node, target)
x = @xrefs.anchor(target, :xref)
t = @xrefs.anchor(target, :title)
ret = case node["style"]
when "basic" then t
when "full" then anchor_xref_full(x, t)
when "short", nil then x
else @xrefs.anchor(target, node[:style].to_sym)
end
ret || x
end
|
#anchor_xref_full(num, title) ⇒ Object
50
51
52
53
54
|
# File 'lib/isodoc/presentation_function/xrefs.rb', line 50
def anchor_xref_full(num, title)
(!title.nil? && !title.empty?) or return nil
l10n("#{num}, #{title}")
end
|
#annex(docxml) ⇒ Object
47
48
49
50
51
52
53
54
|
# File 'lib/isodoc/presentation_function/section.rb', line 47
def annex(docxml)
docxml.xpath(ns("//annex")).each do |f|
@xrefs.klass.single_term_clause?(f) and single_term_clause_retitle(f)
annex1(f)
@xrefs.klass.single_term_clause?(f) and single_term_clause_unnest(f)
end
@xrefs.parse_inclusions(clauses: true).parse(docxml)
end
|
#annex1(elem) ⇒ Object
56
57
58
59
60
61
62
|
# File 'lib/isodoc/presentation_function/section.rb', line 56
def annex1(elem)
lbl = @xrefs.anchor(elem["id"], :label)
if t = elem.at(ns("./title"))
t.children = "<strong>#{to_xml(t.children)}</strong>"
end
prefix_name(elem, "<br/><br/>", lbl, "title")
end
|
#asciimath_dup(node) ⇒ Object
92
93
94
95
96
97
|
# File 'lib/isodoc/presentation_function/math.rb', line 92
def asciimath_dup(node)
return if @suppressasciimathdup
a = MathML2AsciiMath.m2a(node.to_xml)
node.next = "<!-- #{a} -->"
end
|
#bibdata(docxml) ⇒ Object
5
6
7
8
9
10
11
12
13
14
15
|
# File 'lib/isodoc/presentation_function/bibdata.rb', line 5
def bibdata(docxml)
toc_metadata(docxml)
fonts_metadata(docxml)
docid_prefixes(docxml)
a = bibdata_current(docxml) or return
address_precompose(a)
bibdata_i18n(a)
a.next =
"<localized-strings>#{i8n_name(trim_hash(@i18n.get), '').join}" \
"</localized-strings>"
end
|
#bibdata_current(docxml) ⇒ Object
67
68
69
70
71
72
73
74
75
76
|
# File 'lib/isodoc/presentation_function/bibdata.rb', line 67
def bibdata_current(docxml)
a = docxml.at(ns("//bibdata")) or return
a.xpath(ns("./language")).each do |l|
l.text == @lang and l["current"] = "true"
end
a.xpath(ns("./script")).each do |l|
l.text == @script and l["current"] = "true"
end
a
end
|
#bibdata_i18n(bib) ⇒ Object
78
79
80
81
82
83
|
# File 'lib/isodoc/presentation_function/bibdata.rb', line 78
def bibdata_i18n(bib)
hash_translate(bib, @i18n.get["doctype_dict"], "./ext/doctype")
hash_translate(bib, @i18n.get["stage_dict"], "./status/stage")
hash_translate(bib, @i18n.get["substage_dict"], "./status/substage")
edition_translate(bib)
end
|
#bibitem(xml, renderings) ⇒ Object
38
39
40
41
|
# File 'lib/isodoc/presentation_function/refs.rb', line 38
def bibitem(xml, renderings)
@xrefs.klass.implicit_reference(xml) and xml["hidden"] = "true"
bibrender(xml, renderings)
end
|
#biblio_ref_entry_code(ordinal, ids, _id, standard, datefn, _bib) ⇒ Object
if ids is just a number, only use that ([1] Non-Standard) else, use both ordinal, as prefix, and ids
151
152
153
154
155
156
157
158
159
160
161
|
# File 'lib/isodoc/presentation_function/refs.rb', line 151
def biblio_ref_entry_code(ordinal, ids, _id, standard, datefn, _bib)
ret = (ids[:ordinal] || ids[:metanorma] || "[#{ordinal}]")
if ids[:sdo]
ret = prefix_bracketed_ref(ret)
ret += "#{ids[:sdo]}#{datefn}, "
else
ret = prefix_bracketed_ref("#{ret}#{datefn}")
end
ret
end
|
#bibliography_bibitem_number(docxml) ⇒ Object
74
75
76
77
78
79
80
81
|
# File 'lib/isodoc/presentation_function/refs.rb', line 74
def bibliography_bibitem_number(docxml)
i = 0
docxml.xpath(ns("//references[@normative = 'false']/bibitem")).each do |b|
i = bibliography_bibitem_number1(b, i)
end
@xrefs.references docxml
bibliography_bibitem_tag(docxml)
end
|
#bibliography_bibitem_number1(bibitem, idx) ⇒ Object
83
84
85
86
87
88
89
90
91
92
93
94
|
# File 'lib/isodoc/presentation_function/refs.rb', line 83
def bibliography_bibitem_number1(bibitem, idx)
ins = bibliography_bibitem_number_insert_pt(bibitem)
mn = bibitem.at(ns(".//docidentifier[@type = 'metanorma']")) and
/^\[?\d+\]?$/.match?(mn.text) and
mn.remove unless bibliography_bibitem_number_skip(bibitem)
idx += 1
ins.next =
"<docidentifier type='metanorma-ordinal'>[#{idx}]</docidentifier>"
end
idx
end
|
#bibliography_bibitem_number_insert_pt(bibitem) ⇒ Object
96
97
98
99
100
101
102
|
# File 'lib/isodoc/presentation_function/refs.rb', line 96
def bibliography_bibitem_number_insert_pt(bibitem)
unless ins = bibitem.at(ns(".//docidentifier")).previous_element
bibitem.at(ns(".//docidentifier")).previous = " "
ins = bibitem.at(ns(".//docidentifier")).previous
end
ins
end
|
#bibliography_bibitem_number_skip(bibitem) ⇒ Object
67
68
69
70
71
72
|
# File 'lib/isodoc/presentation_function/refs.rb', line 67
def bibliography_bibitem_number_skip(bibitem)
@xrefs.klass.implicit_reference(bibitem) ||
bibitem.at(ns(".//docidentifier[@type = 'metanorma']")) ||
bibitem.at(ns(".//docidentifier[@type = 'metanorma-ordinal']")) ||
bibitem["hidden"] == "true" || bibitem.parent["hidden"] == "true"
end
|
#bibliography_bibitem_tag(docxml) ⇒ Object
110
111
112
113
114
115
116
117
|
# File 'lib/isodoc/presentation_function/refs.rb', line 110
def bibliography_bibitem_tag(docxml)
[true, false].each do |norm|
i = 0
docxml.xpath(ns("//references[@normative = '#{norm}']")).each do |r|
i = bibliography_bibitem_tag1(r, i, norm)
end
end
end
|
#bibliography_bibitem_tag1(ref, idx, norm) ⇒ Object
119
120
121
122
123
124
125
126
|
# File 'lib/isodoc/presentation_function/refs.rb', line 119
def bibliography_bibitem_tag1(ref, idx, norm)
ref.xpath(ns("./bibitem")).each do |b|
@xrefs.klass.implicit_reference(b) and next
idx += 1 unless b["hidden"]
insert_biblio_tag(b, idx, !norm, @xrefs.klass.standard?(b))
end
idx
end
|
#bibrender(xml, renderings) ⇒ Object
43
44
45
46
47
48
|
# File 'lib/isodoc/presentation_function/refs.rb', line 43
def bibrender(xml, renderings)
if (f = xml.at(ns("./formattedref"))) && xml.at(ns("./title")).nil?
bibrender_formattedref(f, xml)
else bibrender_relaton(xml, renderings)
end
end
|
50
|
# File 'lib/isodoc/presentation_function/refs.rb', line 50
def bibrender_formattedref(formattedref, xml); end
|
#bibrender_relaton(xml, renderings) ⇒ Object
52
53
54
55
56
57
|
# File 'lib/isodoc/presentation_function/refs.rb', line 52
def bibrender_relaton(xml, renderings)
f = renderings[xml["id"]][:formattedref]
f &&= "<formattedref>#{f}</formattedref>"
x = xml.xpath(ns("./docidentifier | ./uri | ./note | ./biblio-tag"))
xml.children = "#{f}#{x.to_xml}"
end
|
#bibrenderer ⇒ Object
59
60
61
|
# File 'lib/isodoc/presentation_function/refs.rb', line 59
def bibrenderer
::Relaton::Render::IsoDoc::General.new(language: @lang)
end
|
#blank?(elem) ⇒ Boolean
156
157
158
|
# File 'lib/isodoc/presentation_function/bibdata.rb', line 156
def blank?(elem)
elem.nil? || (elem.respond_to?(:empty?) && elem.empty?)
end
|
#block(docxml) ⇒ Object
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
# File 'lib/isodoc/presentation_xml_convert.rb', line 52
def block(docxml)
amend docxml
table docxml
figure docxml
sourcecode docxml
formula docxml
example docxml
note docxml
admonition docxml
ol docxml
permission docxml
requirement docxml
recommendation docxml
requirement_render docxml
end
|
#block_delim ⇒ Object
13
14
15
|
# File 'lib/isodoc/presentation_function/block.rb', line 13
def block_delim
" — "
end
|
#cache_dataimage(uri) ⇒ Object
142
143
144
145
146
147
148
|
# File 'lib/isodoc/presentation_function/image.rb', line 142
def cache_dataimage(uri)
if %r{^data:}.match?(uri)
uri = save_dataimage(uri)
@tempfile_cache << uri
end
uri
end
|
#can_conflate_eref_rendering?(refs) ⇒ Boolean
39
40
41
42
43
44
45
46
47
48
|
# File 'lib/isodoc/presentation_function/erefs.rb', line 39
def can_conflate_eref_rendering?(refs)
(refs.size > 1 &&
refs.all? { |r| r.name == "localityStack" } &&
refs.all? { |r| r.xpath(ns("./locality")).size == 1 }) or return false
first = refs.first.at(ns("./locality/@type")).text
refs.all? do |r|
r.at(ns("./locality/@type")).text == first
end
end
|
#can_conflate_xref_rendering?(locs) ⇒ Boolean
128
129
130
131
132
|
# File 'lib/isodoc/presentation_function/xrefs.rb', line 128
def can_conflate_xref_rendering?(locs)
(locs.all? { |l| l[:container].nil? } ||
locs.all? { |l| l[:container] == locs.first[:container] }) &&
locs.all? { |l| l[:type] == locs[0][:type] }
end
|
#capitalise_xref(node, linkend, label) ⇒ Object
134
135
136
137
138
139
140
141
142
|
# File 'lib/isodoc/presentation_function/xrefs.rb', line 134
def capitalise_xref(node, linkend, label)
linktext = linkend.gsub(/<[^>]+>/, "")
(label && !label.empty? && /^#{Regexp.escape(label)}/.match?(linktext)) ||
linktext[0, 1].match?(/\p{Upper}/) and return linkend
node["case"] and
return Common::case_with_markup(linkend, node["case"], @script)
capitalise_xref1(node, linkend)
end
|
#capitalise_xref1(node, linkend) ⇒ Object
144
145
146
147
148
149
|
# File 'lib/isodoc/presentation_function/xrefs.rb', line 144
def capitalise_xref1(node, linkend)
if start_of_sentence(node)
Common::case_with_markup(linkend, "capital", @script)
else linkend
end
end
|
#citestyle ⇒ Object
63
64
65
|
# File 'lib/isodoc/presentation_function/refs.rb', line 63
def citestyle
nil
end
|
#clause(docxml) ⇒ Object
5
6
7
8
9
10
11
12
13
14
|
# File 'lib/isodoc/presentation_function/section.rb', line 5
def clause(docxml)
docxml.xpath(ns("//clause | " \
"//terms | //definitions | //references"))
.each do |f|
f.parent.name == "annex" &&
@xrefs.klass.single_term_clause?(f.parent) and next
clause1(f)
end
end
|
#clause1(elem) ⇒ Object
16
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/isodoc/presentation_function/section.rb', line 16
def clause1(elem)
level = @xrefs.anchor(elem["id"], :level, false) ||
(elem.ancestors("clause, annex").size + 1)
t = elem.at(ns("./title")) and t["depth"] = level
return if !elem.ancestors("boilerplate, metanorma-extension").empty? ||
@suppressheadingnumbers || elem["unnumbered"]
lbl = @xrefs.anchor(elem["id"], :label,
elem.parent.name != "sections") or return
prefix_name(elem, "<tab/>", "#{lbl}#{clausedelim}", "title")
end
|
#clausetitle(docxml) ⇒ Object
127
|
# File 'lib/isodoc/presentation_function/section.rb', line 127
def clausetitle(docxml); end
|
#combine_conflated_xref_locations(locs) ⇒ Object
75
76
77
78
79
80
|
# File 'lib/isodoc/presentation_function/xrefs.rb', line 75
def combine_conflated_xref_locations(locs)
out = locs.each { |l| l[:label] = anchor_value(l[:target]) }
label = @i18n.inflect(locs.first[:elem], number: "pl")
out[0][:label] = l10n("#{label} #{out[0][:label]}").strip
combine_conflated_xref_locations_container(locs, l10n(combine_conn(out)))
end
|
#combine_conflated_xref_locations_container(locs, ret) ⇒ Object
82
83
84
85
86
87
88
89
|
# File 'lib/isodoc/presentation_function/xrefs.rb', line 82
def combine_conflated_xref_locations_container(locs, ret)
container = @xrefs.anchor(locs.first[:node]["target"], :container,
false)
prefix_container?(container, locs.first[:node]) and
ret = prefix_container(container, ret, locs.first[:node],
locs.first[:node]["target"])
ret
end
|
#combine_conn(list) ⇒ Object
109
110
111
112
113
114
115
116
117
118
119
120
121
|
# File 'lib/isodoc/presentation_function/xrefs.rb', line 109
def combine_conn(list)
return list.first[:label] if list.size == 1
if list[1..-1].all? { |l| l[:conn] == "and" }
@i18n.boolean_conj(list.map { |l| loc2xref(l) }, "and")
elsif list[1..-1].all? { |l| l[:conn] == "or" }
@i18n.boolean_conj(list.map { |l| loc2xref(l) }, "or")
else
ret = loc2xref(list[0])
list[1..-1].each { |l| ret = i18n_chain_boolean(ret, l) }
ret
end
end
|
#combine_xref_locations(node) ⇒ Object
64
65
66
67
68
69
70
71
72
73
|
# File 'lib/isodoc/presentation_function/xrefs.rb', line 64
def combine_xref_locations(node)
locs = gather_xref_locations(node)
linkend = if can_conflate_xref_rendering?(locs)
combine_conflated_xref_locations(locs)
else
out = locs.each { |l| l[:label] = anchor_linkend1(l[:node]) }
l10n(combine_conn(out))
end
capitalise_xref(node, linkend, anchor_value(node["target"]))
end
|
#concept(docxml) ⇒ Object
3
4
5
6
7
|
# File 'lib/isodoc/presentation_function/terms.rb', line 3
def concept(docxml)
@definition_ids = docxml.xpath(ns("//definitions//dt"))
.each_with_object({}) { |x, m| m[x["id"]] = true }
docxml.xpath(ns("//concept")).each { |f| concept1(f) }
end
|
#concept1(node) ⇒ Object
9
10
11
12
13
14
15
16
17
18
19
|
# File 'lib/isodoc/presentation_function/terms.rb', line 9
def concept1(node)
xref = node&.at(ns("./xref/@target"))&.text or
return concept_render(node, ital: "true", ref: "true", bold: "false",
linkref: "true", linkmention: "false")
if @definition_ids[xref]
concept_render(node, ital: "false", ref: "false", bold: "false",
linkref: "true", linkmention: "false")
else concept_render(node, ital: "true", ref: "true", bold: "false",
linkref: "true", linkmention: "false")
end
end
|
#concept1_linkmention(ref, renderterm, opts) ⇒ Object
48
49
50
51
52
53
54
|
# File 'lib/isodoc/presentation_function/terms.rb', line 48
def concept1_linkmention(ref, renderterm, opts)
(opts[:linkmention] == "true" &&
!renderterm.nil? && !ref.nil?) or return
ref2 = ref.clone
r2 = renderterm.clone
renderterm.replace(ref2).children = r2
end
|
#concept1_ref(_node, ref, opts) ⇒ Object
56
57
58
59
60
61
62
63
|
# File 'lib/isodoc/presentation_function/terms.rb', line 56
def concept1_ref(_node, ref, opts)
ref.nil? and return
opts[:ref] == "false" and return ref.remove
concept1_ref_content(ref)
%w(xref eref).include? ref.name and get_linkend(ref)
opts[:linkref] == "false" && %w(xref eref).include?(ref.name) and
ref.replace(ref.children)
end
|
#concept1_ref_content(ref) ⇒ Object
65
66
67
68
69
70
71
72
73
74
75
|
# File 'lib/isodoc/presentation_function/terms.rb', line 65
def concept1_ref_content(ref)
prev = "["
foll = "]"
if non_locality_elems(ref).select do |c|
!c.text? || /\S/.match(c)
end.empty?
prev, foll = @i18n.term_defined_in.split("%")
end
ref.previous = prev
ref.next = foll
end
|
#concept1_style(node, opts) ⇒ Object
31
32
33
34
35
36
37
|
# File 'lib/isodoc/presentation_function/terms.rb', line 31
def concept1_style(node, opts)
r = node.at(ns(".//renderterm")) or return
opts[:ital] == "true" and r.children = "<em>#{to_xml(r.children)}</em>"
opts[:bold] == "true" and
r.children = "<strong>#{to_xml(r.children)}</strong>"
r.replace(r.children)
end
|
#concept_render(node, defaults) ⇒ Object
21
22
23
24
25
26
27
28
29
|
# File 'lib/isodoc/presentation_function/terms.rb', line 21
def concept_render(node, defaults)
opts, render, ref = concept_render_init(node, defaults)
node&.at(ns("./refterm"))&.remove
ref && opts[:ref] != "false" and render&.next = " "
concept1_linkmention(ref, render, opts)
concept1_ref(node, ref, opts)
concept1_style(node, opts)
node.replace(node.children)
end
|
#concept_render_init(node, defaults) ⇒ Object
39
40
41
42
43
44
45
46
|
# File 'lib/isodoc/presentation_function/terms.rb', line 39
def concept_render_init(node, defaults)
opts = %i(bold ital ref linkref linkmention)
.each_with_object({}) do |x, m|
m[x] = node[x.to_s] || defaults[x]
end
[opts, node.at(ns("./renderterm")),
node.at(ns("./xref | ./eref | ./termref"))]
end
|
#conversions(docxml) ⇒ Object
26
27
28
29
30
31
32
33
34
|
# File 'lib/isodoc/presentation_xml_convert.rb', line 26
def conversions(docxml)
semantic_xml_insert(docxml)
bibdata docxml
@xrefs.parse docxml
section docxml
block docxml
terms docxml
inline docxml
end
|
#convert1(docxml, _filename, _dir) ⇒ Object
18
19
20
21
22
23
24
|
# File 'lib/isodoc/presentation_xml_convert.rb', line 18
def convert1(docxml, _filename, _dir)
@xrefs.parse docxml
info docxml, nil
conversions(docxml)
docxml.root["type"] = "presentation"
docxml.to_xml.gsub(/</, "<").gsub(/>/, ">")
end
|
#custom_css(docxml) ⇒ Object
12
13
14
15
16
17
18
19
20
21
|
# File 'lib/isodoc/presentation_function/sourcecode.rb', line 12
def custom_css(docxml)
ret = ""
@sourcehighlighter and
ret += File.read(File.join(File.dirname(__FILE__), "..", "base_style",
"rouge.css"))
a = docxml.at(ns("//metanorma-extension/" \
"clause[title = 'user-css']/sourcecode")) and
ret += "\n#{to_xml(a.children)}"
ret
end
|
#date_note_process(bib) ⇒ Object
strip any fns in docidentifier before they are extracted for rendering
168
169
170
171
172
173
174
|
# File 'lib/isodoc/presentation_function/refs.rb', line 168
def date_note_process(bib)
ret = ident_fn(bib)
date_note = bib.at(ns("./note[@type = 'Unpublished-Status']"))
date_note.nil? and return ret
id = UUIDTools::UUID.random_create.to_s
"#{ret}<fn reference='#{id}'><p>#{date_note.content}</p></fn>"
end
|
#decorate_fraction_part(fract, locale) ⇒ Object
49
50
51
52
53
54
55
56
57
58
|
# File 'lib/isodoc/presentation_function/math.rb', line 49
def decorate_fraction_part(fract, locale)
result = []
= (locale)
fract = fract.slice(0..([:precision] || -1))
fr_group_digits = [:fraction_group_digits] || 1
until fract.empty?
result.push(fract.slice!(0, fr_group_digits))
end
result.join([:fraction_group].to_s)
end
|
#designation(docxml) ⇒ Object
94
95
96
97
98
|
# File 'lib/isodoc/presentation_function/terms.rb', line 94
def designation(docxml)
docxml.xpath(ns("//term")).each { |t| merge_second_preferred(t) }
docxml.xpath(ns("//preferred | //admitted | //deprecates"))
.each { |p| designation1(p) }
end
|
#designation1(desgn) ⇒ Object
125
126
127
128
129
130
131
|
# File 'lib/isodoc/presentation_function/terms.rb', line 125
def designation1(desgn)
s = desgn.at(ns("./termsource"))
name = desgn.at(ns("./expression/name | ./letter-symbol/name | " \
"./graphical-symbol")) or return
designation_annotate(desgn, name)
s and desgn.next = s
end
|
#designation_annotate(desgn, name) ⇒ Object
133
134
135
136
137
138
139
140
141
|
# File 'lib/isodoc/presentation_function/terms.rb', line 133
def designation_annotate(desgn, name)
designation_boldface(desgn)
designation_field(desgn, name)
g = desgn.at(ns("./expression/grammar")) and
name << ", #{designation_grammar(g).join(', ')}"
designation_localization(desgn, name)
designation_pronunciation(desgn, name)
desgn.children = name.children
end
|
#designation_boldface(desgn) ⇒ Object
143
144
145
146
147
|
# File 'lib/isodoc/presentation_function/terms.rb', line 143
def designation_boldface(desgn)
desgn.name == "preferred" or return
name = desgn.at(ns("./expression/name | ./letter-symbol/name")) or return
name.children = "<strong>#{name.children}</strong>"
end
|
#designation_field(desgn, name) ⇒ Object
149
150
151
152
153
154
|
# File 'lib/isodoc/presentation_function/terms.rb', line 149
def designation_field(desgn, name)
f = desgn.xpath(ns("./field-of-application | ./usage-info"))
&.map { |u| to_xml(u.children) }&.join(", ")
f&.empty? and return nil
name << ", <#{f}>"
end
|
#designation_grammar(grammar) ⇒ Object
156
157
158
159
160
161
162
163
164
165
166
167
|
# File 'lib/isodoc/presentation_function/terms.rb', line 156
def designation_grammar(grammar)
ret = []
grammar.xpath(ns("./gender | ./number")).each do |x|
ret << @i18n.grammar_abbrevs[x.text]
end
%w(isPreposition isParticiple isAdjective isVerb isAdverb isNoun)
.each do |x|
grammar.at(ns("./#{x}[text() = 'true']")) and
ret << @i18n.grammar_abbrevs[x]
end
ret
end
|
#designation_localization(desgn, name) ⇒ Object
169
170
171
172
173
174
175
|
# File 'lib/isodoc/presentation_function/terms.rb', line 169
def designation_localization(desgn, name)
loc = [desgn&.at(ns("./expression/@language"))&.text,
desgn&.at(ns("./expression/@script"))&.text,
desgn&.at(ns("./@geographic-area"))&.text].compact
loc.empty? and return
name << ", #{loc.join(' ')}"
end
|
#designation_pronunciation(desgn, name) ⇒ Object
177
178
179
180
|
# File 'lib/isodoc/presentation_function/terms.rb', line 177
def designation_pronunciation(desgn, name)
f = desgn.at(ns("./expression/pronunciation")) or return
name << ", /#{to_xml(f.children)}/"
end
|
#display_order(docxml) ⇒ Object
112
113
114
115
116
117
118
119
120
121
122
123
124
125
|
# File 'lib/isodoc/presentation_function/section.rb', line 112
def display_order(docxml)
i = 0
i = display_order_xpath(docxml, "//preface/*", i)
i = display_order_at(docxml, "//clause[@type = 'scope']", i)
i = display_order_at(docxml, @xrefs.klass.norm_ref_xpath, i)
i = display_order_at(docxml, "//sections/terms | " \
"//sections/clause[descendant::terms]", i)
i = display_order_at(docxml, "//sections/definitions", i)
i = display_order_xpath(docxml, @xrefs.klass.middle_clause(docxml), i)
i = display_order_xpath(docxml, "//annex", i)
i = display_order_xpath(docxml, @xrefs.klass.bibliography_xpath, i)
i = display_order_xpath(docxml, "//indexsect", i)
display_order_xpath(docxml, "//colophon/*", i)
end
|
#display_order_at(docxml, xpath, idx) ⇒ Object
96
97
98
99
100
101
102
|
# File 'lib/isodoc/presentation_function/section.rb', line 96
def display_order_at(docxml, xpath, idx)
return idx unless c = docxml.at(ns(xpath))
idx += 1
c["displayorder"] = idx
idx
end
|
#display_order_xpath(docxml, xpath, idx) ⇒ Object
104
105
106
107
108
109
110
|
# File 'lib/isodoc/presentation_function/section.rb', line 104
def display_order_xpath(docxml, xpath, idx)
docxml.xpath(ns(xpath)).each do |c|
idx += 1
c["displayorder"] = idx
end
idx
end
|
#docid_prefixes(docxml) ⇒ Object
104
105
106
107
108
|
# File 'lib/isodoc/presentation_function/refs.rb', line 104
def docid_prefixes(docxml)
docxml.xpath(ns("//references/bibitem/docidentifier")).each do |i|
i.children = @xrefs.klass.docid_prefix(i["type"], to_xml(i.children))
end
end
|
#edition_translate(bibdata) ⇒ Object
does not allow %Spellout and %Ordinal in the ordinal expression to be mixed
93
94
95
96
97
98
99
|
# File 'lib/isodoc/presentation_function/bibdata.rb', line 93
def edition_translate(bibdata)
x = bibdata.at(ns("./edition")) or return
/^\d+$/.match?(x.text) or return
tag_translate(x, @lang,
@i18n.edition_ordinal.sub(/%(Spellout|Ordinal)?/,
edition_translate1(x.text.to_i)))
end
|
#edition_translate1(num) ⇒ Object
101
102
103
104
105
106
107
108
109
110
111
|
# File 'lib/isodoc/presentation_function/bibdata.rb', line 101
def edition_translate1(num)
ruleset = case @i18n.edition_ordinal
when /%Spellout/ then "SpelloutRules"
when /%Ordinal/ then "OrdinalRules"
else "Digit"
end
ruleset == "Digit" and return num.to_s
ed = @c.decode(@i18n.edition)
@i18n.inflect_ordinal(num, @i18n.inflection&.dig(ed) || {},
ruleset)
end
|
#embedable_semantic_xml(xml) ⇒ Object
105
106
107
108
|
# File 'lib/isodoc/presentation_xml_convert.rb', line 105
def embedable_semantic_xml(xml)
xml = embedable_semantic_xml_tags(xml)
embedable_semantic_xml_attributes(xml)
end
|
#embedable_semantic_xml_attributes(xml) ⇒ Object
123
124
125
126
127
128
129
130
131
132
|
# File 'lib/isodoc/presentation_xml_convert.rb', line 123
def embedable_semantic_xml_attributes(xml)
Metanorma::Utils::anchor_attributes.each do |(tag_name, attr_name)|
tag_name == "*" or tag_name = "semantic__#{tag_name}"
xml.xpath("//#{tag_name}[@#{attr_name}]").each do |elem|
elem.attributes[attr_name].value =
"semantic__#{elem.attributes[attr_name].value}"
end
end
xml
end
|
110
111
112
113
114
115
116
117
118
119
120
121
|
# File 'lib/isodoc/presentation_xml_convert.rb', line 110
def embedable_semantic_xml_tags(xml)
ret = to_xml(xml)
.sub(/ xmlns=['"][^"']+['"]/, "") .split(/(?=[<> \t\r\n\f\v])/).map do |x|
case x
when /^<[^:]+:/ then x.sub(/:/, ":semantic__")
when /^<[^:]+$/ then x.sub(%r{(</?)([[:alpha:]])},
"\\1semantic__\\2")
else x end
end
Nokogiri::XML(ret.join).root
end
|
#emf_encode(img) ⇒ Object
84
85
86
87
88
89
|
# File 'lib/isodoc/presentation_function/image.rb', line 84
def emf_encode(img)
svg_prep(img)
img.children = "<emf src='#{img['src']}'/>"
img["src"] = ""
img
end
|
#emf_to_svg(img) ⇒ Object
97
98
99
100
|
# File 'lib/isodoc/presentation_function/image.rb', line 97
def emf_to_svg(img)
emf = Metanorma::Utils::save_dataimage(img.at(ns("./emf/@src")).text)
Emf2svg.from_file(emf).sub(/<\?[^>]+>/, "")
end
|
#eps2svg(img) ⇒ Object
65
66
67
68
69
70
71
72
73
|
# File 'lib/isodoc/presentation_function/image.rb', line 65
def eps2svg(img)
return unless eps?(img["mimetype"])
img["mimetype"] = "image/svg+xml"
if src = eps_to_svg(img)
img["src"] = src
img.children = ""
end
end
|
#eps_to_svg(node) ⇒ Object
102
103
104
105
106
107
|
# File 'lib/isodoc/presentation_function/image.rb', line 102
def eps_to_svg(node)
uri = eps_to_svg_uri(node)
ret = imgfile_suffix(uri, "svg")
File.exist?(ret) and return ret
inkscape_convert(uri, ret, "--export-plain-svg")
end
|
#eps_to_svg_uri(node) ⇒ Object
137
138
139
140
|
# File 'lib/isodoc/presentation_function/image.rb', line 137
def eps_to_svg_uri(node)
uri = eps_to_svg_uri_convert(node)
cache_dataimage(uri)
end
|
#eps_to_svg_uri_convert(node) ⇒ Object
158
159
160
161
162
163
164
165
|
# File 'lib/isodoc/presentation_function/image.rb', line 158
def eps_to_svg_uri_convert(node)
if node.text.strip.empty?
node["src"]
else
a = Base64.strict_encode64(node.children.to_xml)
"data:application/postscript;base64,#{a}"
end
end
|
#eref(docxml) ⇒ Object
46
47
48
49
50
|
# File 'lib/isodoc/presentation_function/inline.rb', line 46
def eref(docxml)
docxml.xpath(ns("//eref")).each { |f| xref1(f) }
docxml.xpath(ns("//eref//xref")).each { |f| f.replace(f.children) }
docxml.xpath(ns("//erefstack")).each { |f| erefstack1(f) }
end
|
#eref_localities(refs, target, node) ⇒ Object
18
19
20
21
22
23
24
25
26
|
# File 'lib/isodoc/presentation_function/erefs.rb', line 18
def eref_localities(refs, target, node)
if can_conflate_eref_rendering?(refs)
l10n(", #{eref_localities_conflated(refs, target, node)}"
.gsub(/\s+/, " "))
else
ret = resolve_eref_connectives(eref_locality_stacks(refs, target, node))
l10n(ret.join.gsub(/\s+/, " "))
end
end
|
#eref_localities0(ref, _idx, target, node) ⇒ Object
138
139
140
141
142
143
144
145
146
|
# File 'lib/isodoc/presentation_function/erefs.rb', line 138
def eref_localities0(ref, _idx, target, node)
if ref["type"] == "whole" then @i18n.wholeoftext
else
eref_localities1({ target: target, type: ref["type"], number: "sg",
from: ref.at(ns("./referenceFrom"))&.text,
upto: ref.at(ns("./referenceTo"))&.text, node: node,
lang: @lang })
end
end
|
#eref_localities1(opt) ⇒ Object
def eref_localities1(target, type, from, upto, node, lang = “en”)
158
159
160
161
162
163
164
165
166
167
168
|
# File 'lib/isodoc/presentation_function/erefs.rb', line 158
def eref_localities1(opt)
return nil if opt[:type] == "anchor"
opt[:lang] == "zh" and
return l10n(eref_localities1_zh(opt))
ret = eref_locality_populate(opt[:type], opt[:node], opt[:number])
ret += " #{opt[:from]}" if opt[:from]
ret += "–#{opt[:upto]}" if opt[:upto]
l10n(ret)
end
|
#eref_localities1_zh(opt) ⇒ Object
def eref_localities1_zh(_target, type, from, upto, node)
149
150
151
152
153
154
155
|
# File 'lib/isodoc/presentation_function/erefs.rb', line 149
def eref_localities1_zh(opt)
ret = "第#{opt[:from]}" if opt[:from]
ret += "–#{opt[:upto]}" if opt[:upto]
loc = eref_locality_populate(opt[:type], opt[:node], "sg")
ret += " #{loc}" unless opt[:node]["droploc"] == "true"
ret
end
|
#eref_localities_conflated(refs, target, node) ⇒ Object
28
29
30
31
32
33
34
35
36
37
|
# File 'lib/isodoc/presentation_function/erefs.rb', line 28
def eref_localities_conflated(refs, target, node)
droploc = node["droploc"]
node["droploc"] = true
ret = resolve_eref_connectives(eref_locality_stacks(refs, target,
node))
node.delete("droploc") unless droploc
eref_localities1({ target: target, number: "pl",
type: refs.first.at(ns("./locality/@type")).text,
from: l10n(ret[1..-1].join), node: node, lang: @lang })
end
|
#eref_locality_delimiter(ref) ⇒ Object
107
108
109
110
111
112
|
# File 'lib/isodoc/presentation_function/erefs.rb', line 107
def eref_locality_delimiter(ref)
if ref&.next_element&.name == "localityStack"
ref.next_element["connective"]
else locality_delimiter(ref)
end
end
|
#eref_locality_populate(type, node, number) ⇒ Object
170
171
172
173
174
175
176
177
178
179
180
181
|
# File 'lib/isodoc/presentation_function/erefs.rb', line 170
def eref_locality_populate(type, node, number)
return "" if node["droploc"] == "true"
loc = type.sub(/^locality:/, "")
ret = @i18n.locality[loc] || loc
number == "pl" and ret = @i18n.inflect(ret, number: "pl")
ret = case node["case"]
when "lowercase" then ret.downcase
else Metanorma::Utils.strict_capitalize_first(ret)
end
" #{ret}"
end
|
#eref_locality_stack(ref, idx, target, node) ⇒ Object
114
115
116
117
118
119
120
121
122
123
|
# File 'lib/isodoc/presentation_function/erefs.rb', line 114
def eref_locality_stack(ref, idx, target, node)
ret = []
if ref.name == "localityStack"
ret = eref_locality_stack1(ref, target, node, ret)
else
l = eref_localities0(ref, idx, target, node) and ret << l
end
ret[-1] == ", " and ret.pop
ret
end
|
#eref_locality_stack1(ref, target, node, ret) ⇒ Object
125
126
127
128
129
130
131
132
|
# File 'lib/isodoc/presentation_function/erefs.rb', line 125
def eref_locality_stack1(ref, target, node, ret)
ref.elements.each_with_index do |rr, j|
l = eref_localities0(rr, j, target, node) or next
ret << l
ret << locality_delimiter(rr) unless j == ref.elements.size - 1
end
ret
end
|
#eref_locality_stacks(refs, target, node) ⇒ Object
95
96
97
98
99
100
101
102
103
104
105
|
# File 'lib/isodoc/presentation_function/erefs.rb', line 95
def eref_locality_stacks(refs, target, node)
ret = refs.each_with_index.with_object([]) do |(r, i), m|
added = eref_locality_stack(r, i, target, node)
added.empty? and next
added.each { |a| m << a }
next if i == refs.size - 1
m << eref_locality_delimiter(r)
end
ret.empty? ? ret : [", "] + ret
end
|
#erefstack1(elem) ⇒ Object
10
11
12
13
14
15
16
|
# File 'lib/isodoc/presentation_function/erefs.rb', line 10
def erefstack1(elem)
locs = elem.xpath(ns("./eref")).map do |e|
[e["connective"], to_xml(e)]
end.flatten
ret = resolve_eref_connectives(locs)
elem.replace(ret[1])
end
|
#example(docxml) ⇒ Object
46
47
48
|
# File 'lib/isodoc/presentation_function/block.rb', line 46
def example(docxml)
docxml.xpath(ns("//example")).each { |f| example1(f) }
end
|
#example1(elem) ⇒ Object
50
51
52
53
54
55
56
57
|
# File 'lib/isodoc/presentation_function/block.rb', line 50
def example1(elem)
n = @xrefs.get[elem["id"]]
lbl = if n.nil? || n[:label].nil? || n[:label].empty?
@i18n.example
else l10n("#{@i18n.example} #{n[:label]}")
end
prefix_name(elem, block_delim, lbl, "name")
end
|
#expand_citeas(text) ⇒ Object
5
6
7
8
|
# File 'lib/isodoc/presentation_function/erefs.rb', line 5
def expand_citeas(text)
text.nil? and return text
HTMLEntities.new.decode(text.gsub(/&#x/, "&#"))
end
|
8
9
10
11
12
13
14
|
# File 'lib/isodoc/presentation_function/image.rb', line 8
def figure(docxml)
docxml.xpath("//m:svg", SVG).each { |f| svg_wrap(f) }
docxml.xpath(ns("//image")).each { |f| (f) }
docxml.xpath(ns("//figure")).each { |f| figure1(f) }
docxml.xpath(ns("//svgmap")).each { |s| (s) }
imageconvert(docxml)
end
|
49
50
51
52
53
54
55
56
57
|
# File 'lib/isodoc/presentation_function/image.rb', line 49
def figure1(elem)
return sourcecode1(elem) if elem["class"] == "pseudocode" ||
elem["type"] == "pseudocode"
return if elem.at(ns("./figure")) && !elem.at(ns("./name"))
lbl = @xrefs.anchor(elem["id"], :label, false) or return
prefix_name(elem, block_delim,
l10n("#{figure_label(elem)} #{lbl}"), "name")
end
|
59
60
61
62
63
|
# File 'lib/isodoc/presentation_function/image.rb', line 59
def figure_label(elem)
klass = elem["class"] || "figure"
klasslbl = @i18n.get[klass] || klass
lower2cap klasslbl
end
|
#floattitle(docxml) ⇒ Object
28
29
30
31
32
33
34
35
36
37
38
|
# File 'lib/isodoc/presentation_function/section.rb', line 28
def floattitle(docxml)
docxml.xpath(ns("//clause | //annex | //appendix | //introduction | " \
"//foreword | //preface/abstract | //acknowledgements | " \
"//terms | //definitions | //references | //colophon"))
.each do |f|
floattitle1(f)
end
docxml.xpath(ns("//sections | //preface | //colophon"))
.each { |f| floattitle1(f) }
end
|
#floattitle1(elem) ⇒ Object
40
41
42
43
44
45
|
# File 'lib/isodoc/presentation_function/section.rb', line 40
def floattitle1(elem)
elem.xpath(ns(".//floating-title")).each do |p|
p.name = "p"
p["type"] = "floating-title"
end
end
|
40
41
42
43
44
45
46
47
48
49
50
|
# File 'lib/isodoc/presentation_function/bibdata.rb', line 40
def fonts_metadata(xmldoc)
return unless @fontist_fonts
ins = xmldoc.at(ns("//presentation-metadata")) ||
xmldoc.at(ns("//metanorma-extension")) || xmldoc.at(ns("//bibdata"))
CSV.parse_line(@fontist_fonts, col_sep: ";").map(&:strip).each do |f|
ins.next = presmeta("fonts", f)
end
@fontlicenseagreement and
ins.next = presmeta("font-license-agreement", @fontlicenseagreement)
end
|
29
30
31
|
# File 'lib/isodoc/presentation_function/block.rb', line 29
def formula(docxml)
docxml.xpath(ns("//formula")).each { |f| formula1(f) }
end
|
33
34
35
36
37
|
# File 'lib/isodoc/presentation_function/block.rb', line 33
def formula1(elem)
formula_where(elem.at(ns("./dl")))
lbl = @xrefs.anchor(elem["id"], :label, false)
prefix_name(elem, "", lbl, "name")
end
|
39
40
41
42
43
44
|
# File 'lib/isodoc/presentation_function/block.rb', line 39
def formula_where(dlist)
dlist or return
dlist["class"] = "formula_dl"
where = dlist.xpath(ns("./dt")).size > 1 ? @i18n.where : @i18n.where_one
dlist.previous = "<p keep-with-next='true'>#{where}</p>"
end
|
#gather_xref_locations(node) ⇒ Object
91
92
93
94
95
96
97
98
99
|
# File 'lib/isodoc/presentation_function/xrefs.rb', line 91
def gather_xref_locations(node)
node.xpath(ns("./location")).each_with_object([]) do |l, m|
type = @xrefs.anchor(l["target"], :type)
m << { conn: l["connective"], target: l["target"],
type: type, node: l, elem: @xrefs.anchor(l["target"], :elem),
container: @xrefs.anchor(node["target"], :container, false) ||
%w(termnote).include?(type) }
end
end
|
#get_linkend(node) ⇒ Object
11
12
13
14
15
16
17
18
19
20
21
22
|
# File 'lib/isodoc/presentation_function/inline.rb', line 11
def get_linkend(node)
node["style"] == "id" and anchor_id_postprocess(node)
return unless xref_empty?(node)
link = anchor_linkend(node, docid_l10n(node["target"] ||
expand_citeas(node["citeas"])))
link += eref_localities(node.xpath(ns("./locality | ./localityStack")),
link, node)
non_locality_elems(node).each(&:remove)
node.add_child(cleanup_entities(link))
unnest_linkend(node)
end
|
#hash_translate(bibdata, hash, xpath, lang = @lang) ⇒ Object
85
86
87
88
89
90
|
# File 'lib/isodoc/presentation_function/bibdata.rb', line 85
def hash_translate(bibdata, hash, xpath, lang = @lang)
x = bibdata.at(ns(xpath)) or return
hash.is_a? Hash or return
hash[x.text] or return
tag_translate(x, lang, hash[x.text])
end
|
#hidden_items(docxml) ⇒ Object
13
14
15
16
17
18
19
|
# File 'lib/isodoc/presentation_function/refs.rb', line 13
def hidden_items(docxml)
docxml.xpath(ns("//references[bibitem/@hidden = 'true']")).each do |x|
x.at(ns("./bibitem[not(@hidden = 'true')]")) and next
x.elements.map(&:name).any? { |n| n != "bibitem" } and next
x["hidden"] = "true"
end
end
|
#i18n_chain_boolean(value, entry) ⇒ Object
123
124
125
126
|
# File 'lib/isodoc/presentation_function/xrefs.rb', line 123
def i18n_chain_boolean(value, entry)
@i18n.send("chain_#{entry[:conn]}").sub(/%1/, value)
.sub(/%2/, loc2xref(entry))
end
|
#i18n_safe(key) ⇒ Object
125
126
127
|
# File 'lib/isodoc/presentation_function/bibdata.rb', line 125
def i18n_safe(key)
key.to_s.gsub(/\s|\./, "_")
end
|
#i18n_tag(key, value) ⇒ Object
120
121
122
123
|
# File 'lib/isodoc/presentation_function/bibdata.rb', line 120
def i18n_tag(key, value)
"<localized-string key='#{key}' language='#{@lang}'>#{value}" \
"</localized-string>"
end
|
#i8n_name(hash, pref) ⇒ Object
129
130
131
132
133
134
135
136
137
138
139
|
# File 'lib/isodoc/presentation_function/bibdata.rb', line 129
def i8n_name(hash, pref)
case hash
when Hash then i8n_name1(hash, pref)
when Array
hash.reject { |a| blank?(a) }.each_with_object([])
.with_index do |(v1, g), i|
i8n_name(v1, "#{i18n_safe(k)}.#{i}").each { |x| g << x }
end
else [i18n_tag(pref, hash)]
end
end
|
#i8n_name1(hash, pref) ⇒ Object
141
142
143
144
145
146
147
148
149
150
151
152
153
|
# File 'lib/isodoc/presentation_function/bibdata.rb', line 141
def i8n_name1(hash, pref)
hash.reject { |_k, v| blank?(v) }.each_with_object([]) do |(k, v), g|
case v
when Hash then i8n_name(v, i18n_safe(k)).each { |x| g << x }
when Array
v.reject { |a| blank?(a) }.each_with_index do |v1, i|
i8n_name(v1, "#{i18n_safe(k)}.#{i}").each { |x| g << x }
end
else
g << i18n_tag("#{pref}#{pref.empty? ? '' : '.'}#{i18n_safe(k)}", v)
end
end
end
|
#ident_fn(bib) ⇒ Object
176
177
178
179
|
# File 'lib/isodoc/presentation_function/refs.rb', line 176
def ident_fn(bib)
ret = bib.at(ns("./docidentifier//fn")) or return ""
to_xml(ret.remove)
end
|
#identifier(docxml) ⇒ Object
86
87
88
89
90
|
# File 'lib/isodoc/presentation_function/inline.rb', line 86
def identifier(docxml)
docxml.xpath(ns("//identifier")).each do |n|
n.name = "tt"
end
end
|
#imageconvert(docxml) ⇒ Object
29
30
31
32
33
34
|
# File 'lib/isodoc/presentation_function/image.rb', line 29
def imageconvert(docxml)
docxml.xpath(ns("//image")).each do |f|
eps2svg(f)
svg_emf_double(f)
end
end
|
#imgfile_suffix(uri, suffix) ⇒ Object
167
168
169
|
# File 'lib/isodoc/presentation_function/image.rb', line 167
def imgfile_suffix(uri, suffix)
"#{File.join(File.dirname(uri), File.basename(uri, '.*'))}.#{suffix}"
end
|
#index(docxml) ⇒ Object
92
93
94
|
# File 'lib/isodoc/presentation_function/section.rb', line 92
def index(docxml)
docxml.xpath(ns("//index | //index-xref | //indexsect")).each(&:remove)
end
|
#inkscape_convert(uri, file, option) ⇒ Object
121
122
123
124
125
126
127
128
129
130
|
# File 'lib/isodoc/presentation_function/image.rb', line 121
def inkscape_convert(uri, file, option)
exe = inkscape_installed? or raise "Inkscape missing in PATH, unable" \
"to convert image #{uri}. Aborting."
uri = Metanorma::Utils::external_path uri
exe = Metanorma::Utils::external_path exe
system(%(#{exe} #{option} #{uri})) and
return Metanorma::Utils::datauri(file)
raise %(Fail on #{exe} #{option} #{uri})
end
|
#inkscape_installed? ⇒ Boolean
171
172
173
174
175
176
177
178
179
180
181
|
# File 'lib/isodoc/presentation_function/image.rb', line 171
def inkscape_installed?
cmd = "inkscape"
exts = ENV["PATHEXT"] ? ENV["PATHEXT"].split(";") : [""]
ENV["PATH"].split(File::PATH_SEPARATOR).each do |path|
exts.each do |ext|
exe = File.join(path, "#{cmd}#{ext}")
return exe if File.executable?(exe) && !File.directory?(exe)
end
end
nil
end
|
#inline(docxml) ⇒ Object
68
69
70
71
72
73
74
75
76
|
# File 'lib/isodoc/presentation_xml_convert.rb', line 68
def inline(docxml)
xref docxml
eref docxml
origin docxml
quotesource docxml
mathml docxml
variant docxml
identifier docxml
end
|
#insert_biblio_tag(bib, ordinal, biblio, standard) ⇒ Object
128
129
130
131
132
133
134
135
136
137
|
# File 'lib/isodoc/presentation_function/refs.rb', line 128
def insert_biblio_tag(bib, ordinal, biblio, standard)
datefn = date_note_process(bib)
ids = @xrefs.klass.bibitem_ref_code(bib)
idents = @xrefs.klass.render_identifier(ids)
ret = if biblio then biblio_ref_entry_code(ordinal, idents, ids,
standard, datefn, bib)
else norm_ref_entry_code(ordinal, idents, ids, standard, datefn, bib)
end
bib << "<biblio-tag>#{ret}</biblio-tag>"
end
|
#loc2xref(entry) ⇒ Object
101
102
103
104
105
106
107
|
# File 'lib/isodoc/presentation_function/xrefs.rb', line 101
def loc2xref(entry)
if entry[:target]
"<xref nested='true' target='#{entry[:target]}'>#{entry[:label]}</xref>"
else
entry[:label]
end
end
|
#locality_delimiter(_loc) ⇒ Object
134
135
136
|
# File 'lib/isodoc/presentation_function/erefs.rb', line 134
def locality_delimiter(_loc)
", "
end
|
#localize_maths(node, locale) ⇒ Object
symbols is merged into TwitterCldr::DataReaders::NumberDataReader.new(locale).symbols
18
19
20
21
22
23
24
25
|
# File 'lib/isodoc/presentation_function/math.rb', line 18
def localize_maths(node, locale)
node.xpath(".//m:mn", MATHML).each do |x|
num = BigDecimal(x.text)
precision = /\./.match?(x.text) ? x.text.sub(/^.*\./, "").size : 0
x.children = localized_number(num, locale, precision)
rescue ArgumentError => e
end
end
|
#localized_number(num, locale, precision) ⇒ Object
By itself twitter-cldr does not support fraction part digits grouping and custom delimeter, will decorate fraction part manually
29
30
31
32
33
34
35
36
37
38
39
|
# File 'lib/isodoc/presentation_function/math.rb', line 29
def localized_number(num, locale, precision)
localized = localized_number1(num, locale, precision)
= (locale)
return localized unless [:decimal]
integer, fraction = localized.split([:decimal])
return localized if fraction.nil? || fraction.empty?
[integer, decorate_fraction_part(fraction, locale)]
.join([:decimal])
end
|
#localized_number1(num, locale, precision) ⇒ Object
41
42
43
44
45
46
47
|
# File 'lib/isodoc/presentation_function/math.rb', line 41
def localized_number1(num, locale, precision)
if precision.zero?
num.localize(locale).to_s
else
num.localize(locale).to_decimal.to_s(precision: precision)
end
end
|
#lower2cap(text) ⇒ Object
7
8
9
10
11
|
# File 'lib/isodoc/presentation_function/block.rb', line 7
def lower2cap(text)
return text if /^[[:upper:]][[:upper:]]/.match?(text)
text.capitalize
end
|
#mathml(docxml) ⇒ Object
9
10
11
12
13
14
|
# File 'lib/isodoc/presentation_function/math.rb', line 9
def mathml(docxml)
locale =
docxml.xpath("//m:math", MATHML).each do |f|
mathml1(f, locale)
end
end
|
#mathml1(node, locale) ⇒ Object
99
100
101
102
103
104
|
# File 'lib/isodoc/presentation_function/math.rb', line 99
def mathml1(node, locale)
mathml_style_inherit(node)
asciimath_dup(node)
localize_maths(node, locale)
mathml_number_to_number(node)
end
|
#mathml_number_to_number(node) ⇒ Object
112
113
114
115
116
117
118
119
120
|
# File 'lib/isodoc/presentation_function/math.rb', line 112
def mathml_number_to_number(node)
(node.elements.size == 1 && node.elements.first.name == "mn") or return
repl = node.at("./m:mn", MATHML).children
if node.parent.name == "stem"
node.parent.replace(repl)
else
node.replace(repl)
end
end
|
#mathml_style_inherit(node) ⇒ Object
106
107
108
109
110
|
# File 'lib/isodoc/presentation_function/math.rb', line 106
def mathml_style_inherit(node)
node.at("./ancestor::xmlns:strong") or return
node.children =
"<mstyle mathvariant='bold'>#{node.children.to_xml}</mstyle>"
end
|
#merge_preferred_eligible?(first, second) ⇒ Boolean
116
117
118
119
120
121
122
123
|
# File 'lib/isodoc/presentation_function/terms.rb', line 116
def merge_preferred_eligible?(first, second)
firstex = first.at(ns("./expression")) || {}
secondex = second.at(ns("./expression")) || {}
first["geographic-area"] == second["geographic-area"] &&
firstex["language"] == secondex["language"] &&
!first.at(ns("./pronunciation | ./grammar")) &&
!second.at(ns("./pronunciation | ./grammar"))
end
|
#merge_second_preferred(term) ⇒ Object
100
101
102
103
104
105
106
107
|
# File 'lib/isodoc/presentation_function/terms.rb', line 100
def merge_second_preferred(term)
pref = nil
term.xpath(ns("./preferred[expression/name]")).each_with_index do |p, i|
if i.zero? then pref = p
else merge_second_preferred1(pref, p)
end
end
end
|
#merge_second_preferred1(pref, second) ⇒ Object
109
110
111
112
113
114
|
# File 'lib/isodoc/presentation_function/terms.rb', line 109
def merge_second_preferred1(pref, second)
merge_preferred_eligible?(pref, second) or return
n1 = pref.at(ns("./expression/name"))
n2 = second.remove.at(ns("./expression/name"))
n1.children = l10n("#{to_xml(n1.children)}; #{Common::to_xml(n2.children)}")
end
|
97
98
99
100
101
102
103
|
# File 'lib/isodoc/presentation_xml_convert.rb', line 97
def metanorma_extension_insert_pt(xml)
xml.at(ns("//metanorma-extension")) ||
xml.at(ns("//bibdata"))&.after("<metanorma-extension/>")
&.next_element ||
xml.root.elements.first.before("<metanorma-extension/>")
.previous_element
end
|
#multidef(elem) ⇒ Object
206
207
208
209
210
211
212
213
214
|
# File 'lib/isodoc/presentation_function/terms.rb', line 206
def multidef(elem)
d = elem.at(ns("./definition"))
d = d.replace("<ol><li>#{to_xml(d.children)}</li></ol>").first
elem.xpath(ns("./definition")).each do |f|
f = f.replace("<li>#{to_xml(f.children)}</li>").first
d << f
end
d.wrap("<definition></definition>")
end
|
#non_locality_elems(node) ⇒ Object
5
6
7
8
9
|
# File 'lib/isodoc/presentation_function/inline.rb', line 5
def non_locality_elems(node)
node.children.reject do |c|
%w{locality localityStack location}.include? c.name
end
end
|
#norm_ref_entry_code(_ordinal, idents, _ids, _standard, datefn, _bib) ⇒ Object
139
140
141
142
143
144
145
146
147
|
# File 'lib/isodoc/presentation_function/refs.rb', line 139
def norm_ref_entry_code(_ordinal, idents, _ids, _standard, datefn, _bib)
ret = (idents[:ordinal] || idents[:metanorma] || idents[:sdo]).to_s
(idents[:ordinal] || idents[:metanorma]) && idents[:sdo] and
ret += ", #{idents[:sdo]}"
ret += datefn
ret.empty? and return ret
idents[:sdo] and ret += ","
"#{ret} "
end
|
#note(docxml) ⇒ Object
59
60
61
|
# File 'lib/isodoc/presentation_function/block.rb', line 59
def note(docxml)
docxml.xpath(ns("//note")).each { |f| note1(f) }
end
|
#note1(elem) ⇒ Object
63
64
65
66
67
68
69
70
71
|
# File 'lib/isodoc/presentation_function/block.rb', line 63
def note1(elem)
%w(bibdata bibitem).include?(elem.parent.name) ||
elem["notag"] == "true" and return
n = @xrefs.get[elem["id"]]
lbl = @i18n.note
(n.nil? || n[:label].nil? || n[:label].empty?) or
lbl = l10n("#{lbl} #{n[:label]}")
prefix_name(elem, "", lbl, "name")
end
|
#ol(docxml) ⇒ Object
140
141
142
143
|
# File 'lib/isodoc/presentation_function/block.rb', line 140
def ol(docxml)
docxml.xpath(ns("//ol")).each { |f| ol1(f) }
@xrefs.list_anchor_names(docxml.xpath(ns(@xrefs.sections_xpath)))
end
|
#ol1(elem) ⇒ Object
158
159
160
|
# File 'lib/isodoc/presentation_function/block.rb', line 158
def ol1(elem)
elem["type"] ||= ol_depth(elem).to_s
end
|
#ol_depth(node) ⇒ Object
We don’t really want users to specify type of ordered list; we will use by default a fixed hierarchy as practiced by ISO (though not fully spelled out): a) 1) i) A) I)
148
149
150
151
152
153
154
155
156
|
# File 'lib/isodoc/presentation_function/block.rb', line 148
def ol_depth(node)
depth = node.ancestors("ul, ol").size + 1
type = :alphabet
type = :arabic if [2, 7].include? depth
type = :roman if [3, 8].include? depth
type = :alphabet_upper if [4, 9].include? depth
type = :roman_upper if [5, 10].include? depth
type
end
|
#origin(docxml) ⇒ Object
52
53
54
|
# File 'lib/isodoc/presentation_function/inline.rb', line 52
def origin(docxml)
docxml.xpath(ns("//origin[not(termref)]")).each { |f| xref1(f) }
end
|
#parse_localize_number ⇒ Object
79
80
81
82
83
84
85
86
87
88
89
90
|
# File 'lib/isodoc/presentation_function/math.rb', line 79
def parse_localize_number
return {} unless @localizenumber
m = %r{(?<group>[^#])?(?<groupdigits>#+0)(?<decimal>.)(?<fractdigits>#+)(?<fractgroup>[^#])?}
.match(@localizenumber) or return {}
ret = { decimal: m[:decimal], group_digits: m[:groupdigits].size,
fraction_group_digits: m[:fractdigits].size,
group: m[:group] || "",
fraction_group: m[:fractgroup] || "" }.compact
%i(group fraction_group).each { |x| ret[x] == " " and ret[x] = "\u00A0" }
ret
end
|
#permission(docxml) ⇒ Object
104
105
106
107
108
|
# File 'lib/isodoc/presentation_function/block.rb', line 104
def permission(docxml)
docxml.xpath(ns("//permission")).each do |f|
recommendation1(f, lower2cap(@i18n.permission))
end
end
|
#postprocess(result, filename, _dir) ⇒ Object
134
135
136
137
|
# File 'lib/isodoc/presentation_xml_convert.rb', line 134
def postprocess(result, filename, _dir)
to_xml_file(result, filename)
@files_to_delete.each { |f| FileUtils.rm_rf f }
end
|
#prefix_bracketed_ref(text) ⇒ Object
163
164
165
|
# File 'lib/isodoc/presentation_function/refs.rb', line 163
def prefix_bracketed_ref(text)
"#{text}<tab/>"
end
|
#prefix_container(container, linkend, node, _target) ⇒ Object
3
4
5
|
# File 'lib/isodoc/presentation_function/xrefs.rb', line 3
def prefix_container(container, linkend, node, _target)
l10n("#{anchor_xref(node, container)}, #{linkend}")
end
|
#prefix_container?(container, node) ⇒ Boolean
56
57
58
59
60
61
62
|
# File 'lib/isodoc/presentation_function/xrefs.rb', line 56
def prefix_container?(container, node)
node["style"] == "modspec" and return false type = @xrefs.anchor(node["target"], :type)
container &&
get_note_container_id(node, type) != container &&
@xrefs.get[node["target"]]
end
|
#prefix_name(node, delim, number, elem) ⇒ Object
17
18
19
20
21
22
23
24
25
26
27
|
# File 'lib/isodoc/presentation_function/block.rb', line 17
def prefix_name(node, delim, number, elem)
number.nil? || number.empty? and return
unless name = node.at(ns("./#{elem}"))
(node.children.empty? and node.add_child("<#{elem}></#{elem}>")) or
node.children.first.previous = "<#{elem}></#{elem}>"
name = node.children.first
end
if name.children.empty? then name.add_child(cleanup_entities(number.strip))
else (name.children.first.previous = "#{number.strip}#{delim}")
end
end
|
#prep_for_rendering(bib) ⇒ Object
32
33
34
35
36
|
# File 'lib/isodoc/presentation_function/refs.rb', line 32
def prep_for_rendering(bib)
bib["suppress_identifier"] == true and
bib.xpath(ns("./docidentifier")).each(&:remove)
bib["type"] ||= "standard"
end
|
52
53
54
55
|
# File 'lib/isodoc/presentation_function/bibdata.rb', line 52
def presmeta(name, value)
"<presentation-metadata><name>#{name}</name><value>#{value}</value>" \
"</presentation-metadata>"
end
|
#quotesource(docxml) ⇒ Object
56
57
58
59
60
61
|
# File 'lib/isodoc/presentation_function/inline.rb', line 56
def quotesource(docxml)
docxml.xpath(ns("//quote/source")).each { |f| xref1(f) }
docxml.xpath(ns("//quote/source//xref")).each do |f|
f.replace(f.children)
end
end
|
#recommendation(docxml) ⇒ Object
92
93
94
95
96
|
# File 'lib/isodoc/presentation_function/block.rb', line 92
def recommendation(docxml)
docxml.xpath(ns("//recommendation")).each do |f|
recommendation1(f, lower2cap(@i18n.recommendation))
end
end
|
#recommendation1(elem, type) ⇒ Object
110
111
112
113
114
|
# File 'lib/isodoc/presentation_function/block.rb', line 110
def recommendation1(elem, type)
lbl = @reqt_models.model(elem["model"])
.recommendation_label(elem, type, xrefs)
prefix_name(elem, "", l10n(lbl), "name")
end
|
#references(docxml) ⇒ Object
3
4
5
6
7
8
9
10
11
|
# File 'lib/isodoc/presentation_function/refs.rb', line 3
def references(docxml)
bibliography_bibitem_number(docxml)
renderings = references_render(docxml)
docxml.xpath(ns("//references/bibitem")).each do |x|
bibitem(x, renderings)
end
hidden_items(docxml)
@xrefs.parse_inclusions(refs: true).parse(docxml)
end
|
#references_render(docxml) ⇒ Object
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/isodoc/presentation_function/refs.rb', line 21
def references_render(docxml)
d = docxml.clone
d.remove_namespaces!
refs = d.xpath("//references/bibitem").each_with_object([]) do |b, m|
prep_for_rendering(b)
m << to_xml(b)
end.join
bibrenderer.render_all("<references>#{refs}</references>",
type: citestyle)
end
|
77
78
79
|
# File 'lib/isodoc/presentation_function/terms.rb', line 77
def related(docxml)
docxml.xpath(ns("//related")).each { |f| related1(f) }
end
|
81
82
83
84
85
86
87
88
89
90
91
92
|
# File 'lib/isodoc/presentation_function/terms.rb', line 81
def related1(node)
p = node.at(ns("./preferred"))
ref = node.at(ns("./xref | ./eref | ./termref"))
label = @i18n.relatedterms[node["type"]].upcase
if p && ref
node.replace(l10n("<p><strong>#{label}:</strong> " \
"<em>#{to_xml(p)}</em> (#{Common::to_xml(ref)})</p>"))
else
node.replace(l10n("<p><strong>#{label}:</strong> " \
"<strong>**RELATED TERM NOT FOUND**</strong></p>"))
end
end
|
#requirement(docxml) ⇒ Object
98
99
100
101
102
|
# File 'lib/isodoc/presentation_function/block.rb', line 98
def requirement(docxml)
docxml.xpath(ns("//requirement")).each do |f|
recommendation1(f, lower2cap(@i18n.requirement))
end
end
|
#requirement_render(docxml) ⇒ Object
166
167
168
169
170
171
172
173
174
175
|
# File 'lib/isodoc/presentation_function/block.rb', line 166
def requirement_render(docxml)
requirement_render_preprocessing(docxml)
REQS.each do |x|
REQS.each do |y|
docxml.xpath(ns("//#{x}//#{y}")).each { |r| requirement_render1(r) }
end
end
docxml.xpath(ns("//requirement | //recommendation | //permission"))
.each { |r| requirement_render1(r) }
end
|
#requirement_render1(node) ⇒ Object
177
178
179
180
|
# File 'lib/isodoc/presentation_function/block.rb', line 177
def requirement_render1(node)
node.replace(@reqt_models.model(node["model"])
.requirement_render1(node))
end
|
#requirement_render_preprocessing(docxml) ⇒ Object
162
|
# File 'lib/isodoc/presentation_function/block.rb', line 162
def requirement_render_preprocessing(docxml); end
|
#resolve_comma_connectives(locs) ⇒ Object
61
62
63
64
65
66
67
68
69
|
# File 'lib/isodoc/presentation_function/erefs.rb', line 61
def resolve_comma_connectives(locs)
locs1 = []
add = ""
until locs.empty?
locs, locs1, add = resolve_comma_connectives1(locs, locs1, add)
end
locs1 << add unless add.empty?
locs1
end
|
#resolve_comma_connectives1(locs, locs1, add) ⇒ Object
71
72
73
74
75
76
77
78
79
80
81
|
# File 'lib/isodoc/presentation_function/erefs.rb', line 71
def resolve_comma_connectives1(locs, locs1, add)
if [", ", " ", ""].include?(locs[1])
add += locs[0..2].join
locs.shift(3)
else
locs1 << add unless add.empty?
add = ""
locs1 << locs.shift
end
[locs, locs1, add]
end
|
#resolve_eref_connectives(locs) ⇒ Object
50
51
52
53
54
55
56
57
58
59
|
# File 'lib/isodoc/presentation_function/erefs.rb', line 50
def resolve_eref_connectives(locs)
locs = resolve_comma_connectives(locs)
locs = resolve_to_connectives(locs)
return locs if locs.size < 3
locs = locs.each_slice(2).with_object([]) do |a, m|
m << { conn: a[0], label: a[1] }
end
[", ", combine_conn(locs)]
end
|
#resolve_to_connectives(locs) ⇒ Object
83
84
85
86
87
88
89
90
91
92
93
|
# File 'lib/isodoc/presentation_function/erefs.rb', line 83
def resolve_to_connectives(locs)
locs1 = []
until locs.empty?
if locs[1] == "to"
locs1 << @i18n.chain_to.sub(/%1/, locs[0]).sub(/%2/, locs[2])
locs.shift(3)
else locs1 << locs.shift
end
end
locs1
end
|
#section(docxml) ⇒ Object
parse annex after term, references, to deal with single-term and single-ref annexes
38
39
40
41
42
43
44
45
46
47
48
49
50
|
# File 'lib/isodoc/presentation_xml_convert.rb', line 38
def section(docxml)
references docxml
annex docxml
clause docxml
term docxml
index docxml
clausetitle docxml
floattitle docxml
toc docxml
display_order docxml
end
|
#semantic_xml_insert(xml) ⇒ Object
88
89
90
91
92
93
94
95
|
# File 'lib/isodoc/presentation_xml_convert.rb', line 88
def semantic_xml_insert(xml)
@semantic_xml_insert or return
embed = embedable_semantic_xml(xml)
ins = metanorma_extension_insert_pt(xml)
ins = ins.at(ns("./metanorma")) || ins.add_child("<metanorma/>").first
ins = ins.add_child("<source/>").first
ins << embed
end
|
#single_term_clause_retitle(elem) ⇒ Object
64
65
66
67
68
69
70
|
# File 'lib/isodoc/presentation_function/section.rb', line 64
def single_term_clause_retitle(elem)
t = elem.at(ns("./terms | ./definitions | ./references"))
title1 = elem.at(ns("./title"))
title2 = t.at(ns("./title"))&.remove
!title1 && title2 and
elem.first_element_child.previous = title2
end
|
#single_term_clause_unnest(elem) ⇒ Object
72
73
74
75
76
77
78
79
|
# File 'lib/isodoc/presentation_function/section.rb', line 72
def single_term_clause_unnest(elem)
t = elem.at(ns("./terms | ./definitions | ./references"))
t.xpath(ns(".//clause | .//terms | .//definitions | .//references"))
.each do |c|
tit = c.at(ns("./title")) or return
tit["depth"] = tit["depth"].to_i - 1 unless tit["depth"] == "1"
end
end
|
#source_highlight(elem) ⇒ Object
45
46
47
48
49
50
51
52
53
54
55
56
|
# File 'lib/isodoc/presentation_function/sourcecode.rb', line 45
def source_highlight(elem)
@highlighter or return
markup = source_remove_markup(elem)
p = source_lex(elem)
elem.children = if elem["linenums"] == "true"
r = sourcecode_table_to_elem(elem, p)
source_restore_markup_table(r, markup)
else
r = @highlighter[:formatter].format(p)
source_restore_markup(Nokogiri::XML.fragment(r), markup)
end
end
|
#source_label(elem) ⇒ Object
123
124
125
126
127
128
|
# File 'lib/isodoc/presentation_function/sourcecode.rb', line 123
def source_label(elem)
labelled_ancestor(elem) and return
lbl = @xrefs.anchor(elem["id"], :label, false) or return
prefix_name(elem, block_delim,
l10n("#{lower2cap @i18n.figure} #{lbl}"), "name")
end
|
#source_lex(elem) ⇒ Object
114
115
116
117
118
119
120
121
|
# File 'lib/isodoc/presentation_function/sourcecode.rb', line 114
def source_lex(elem)
lexer = (Rouge::Lexer.find(elem["lang"] || "plaintext") ||
Rouge::Lexer.find("plaintext"))
l = Rouge::Lexers::Escape.new(start: "{^^{", end: "}^^}", lang: lexer)
source = to_xml(elem.children).gsub(/</, "{^^{<").gsub(/>/, ">}^^}")
l.lang.reset!
l.lex(@c.decode(source))
end
|
#source_remove_annotations(ret, elem) ⇒ Object
65
66
67
68
69
70
71
|
# File 'lib/isodoc/presentation_function/sourcecode.rb', line 65
def source_remove_annotations(ret, elem)
ret[:ann] = elem.xpath(ns("./annotation")).each(&:remove)
ret[:call] = elem.xpath(ns("./callout")).each_with_object([]) do |c, m|
m << { xml: c.remove.to_xml, line: c.line - elem.line }
end
ret
end
|
#source_remove_markup(elem) ⇒ Object
58
59
60
61
62
63
|
# File 'lib/isodoc/presentation_function/sourcecode.rb', line 58
def source_remove_markup(elem)
ret = {}
name = elem.at(ns("./name")) and ret[:name] = name.remove.to_xml
source_remove_annotations(ret, elem)
ret
end
|
#source_restore_callouts(code, callouts) ⇒ Object
84
85
86
87
88
89
90
91
92
|
# File 'lib/isodoc/presentation_function/sourcecode.rb', line 84
def source_restore_callouts(code, callouts)
text = to_xml(code)
text.split(/[\n\r]/).each_with_index do |c, i|
while !callouts.empty? && callouts[0][:line] == i
c.sub!(/\s+$/, " <span class='c'>#{callouts[0][:xml]}</span> ")
callouts.shift
end
end.join("\n")
end
|
#source_restore_callouts_table(table, callouts) ⇒ Object
94
95
96
97
98
99
100
101
102
|
# File 'lib/isodoc/presentation_function/sourcecode.rb', line 94
def source_restore_callouts_table(table, callouts)
table.xpath(".//td[@class = 'rouge-code']/sourcecode")
.each_with_index do |c, i|
while !callouts.empty? && callouts[0][:line] == i
c << " <span class='c'>#{callouts[0][:xml]}</span> "
callouts.shift
end
end
end
|
#source_restore_markup(wrapper, markup) ⇒ Object
73
74
75
76
|
# File 'lib/isodoc/presentation_function/sourcecode.rb', line 73
def source_restore_markup(wrapper, markup)
ret = source_restore_callouts(wrapper, markup[:call])
"#{markup[:name]}#{ret}#{markup[:ann]}"
end
|
#source_restore_markup_table(wrapper, markup) ⇒ Object
78
79
80
81
82
|
# File 'lib/isodoc/presentation_function/sourcecode.rb', line 78
def source_restore_markup_table(wrapper, markup)
source_restore_callouts_table(wrapper, markup[:call])
ret = to_xml(wrapper)
"#{markup[:name]}#{ret}#{markup[:ann]}"
end
|
#sourcecode(docxml) ⇒ Object
32
33
34
35
36
37
38
|
# File 'lib/isodoc/presentation_function/sourcecode.rb', line 32
def sourcecode(docxml)
sourcehighlighter_css(docxml)
@highlighter = sourcehighlighter
docxml.xpath(ns("//sourcecode")).each do |f|
sourcecode1(f)
end
end
|
#sourcecode1(elem) ⇒ Object
40
41
42
43
|
# File 'lib/isodoc/presentation_function/sourcecode.rb', line 40
def sourcecode1(elem)
source_highlight(elem)
source_label(elem)
end
|
#sourcecode_table_to_elem(elem, tokens) ⇒ Object
104
105
106
107
108
109
110
111
112
|
# File 'lib/isodoc/presentation_function/sourcecode.rb', line 104
def sourcecode_table_to_elem(elem, tokens)
r = Nokogiri::XML(@highlighter[:formatter_line].format(tokens)).root
r.xpath(".//td[@class = 'rouge-code']/pre").each do |pre|
%w(style).each { |n| elem[n] and pre[n] = elem[n] }
pre.name = "sourcecode"
pre.children = to_xml(pre.children).sub(/\s+$/, "")
end
r
end
|
#sourcehighlighter ⇒ Object
23
24
25
26
27
28
29
30
|
# File 'lib/isodoc/presentation_function/sourcecode.rb', line 23
def sourcehighlighter
@sourcehighlighter or return
Rouge::Formatter.enable_escape!
f = Rouge::Formatters::HTML.new
opts = { gutter_class: "rouge-gutter", code_class: "rouge-code" }
f1 = Rouge::Formatters::HTMLLineTable.new(f, opts)
{ formatter: f, formatter_line: f1 }
end
|
#sourcehighlighter_css(docxml) ⇒ Object
3
4
5
6
7
8
9
10
|
# File 'lib/isodoc/presentation_function/sourcecode.rb', line 3
def sourcehighlighter_css(docxml)
ret = custom_css(docxml)
ret.empty? and return
ins = docxml.at(ns("//metanorma-extension")) ||
docxml.at(ns("//bibdata")).after("<metanorma-extension/>").next_element
ins << "<source-highlighter-css>#{ret}" \
"</source-highlighter-css>"
end
|
#svg_emf_double(img) ⇒ Object
75
76
77
78
79
80
81
82
|
# File 'lib/isodoc/presentation_function/image.rb', line 75
def svg_emf_double(img)
if emf?(img["mimetype"])
img = emf_encode(img)
img.children.first.previous = emf_to_svg(img)
elsif img["mimetype"] == "image/svg+xml"
src = svg_to_emf(img) and img << "<emf src='#{src}'/>"
end
end
|
36
37
38
39
40
41
42
43
44
45
46
47
|
# File 'lib/isodoc/presentation_function/image.rb', line 36
def (elem)
return unless %r{^data:image/svg\+xml;}.match?(elem["src"])
return if elem.at("./m:svg", SVG)
svg = Base64.strict_decode64(elem["src"]
.sub(%r{^data:image/svg\+xml;(charset=[^;]+;)?base64,}, ""))
x = Nokogiri::XML.fragment(svg.sub(/<\?xml[^>]*>/, "")) do |config|
config.huge
end
elem["src"] = ""
elem.children = x
end
|
#svg_prep(img) ⇒ Object
91
92
93
94
95
|
# File 'lib/isodoc/presentation_function/image.rb', line 91
def svg_prep(img)
img["mimetype"] = "image/svg+xml"
%r{^data:image}.match?(img["src"]) or
img["src"] = Metanorma::Utils::datauri(img["src"])
end
|
#svg_to_emf(node) ⇒ Object
109
110
111
112
113
114
115
116
117
118
119
|
# File 'lib/isodoc/presentation_function/image.rb', line 109
def svg_to_emf(node)
uri = svg_to_emf_uri(node)
if node.elements&.first&.name == "svg" &&
(!node["height"] || node["height"] == "auto")
node["height"] = node.elements.first["height"]
node["width"] = node.elements.first["width"]
end
ret = imgfile_suffix(uri, "emf")
File.exist?(ret) and return ret
inkscape_convert(uri, ret, '--export-type="emf"')
end
|
#svg_to_emf_uri(node) ⇒ Object
132
133
134
135
|
# File 'lib/isodoc/presentation_function/image.rb', line 132
def svg_to_emf_uri(node)
uri = svg_to_emf_uri_convert(node)
cache_dataimage(uri)
end
|
#svg_to_emf_uri_convert(node) ⇒ Object
150
151
152
153
154
155
156
|
# File 'lib/isodoc/presentation_function/image.rb', line 150
def svg_to_emf_uri_convert(node)
if node.elements&.first&.name == "svg"
a = Base64.strict_encode64(node.children.to_xml)
"data:image/svg+xml;base64,#{a}"
else node["src"]
end
end
|
#svg_wrap(elem) ⇒ Object
16
17
18
19
20
21
|
# File 'lib/isodoc/presentation_function/image.rb', line 16
def svg_wrap(elem)
return if elem.parent.name == "image"
elem.wrap("<image src='' mimetype='image/svg+xml' height='auto' " \
"width='auto'></image>")
end
|
23
24
25
26
27
|
# File 'lib/isodoc/presentation_function/image.rb', line 23
def (elem)
if f = elem.at(ns("./figure")) then elem.replace(f)
else elem.remove
end
end
|
#table(docxml) ⇒ Object
116
117
118
|
# File 'lib/isodoc/presentation_function/block.rb', line 116
def table(docxml)
docxml.xpath(ns("//table")).each { |f| table1(f) }
end
|
#table1(elem) ⇒ Object
120
121
122
123
124
125
126
|
# File 'lib/isodoc/presentation_function/block.rb', line 120
def table1(elem)
labelled_ancestor(elem) and return
elem["unnumbered"] && !elem.at(ns("./name")) and return
n = @xrefs.anchor(elem["id"], :label, false)
prefix_name(elem, block_delim, l10n("#{lower2cap @i18n.table} #{n}"),
"name")
end
|
#tag_translate(tag, lang, value) ⇒ Object
113
114
115
116
117
118
|
# File 'lib/isodoc/presentation_function/bibdata.rb', line 113
def tag_translate(tag, lang, value)
tag["language"] = ""
tag.next = tag.dup
tag.next["language"] = lang
tag.next.children = value
end
|
#term(docxml) ⇒ Object
81
82
83
84
85
|
# File 'lib/isodoc/presentation_function/section.rb', line 81
def term(docxml)
docxml.xpath(ns("//term")).each do |f|
term1(f)
end
end
|
#term1(elem) ⇒ Object
87
88
89
90
|
# File 'lib/isodoc/presentation_function/section.rb', line 87
def term1(elem)
lbl = @xrefs.anchor(elem["id"], :label) or return
prefix_name(elem, "", "#{lbl}#{clausedelim}", "name")
end
|
#termdefinition(docxml) ⇒ Object
195
196
197
198
199
|
# File 'lib/isodoc/presentation_function/terms.rb', line 195
def termdefinition(docxml)
docxml.xpath(ns("//term[definition]")).each do |f|
termdefinition1(f)
end
end
|
#termdefinition1(elem) ⇒ Object
201
202
203
204
|
# File 'lib/isodoc/presentation_function/terms.rb', line 201
def termdefinition1(elem)
unwrap_definition(elem)
multidef(elem) if elem.xpath(ns("./definition")).size > 1
end
|
#termexample(docxml) ⇒ Object
182
183
184
|
# File 'lib/isodoc/presentation_function/terms.rb', line 182
def termexample(docxml)
docxml.xpath(ns("//termexample")).each { |f| example1(f) }
end
|
#termnote(docxml) ⇒ Object
186
187
188
|
# File 'lib/isodoc/presentation_function/terms.rb', line 186
def termnote(docxml)
docxml.xpath(ns("//termnote")).each { |f| termnote1(f) }
end
|
#termnote1(elem) ⇒ Object
190
191
192
193
|
# File 'lib/isodoc/presentation_function/terms.rb', line 190
def termnote1(elem)
lbl = l10n(@xrefs.anchor(elem["id"], :label) || "???")
prefix_name(elem, "", lower2cap(lbl), "name")
end
|
#terms(docxml) ⇒ Object
78
79
80
81
82
83
84
85
86
|
# File 'lib/isodoc/presentation_xml_convert.rb', line 78
def terms(docxml)
termexample docxml
termnote docxml
termdefinition docxml
designation docxml
termsource docxml
concept docxml
related docxml
end
|
#termsource(docxml) ⇒ Object
225
226
227
228
229
230
231
232
|
# File 'lib/isodoc/presentation_function/terms.rb', line 225
def termsource(docxml)
docxml.xpath(ns("//termsource/modification")).each do |f|
termsource_modification(f)
end
docxml.xpath(ns("//termsource")).each do |f|
termsource1(f)
end
end
|
#termsource1(elem) ⇒ Object
234
235
236
237
238
239
|
# File 'lib/isodoc/presentation_function/terms.rb', line 234
def termsource1(elem)
while elem&.next_element&.name == "termsource"
elem << "; #{to_xml(elem.next_element.remove.children)}"
end
elem.children = l10n("[#{@i18n.source}: #{to_xml(elem.children).strip}]")
end
|
#termsource_modification(mod) ⇒ Object
241
242
243
244
245
246
247
|
# File 'lib/isodoc/presentation_function/terms.rb', line 241
def termsource_modification(mod)
mod.previous_element.next = l10n(", #{@i18n.modified}")
mod.text.strip.empty? or mod.previous = " – "
mod.elements.size == 1 and
mod.elements[0].replace(mod.elements[0].children)
mod.replace(mod.children)
end
|
#to_xml_file(result, filename) ⇒ Object
139
140
141
|
# File 'lib/isodoc/presentation_xml_convert.rb', line 139
def to_xml_file(result, filename)
File.open(filename, "w:UTF-8") { |f| f.write(result) }
end
|
#toc(docxml) ⇒ Object
129
130
131
132
133
134
|
# File 'lib/isodoc/presentation_function/section.rb', line 129
def toc(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
|
17
18
19
20
21
22
23
24
25
26
27
28
29
|
# File 'lib/isodoc/presentation_function/bibdata.rb', line 17
def toc_metadata(docxml)
return unless @tocfigures || @toctables || @tocrecommendations
ins = docxml.at(ns("//metanorma-extension")) ||
docxml.at(ns("//bibdata")).after("<metanorma-extension/>").next_element
@tocfigures and
ins << "<toc type='figure'><title>#{@i18n.toc_figures}</title></toc>"
@toctables and
ins << "<toc type='table'><title>#{@i18n.toc_tables}</title></toc>"
@tocfigures and
ins << "<toc type='recommendation'><title>#{@i18n.toc_recommendations}" \
"</title></toc>"
end
|
#trim_hash(hash) ⇒ Object
160
161
162
163
164
165
166
167
|
# File 'lib/isodoc/presentation_function/bibdata.rb', line 160
def trim_hash(hash)
loop do
h_new = trim_hash1(hash)
break hash if hash == h_new
hash = h_new
end
end
|
#trim_hash1(hash) ⇒ Object
169
170
171
172
173
174
175
176
177
178
179
180
181
182
|
# File 'lib/isodoc/presentation_function/bibdata.rb', line 169
def trim_hash1(hash)
return hash unless hash.is_a? Hash
hash.each_with_object({}) do |(k, v), g|
next if blank?(v)
g[k] = case v
when Hash then trim_hash1(hash[k])
when Array
hash[k].map { |a| trim_hash1(a) }.reject { |a| blank?(a) }
else v
end
end
end
|
73
74
75
76
77
|
# File 'lib/isodoc/presentation_function/math.rb', line 73
def
locale = TwitterCldr.supported_locale?(@lang.to_sym) ? @lang.to_sym : :en
(locale)
locale
end
|
60
61
62
|
# File 'lib/isodoc/presentation_function/math.rb', line 60
def
{}
end
|
64
65
66
67
68
69
70
71
|
# File 'lib/isodoc/presentation_function/math.rb', line 64
def (locale)
return @twitter_cldr_reader if @twitter_cldr_reader
num = TwitterCldr::DataReaders::NumberDataReader.new(locale)
@twitter_cldr_reader = num.symbols.merge!()
.merge!(parse_localize_number)
@twitter_cldr_reader
end
|
#unnest_linkend(node) ⇒ Object
so not <origin bibitemid=“ISO7301” citeas=“ISO 7301”> <locality type=“section”><reference>3.1</reference></locality></origin>
26
27
28
29
30
31
32
|
# File 'lib/isodoc/presentation_function/inline.rb', line 26
def unnest_linkend(node)
return unless node.at(ns("./xref[@nested]"))
node.xpath(ns("./xref[@nested]")).each { |x| x.delete("nested") }
node.xpath(ns("./location | ./locationStack")).each(&:remove)
node.replace(node.children)
end
|
#unwrap_definition(elem) ⇒ Object
216
217
218
219
220
221
222
223
|
# File 'lib/isodoc/presentation_function/terms.rb', line 216
def unwrap_definition(elem)
elem.xpath(ns("./definition")).each do |d|
%w(verbal-definition non-verbal-representation).each do |e|
v = d&.at(ns("./#{e}"))
v&.replace(v.children)
end
end
end
|
#variant(docxml) ⇒ Object
67
68
69
70
71
72
73
74
75
76
|
# File 'lib/isodoc/presentation_function/inline.rb', line 67
def variant(docxml)
docxml.xpath(ns("//variant")).each { |f| variant1(f) }
docxml.xpath(ns("//variant[@remove = 'true']")).each(&:remove)
docxml.xpath(ns("//variant")).each do |v|
next unless v&.next&.name == "variant"
v.next = "/"
end
docxml.xpath(ns("//variant")).each { |f| f.replace(f.children) }
end
|
#variant1(node) ⇒ Object
78
79
80
81
82
83
84
|
# File 'lib/isodoc/presentation_function/inline.rb', line 78
def variant1(node)
if !((!node["lang"] || node["lang"] == @lang) &&
(!node["script"] || node["script"] == @script)) &&
found_matching_variant_sibling(node)
node["remove"] = "true"
end
end
|
#xref(docxml) ⇒ Object
41
42
43
44
|
# File 'lib/isodoc/presentation_function/inline.rb', line 41
def xref(docxml)
docxml.xpath(ns("//xref")).each { |f| xref1(f) }
docxml.xpath(ns("//xref//xref")).each { |f| f.replace(f.children) }
end
|
#xref1(node) ⇒ Object
63
64
65
|
# File 'lib/isodoc/presentation_function/inline.rb', line 63
def xref1(node)
get_linkend(node)
end
|
#xref_empty?(node) ⇒ Boolean
34
35
36
37
|
# File 'lib/isodoc/presentation_function/inline.rb', line 34
def xref_empty?(node)
c1 = non_locality_elems(node).select { |c| !c.text? || /\S/.match(c) }
c1.empty?
end
|