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/reqt.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/concepts.rb,
lib/isodoc/presentation_function/metadata.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
- COPY_XSLT =
'<xsl:copy><xsl:apply-templates select="@* | node()"/></xsl:copy>'.freeze
- COPY_CHILDREN_XSLT =
'<xsl:apply-templates select="node()"/>'.freeze
Constants inherited
from Convert
Convert::AGENCIES
Function::Utils::CLAUSE_ANCESTOR, Function::Utils::DOCTYPE_HDR, Function::Utils::HUGESTRICT, Function::Utils::LABELLED_ANCESTOR_ELEMENTS, Function::Utils::NOTE_CONTAINER_ANCESTOR
Function::ToWordHtml::TOP_ELEMENTS
Function::Table::SW
Function::Section::TERM_CLAUSE
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
#bibrender, #doctype, #i18n, #meta, #options, #reqt_models, #requirements_processor, #tempfile_cache, #wordcoverpage, #wordintropage, #xrefs
Instance Method Summary
collapse
-
#address_precompose(bib) ⇒ Object
-
#address_precompose1(addr) ⇒ Object
-
#admits(elem) ⇒ 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, container: false) ⇒ Object
-
#anchor_xref_full(num, title) ⇒ Object
-
#anchor_xref_short(node, target, container) ⇒ Object
-
#annex(docxml) ⇒ Object
-
#annex1(elem) ⇒ Object
-
#annotations(elem) ⇒ Object
-
#asciimath_dup(node) ⇒ Object
-
#bibdata(docxml) ⇒ Object
-
#bibdata_current(docxml) ⇒ Object
-
#bibdata_i18n(bib) ⇒ Object
-
#bibitem(xml, renderings) ⇒ Object
-
#bibitem_lookup(docxml) ⇒ 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_formattedref(formattedref, xml) ⇒ Object
-
#bibrender_item(xml, renderings) ⇒ Object
-
#bibrender_relaton(xml, renderings) ⇒ Object
-
#blank?(elem) ⇒ Boolean
-
#block(docxml) ⇒ Object
-
#block_delim ⇒ Object
-
#callouts(elem) ⇒ Object
-
#can_conflate_eref_rendering?(refs) ⇒ Boolean
-
#can_conflate_xref_rendering?(locs) ⇒ Boolean
-
#capitalise_xref(node, linkend, label) ⇒ Object
-
#capitalise_xref1(node, linkend) ⇒ Object
-
#change_case(span, value, seen_space) ⇒ Object
-
#citeas(xmldoc) ⇒ Object
-
#citestyle ⇒ Object
-
#cjk_extended_title(docxml) ⇒ Object
-
#cjk_search ⇒ Object
-
#clause(docxml) ⇒ Object
-
#clause1(elem) ⇒ Object
-
#clausetitle(docxml) ⇒ Object
-
#combine_conflated_xref_locations(locs) ⇒ Object
Note % to entry and Note % to entry: cannot conflate as Note % to entry 1 and 2 So Notes 1 and 3, but Note 1 to entry and Note 3 to entry.
-
#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
-
#conditional_capitalize(text, seen_space) ⇒ Object
-
#conflate_xref_locations(locs) ⇒ Object
-
#conversions(docxml) ⇒ Object
-
#convert1(docxml, _filename, _dir) ⇒ Object
-
#custom_charset(docxml) ⇒ Object
-
#custom_css(docxml) ⇒ Object
-
#date(docxml) ⇒ Object
-
#date1(elem) ⇒ Object
-
#date_note_process(bib) ⇒ Object
strip any fns in docidentifier before they are extracted for rendering.
-
#decorate_fraction_part(fract, locale) ⇒ Object
-
#deprecates(elem) ⇒ Object
-
#designation(docxml) ⇒ Object
-
#designation1(desgn) ⇒ Object
-
#designation_annotate(desgn, name) ⇒ Object
-
#designation_boldface(desgn) ⇒ Object
-
#designation_bookmarks(desgn, name) ⇒ 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.
-
#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_from_node(node, target_path = nil) ⇒ Object
-
#eref(docxml) ⇒ Object
-
#eref2link(docxml) ⇒ Object
-
#eref2link1(node, href) ⇒ Object
-
#eref2xref(node) ⇒ 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
-
#eref_target(node) ⇒ Object
-
#eref_url(id) ⇒ Object
-
#erefstack1(elem) ⇒ Object
-
#example(docxml) ⇒ Object
-
#example1(elem) ⇒ Object
-
#expand_citeas(text) ⇒ Object
-
#extension_insert(xml, path = []) ⇒ Object
-
#extension_insert_pt(xml) ⇒ Object
-
#extract_custom_charsets(docxml) ⇒ Object
-
#figure(docxml) ⇒ Object
-
#figure1(elem) ⇒ Object
-
#figure_label(elem) ⇒ Object
-
#figuresource(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.
-
#inline(docxml) ⇒ Object
-
#inline_format(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_linebreak(node) ⇒ Object
-
#mathml_number(node, locale) ⇒ Object
-
#mathml_number_to_number(node) ⇒ Object
-
#mathml_style_inherit(node) ⇒ Object
-
#maths_just_numeral(node) ⇒ Object
-
#merge_preferred_eligible?(first, second) ⇒ Boolean
-
#merge_second_preferred(term) ⇒ Object
-
#merge_second_preferred1(pref, second) ⇒ Object
-
#metadata(docxml) ⇒ Object
-
#metanorma_extension_insert_pt(xml) ⇒ Object
-
#middle_title(docxml) ⇒ Object
-
#move_norm_ref_to_sections(docxml) ⇒ 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
-
#numeric_mathml?(node) ⇒ Boolean
-
#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).
-
#ol_label(elem) ⇒ Object
-
#origin(docxml) ⇒ Object
-
#parse_localize_number ⇒ Object
-
#passthrough(docxml) ⇒ Object
-
#passthrough1(elem, formats) ⇒ Object
-
#passthrough_xslt ⇒ Object
-
#permission(docxml) ⇒ Object
-
#postprocess(result, filename, _dir) ⇒ Object
-
#preceding_floating_titles(node, idx) ⇒ Object
-
#preceding_floats(clause) ⇒ Object
-
#preface_move(clause, after, _doc) ⇒ Object
-
#preface_move1(clause, preface, float, prev, xpath) ⇒ Object
-
#preface_rearrange(doc) ⇒ 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
-
#preprocess_xslt_insert(docxml) ⇒ Object
-
#preprocess_xslt_read ⇒ Object
read in from file, but with ‘<preprocess-xslt @format=“”>` wrapper.
-
#presmeta(name, value) ⇒ Object
-
#presmeta_insert_pt(xmldoc) ⇒ Object
-
#quotesource(docxml) ⇒ Object
-
#rearrange_clauses(docxml) ⇒ Object
-
#recommendation(docxml) ⇒ Object
-
#recommendation1(elem, type) ⇒ Object
-
#references(docxml) ⇒ Object
-
#references_render(docxml) ⇒ Object
-
#reinsert_callout(xml) ⇒ 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
-
#rouge_css_location ⇒ Object
replace in local gem rather than specify overrides of default.
-
#ruby(docxml) ⇒ Object
-
#ruby1(elem) ⇒ 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(docxml) ⇒ Object
-
#source1(elem) ⇒ Object
-
#source_highlight(elem) ⇒ Object
-
#source_label(elem) ⇒ Object
-
#source_lex(elem) ⇒ Object
-
#source_modification(mod) ⇒ 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
-
#suffix_url(url) ⇒ Object
-
#svg_emf_double(img) ⇒ Object
-
#svg_extract(elem) ⇒ Object
-
#svg_impose_height_attr(node) ⇒ Object
-
#svg_prep(img) ⇒ Object
-
#svg_to_emf(node) ⇒ Object
-
#svg_to_emf_from_node(node, target_path = nil) ⇒ Object
-
#svg_wrap(elem) ⇒ Object
-
#svgmap_extract(elem) ⇒ Object
-
#table(docxml) ⇒ Object
-
#table1(elem) ⇒ Object
-
#table_long_strings_cleanup(docxml) ⇒ Object
-
#tablesource(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_add_modification_text(mod) ⇒ Object
-
#termsource_modification(elem) ⇒ Object
-
#termsource_status(status) ⇒ Object
-
#text_transform(docxml) ⇒ Object
-
#text_transform1(span) ⇒ Object
-
#to_xml_file(result, filename) ⇒ Object
-
#toc(docxml) ⇒ Object
-
#toc_metadata(docxml) ⇒ Object
-
#toc_refs(docxml) ⇒ Object
-
#toc_title(docxml) ⇒ Object
-
#toc_title_insert_pt(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(xml) ⇒ Object
-
#variant1(node) ⇒ Object
-
#xref(docxml) ⇒ Object
-
#xref1(node) ⇒ Object
-
#xref_empty?(node) ⇒ Boolean
-
#xslt_template(content) ⇒ Object
Methods inherited from Convert
#agency?, #bibrenderer, #convert, #convert1_namespaces, #convert_i18n_init, #convert_i18n_init1, #convert_init, #convert_scss, #default_file_locations, #default_fonts, #extract_preprocess_xslt, #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, #preprocess_xslt, #scss_fontheader, #swap_renderer, #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, #content, #define_head, #info, #init_dir, #init_file, #make_body, #make_body1, #make_body2, #make_body3, #note?, #parse, #rel_tmpimagedir, #set_termdomain, #tmpimagedir, #top_element_render
#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_parse_tail, #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, #executivesummary, #feedback_parse, #foreword, #indexsect, #inline_header_title, #introduction, #is_clause?, #legal_parse, #license_parse, #preface, #preface_attrs, #preface_block, #preface_normal, #scope, #single_term_clause?, #symbols_abbrevs, #symbols_parse, #table_of_contents, #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, #pref_ref_code_parse, #reference_format, #render_identifier, #standard?, #std_bibitem_entry, #unbracket, #unbracket1
#dl_attrs, #dl_parse, #dl_parse1, #dl_parse_notes, #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, #error_parse, #hr_parse, #image_body_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, #rb_parse, #rt_parse, #ruby_parse, #section_break, #smallcap_parse, #span_parse, #stem_parse, #strike_parse, #strong_parse, #sub_parse, #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, #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_note_cleanup, #textcleanup
#admonition_attrs, #admonition_class, #admonition_name, #admonition_name_parse, #admonition_parse, #annotation_parse, #columnbreak_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, #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, #source_parse, #sourcecode_attrs, #sourcecode_name_parse, #sourcecode_parse, #sourcecode_parse1, #svg_parse, #toc_parse
Constructor Details
Returns a new instance of PresentationXMLConvert.
15
16
17
18
19
|
# File 'lib/isodoc/presentation_xml_convert.rb', line 15
def initialize(options)
@format = :presentation
@suffix = "presentation.xml"
super
end
|
Instance Method Details
#address_precompose(bib) ⇒ Object
11
12
13
14
15
16
17
18
|
# File 'lib/isodoc/presentation_function/bibdata.rb', line 11
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
20
21
22
23
24
25
26
27
28
|
# File 'lib/isodoc/presentation_function/bibdata.rb', line 20
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
|
#admits(elem) ⇒ Object
15
|
# File 'lib/isodoc/presentation_function/terms.rb', line 15
def admits(elem); end
|
#admonition(docxml) ⇒ Object
72
73
74
|
# File 'lib/isodoc/presentation_function/block.rb', line 72
def admonition(docxml)
docxml.xpath(ns("//admonition")).each { |f| admonition1(f) }
end
|
#admonition1(elem) ⇒ Object
76
77
78
79
80
81
82
83
|
# File 'lib/isodoc/presentation_function/block.rb', line 76
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
85
86
87
88
89
|
# File 'lib/isodoc/presentation_function/block.rb', line 85
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
116
117
118
|
# File 'lib/isodoc/presentation_function/block.rb', line 116
def amend(docxml)
docxml.xpath(ns("//amend")).each { |f| amend1(f) }
end
|
#amend1(elem) ⇒ Object
120
121
122
123
124
125
|
# File 'lib/isodoc/presentation_function/block.rb', line 120
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
33
34
35
|
# File 'lib/isodoc/presentation_function/xrefs.rb', line 33
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
19
20
21
22
23
24
25
26
27
28
29
30
31
|
# File 'lib/isodoc/presentation_function/xrefs.rb', line 19
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
37
38
39
40
41
42
|
# File 'lib/isodoc/presentation_function/xrefs.rb', line 37
def anchor_linkend1(node)
linkend = anchor_xref(node, node["target"])
container = @xrefs.anchor(node["target"], :container, false)
linkend = prefix_container(container, linkend, node, node["target"])
capitalise_xref(node, linkend, anchor_value(node["target"]))
end
|
#anchor_value(id) ⇒ Object
14
15
16
17
|
# File 'lib/isodoc/presentation_function/xrefs.rb', line 14
def anchor_value(id)
@xrefs.anchor(id, :bare_xref) || @xrefs.anchor(id, :value) ||
@xrefs.anchor(id, :label) || @xrefs.anchor(id, :xref)
end
|
#anchor_xref(node, target, container: false) ⇒ Object
44
45
46
47
48
49
50
51
52
53
54
|
# File 'lib/isodoc/presentation_function/xrefs.rb', line 44
def anchor_xref(node, target, container: false)
x = anchor_xref_short(node, target, container)
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
63
64
65
66
|
# File 'lib/isodoc/presentation_function/xrefs.rb', line 63
def anchor_xref_full(num, title)
(!title.nil? && !title.empty?) or return nil
l10n("#{num}, #{title}")
end
|
#anchor_xref_short(node, target, container) ⇒ Object
56
57
58
59
60
61
|
# File 'lib/isodoc/presentation_function/xrefs.rb', line 56
def anchor_xref_short(node, target, container)
if (l = node["label"]) && !container
@i18n.l10n("#{l} #{anchor_value(target)}")
else @xrefs.anchor(target, :xref)
end
end
|
#annex(docxml) ⇒ Object
54
55
56
57
58
59
60
61
|
# File 'lib/isodoc/presentation_function/section.rb', line 54
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
63
64
65
66
67
68
69
|
# File 'lib/isodoc/presentation_function/section.rb', line 63
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
|
#annotations(elem) ⇒ Object
57
58
59
60
61
62
63
64
65
66
67
68
|
# File 'lib/isodoc/presentation_function/sourcecode.rb', line 57
def annotations(elem)
elem.at(ns("./annotation")) or return
ret = ""
elem.xpath(ns("./annotation")).each do |a|
a.remove
ret += <<~OUT
<dt id='#{a['id']}'><span class='c'>#{@callouts[a['id']]}</span></dt>
<dd>#{a.children.to_xml}</dd>
OUT
end
elem << "<dl><name>#{@i18n.key}</name>#{ret}</dl>"
end
|
#asciimath_dup(node) ⇒ Object
92
93
94
95
96
97
98
99
100
|
# File 'lib/isodoc/presentation_function/math.rb', line 92
def asciimath_dup(node)
@suppressasciimathdup || node.parent.at(ns("./asciimath")) and return
math = node.to_xml.gsub(/ xmlns=["'][^"']+["']/, "")
.gsub(%r{<[^:/>]+:}, "<").gsub(%r{</[^:/>]+:}, "</")
ret = Plurimath::Math.parse(math, "mathml").to_asciimath
node.next = "<asciimath>#{@c.encode(ret, :basic)}</asciimath>"
rescue StandardError => e
warn "Failure to convert MathML to AsciiMath\n#{node.parent.to_xml}\n#{e}"
end
|
#bibdata(docxml) ⇒ Object
5
6
7
8
9
|
# File 'lib/isodoc/presentation_function/bibdata.rb', line 5
def bibdata(docxml)
a = bibdata_current(docxml) or return
address_precompose(a)
bibdata_i18n(a)
end
|
#bibdata_current(docxml) ⇒ Object
30
31
32
33
34
35
36
37
38
39
|
# File 'lib/isodoc/presentation_function/bibdata.rb', line 30
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
41
42
43
44
45
46
|
# File 'lib/isodoc/presentation_function/bibdata.rb', line 41
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
50
51
52
53
|
# File 'lib/isodoc/presentation_function/refs.rb', line 50
def bibitem(xml, renderings)
@xrefs.klass.implicit_reference(xml) and xml["hidden"] = "true"
bibrender_item(xml, renderings)
end
|
#bibitem_lookup(docxml) ⇒ Object
30
31
32
33
34
35
|
# File 'lib/isodoc/presentation_xml_convert.rb', line 30
def bibitem_lookup(docxml)
@bibitem_lookup ||= docxml.xpath(ns("//references/bibitem"))
.each_with_object({}) do |b, m|
m[b["id"]] = b
end
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
160
161
162
163
164
165
166
167
168
169
170
|
# File 'lib/isodoc/presentation_function/refs.rb', line 160
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
82
83
84
85
86
87
88
89
|
# File 'lib/isodoc/presentation_function/refs.rb', line 82
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
91
92
93
94
95
96
97
98
99
100
101
102
|
# File 'lib/isodoc/presentation_function/refs.rb', line 91
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
104
105
106
107
108
109
110
|
# File 'lib/isodoc/presentation_function/refs.rb', line 104
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
75
76
77
78
79
80
|
# File 'lib/isodoc/presentation_function/refs.rb', line 75
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
118
119
120
121
122
123
124
125
|
# File 'lib/isodoc/presentation_function/refs.rb', line 118
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
127
128
129
130
131
132
133
134
|
# File 'lib/isodoc/presentation_function/refs.rb', line 127
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
|
62
|
# File 'lib/isodoc/presentation_function/refs.rb', line 62
def bibrender_formattedref(formattedref, xml); end
|
#bibrender_item(xml, renderings) ⇒ Object
55
56
57
58
59
60
|
# File 'lib/isodoc/presentation_function/refs.rb', line 55
def bibrender_item(xml, renderings)
if (f = xml.at(ns("./formattedref"))) && xml.at(ns("./title")).nil?
bibrender_formattedref(f, xml)
else bibrender_relaton(xml, renderings)
end
end
|
#bibrender_relaton(xml, renderings) ⇒ Object
64
65
66
67
68
69
|
# File 'lib/isodoc/presentation_function/refs.rb', line 64
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
|
#blank?(elem) ⇒ Boolean
158
159
160
|
# File 'lib/isodoc/presentation_function/metadata.rb', line 158
def blank?(elem)
elem.nil? || (elem.respond_to?(:empty?) && elem.empty?)
end
|
#block(docxml) ⇒ Object
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
# File 'lib/isodoc/presentation_xml_convert.rb', line 67
def block(docxml)
amend docxml
table docxml
figure docxml
sourcecode docxml
formula docxml
example docxml
note docxml
admonition docxml
source docxml
ol docxml
permission docxml
requirement docxml
recommendation docxml
requirement_render docxml
end
|
#block_delim ⇒ Object
12
13
14
|
# File 'lib/isodoc/presentation_function/block.rb', line 12
def block_delim
" — "
end
|
#callouts(elem) ⇒ Object
35
36
37
38
39
|
# File 'lib/isodoc/presentation_function/sourcecode.rb', line 35
def callouts(elem)
elem.xpath(ns(".//callout")).each do |c|
@callouts[c["target"]] = c.children.to_xml
end
end
|
#can_conflate_eref_rendering?(refs) ⇒ Boolean
46
47
48
49
50
51
52
53
54
|
# File 'lib/isodoc/presentation_function/erefs.rb', line 46
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
151
152
153
154
155
156
|
# File 'lib/isodoc/presentation_function/xrefs.rb', line 151
def can_conflate_xref_rendering?(locs)
@i18n.get["no_conflate_xref_locations"] == true and return false
(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
158
159
160
161
162
163
164
165
|
# File 'lib/isodoc/presentation_function/xrefs.rb', line 158
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
167
168
169
170
171
172
|
# File 'lib/isodoc/presentation_function/xrefs.rb', line 167
def capitalise_xref1(node, linkend)
if start_of_sentence(node)
Common::case_with_markup(linkend, "capital", @script)
else linkend
end
end
|
#change_case(span, value, seen_space) ⇒ Object
124
125
126
127
128
129
130
131
132
133
134
135
|
# File 'lib/isodoc/presentation_function/inline.rb', line 124
def change_case(span, value, seen_space)
span.traverse do |s|
s.text? or next
case value
when "uppercase" then s.replace s.text.upcase
when "lowercase" then s.replace s.text.downcase
when "capitalize"
s.replace conditional_capitalize(s.text, seen_space)
end
seen_space = /\s$/.match?(s.text)
end
end
|
#citeas(xmldoc) ⇒ Object
5
6
7
8
9
10
|
# File 'lib/isodoc/presentation_function/erefs.rb', line 5
def citeas(xmldoc)
xmldoc.xpath(ns("//eref | //origin | //quote/source")).each do |e|
e["bibitemid"] && e["citeas"] or next
a = @xrefs.anchor(e["bibitemid"], :xref, false) and e["citeas"] = a
end
end
|
#citestyle ⇒ Object
71
72
73
|
# File 'lib/isodoc/presentation_function/refs.rb', line 71
def citestyle
nil
end
|
#cjk_extended_title(docxml) ⇒ Object
157
158
159
160
161
162
163
164
165
|
# File 'lib/isodoc/presentation_function/section.rb', line 157
def cjk_extended_title(docxml)
l = cjk_search
docxml.xpath(ns("//bibdata/title[#{l}] | //floating-title[#{l}] | " \
"//title[@depth = '1' or not(@depth)][#{l}]")).each do |t|
t.text.size < 4 or next
t.elements.empty? or next t.children = @i18n.cjk_extend(t.text)
end
end
|
#cjk_search ⇒ Object
150
151
152
153
154
155
|
# File 'lib/isodoc/presentation_function/section.rb', line 150
def cjk_search
lang = %w(zh ja ko).map { |x| "@language = '#{x}'" }.join(" or ")
%(Hans Hant Jpan Hang Kore).include?(@script) and
lang += " or not(@language)"
lang
end
|
#clause(docxml) ⇒ Object
13
14
15
16
17
18
19
20
21
22
|
# File 'lib/isodoc/presentation_function/section.rb', line 13
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
24
25
26
27
28
29
30
31
32
33
|
# File 'lib/isodoc/presentation_function/section.rb', line 24
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
!elem.ancestors("boilerplate, metanorma-extension").empty? ||
@suppressheadingnumbers || elem["unnumbered"] and return
lbl = @xrefs.anchor(elem["id"], :label,
elem.parent.name != "sections") or return
prefix_name(elem, "<tab/>", "#{lbl}#{clausedelim}", "title")
end
|
#clausetitle(docxml) ⇒ Object
146
147
148
|
# File 'lib/isodoc/presentation_function/section.rb', line 146
def clausetitle(docxml)
cjk_extended_title(docxml)
end
|
#combine_conflated_xref_locations(locs) ⇒ Object
Note % to entry and Note % to entry: cannot conflate as Note % to entry 1 and 2 So Notes 1 and 3, but Note 1 to entry and Note 3 to entry
90
91
92
93
94
95
96
97
|
# File 'lib/isodoc/presentation_function/xrefs.rb', line 90
def combine_conflated_xref_locations(locs)
out = if locs.any? { |l| l[:elem]&.include?("%") }
locs.each { |l| l[:label] = @xrefs.anchor(l[:target], :xref) }
else
conflate_xref_locations(locs)
end
combine_conflated_xref_locations_container(locs, l10n(combine_conn(out)))
end
|
#combine_conflated_xref_locations_container(locs, ret) ⇒ Object
106
107
108
109
110
111
112
113
|
# File 'lib/isodoc/presentation_function/xrefs.rb', line 106
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
133
134
135
136
137
138
139
140
141
142
143
144
|
# File 'lib/isodoc/presentation_function/xrefs.rb', line 133
def combine_conn(list)
list.size == 1 and list.first[:label]
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
76
77
78
79
80
81
82
83
84
85
|
# File 'lib/isodoc/presentation_function/xrefs.rb', line 76
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/concepts.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/concepts.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
46
47
48
49
50
51
|
# File 'lib/isodoc/presentation_function/concepts.rb', line 46
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
53
54
55
56
57
58
59
60
|
# File 'lib/isodoc/presentation_function/concepts.rb', line 53
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
62
63
64
65
66
67
68
69
70
71
|
# File 'lib/isodoc/presentation_function/concepts.rb', line 62
def concept1_ref_content(ref)
prev = "["
foll = "]"
non_locality_elems(ref).select do |c|
!c.text? || /\S/.match(c)
end.empty? and
(prev, foll = @i18n.term_defined_in.split("%"))
ref.previous = prev
ref.next = foll
end
|
#concept1_style(node, opts) ⇒ Object
31
32
33
34
35
36
37
|
# File 'lib/isodoc/presentation_function/concepts.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/concepts.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
|
# File 'lib/isodoc/presentation_function/concepts.rb', line 39
def concept_render_init(node, defaults)
opts = %i(bold ital ref linkref linkmention)
.each_with_object({}) { |x, m| m[x] = node[x.to_s] || defaults[x] }
[opts, node.at(ns("./renderterm")),
node.at(ns("./xref | ./eref | ./termref"))]
end
|
#conditional_capitalize(text, seen_space) ⇒ Object
137
138
139
140
141
142
143
|
# File 'lib/isodoc/presentation_function/inline.rb', line 137
def conditional_capitalize(text, seen_space)
m = text.split(/(?<=\s)/)
((seen_space ? 0 : 1)...m.size).each do |i|
m[i] = m[i].capitalize
end
m.join
end
|
#conflate_xref_locations(locs) ⇒ Object
99
100
101
102
103
104
|
# File 'lib/isodoc/presentation_function/xrefs.rb', line 99
def conflate_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
out
end
|
#conversions(docxml) ⇒ Object
37
38
39
40
41
42
43
44
45
46
|
# File 'lib/isodoc/presentation_xml_convert.rb', line 37
def conversions(docxml)
semantic_xml_insert(docxml)
metadata docxml
bibdata docxml
@xrefs.parse docxml
section docxml
block docxml
terms docxml
inline docxml
end
|
#convert1(docxml, _filename, _dir) ⇒ Object
21
22
23
24
25
26
27
28
|
# File 'lib/isodoc/presentation_xml_convert.rb', line 21
def convert1(docxml, _filename, _dir)
docid_prefixes(docxml) @xrefs.parse docxml
info docxml, nil
conversions(docxml)
docxml.root["type"] = "presentation"
docxml.to_xml.gsub("<", "<").gsub(">", ">")
end
|
#custom_charset(docxml) ⇒ Object
145
146
147
148
149
150
151
|
# File 'lib/isodoc/presentation_function/inline.rb', line 145
def custom_charset(docxml)
charsets = (docxml)
docxml.xpath(ns("//span[@custom-charset]")).each do |s|
s["style"] ||= ""
s["style"] += ";font-family:#{charsets[s['custom-charset']]}"
end
end
|
#custom_css(docxml) ⇒ Object
11
12
13
14
15
16
17
18
|
# File 'lib/isodoc/presentation_function/sourcecode.rb', line 11
def custom_css(docxml)
ret = ""
@sourcehighlighter and ret += rouge_css_location
a = docxml.at(ns("//metanorma-extension/" \
"clause[title = 'user-css']/sourcecode")) and
ret += "\n#{to_xml(a.children)}"
ret
end
|
#date(docxml) ⇒ Object
92
93
94
95
96
97
|
# File 'lib/isodoc/presentation_function/inline.rb', line 92
def date(docxml)
(docxml.xpath(ns("//date")) -
docxml.xpath(ns("//bibdata/date | //bibitem//date"))).each do |d|
date1(d)
end
end
|
#date1(elem) ⇒ Object
99
100
101
102
|
# File 'lib/isodoc/presentation_function/inline.rb', line 99
def date1(elem)
elem["value"] && elem["format"] or return
elem.replace(@i18n.date(elem["value"], elem["format"].strip))
end
|
#date_note_process(bib) ⇒ Object
strip any fns in docidentifier before they are extracted for rendering
177
178
179
180
181
182
183
|
# File 'lib/isodoc/presentation_function/refs.rb', line 177
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
50
51
52
53
54
55
56
57
58
59
|
# File 'lib/isodoc/presentation_function/math.rb', line 50
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
|
#deprecates(elem) ⇒ Object
11
12
13
|
# File 'lib/isodoc/presentation_function/terms.rb', line 11
def deprecates(elem)
elem.children.first.previous = @i18n.l10n("#{@i18n.deprecated}: ")
end
|
#designation(docxml) ⇒ Object
3
4
5
6
7
8
9
|
# File 'lib/isodoc/presentation_function/terms.rb', line 3
def designation(docxml)
docxml.xpath(ns("//term")).each { |t| merge_second_preferred(t) }
docxml.xpath(ns("//preferred | //admitted | //deprecates"))
.each { |p| designation1(p) }
docxml.xpath(ns("//deprecates")).each { |d| deprecates(d) }
docxml.xpath(ns("//admitted")).each { |d| admits(d) }
end
|
#designation1(desgn) ⇒ Object
40
41
42
43
44
45
46
|
# File 'lib/isodoc/presentation_function/terms.rb', line 40
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
48
49
50
51
52
53
54
55
56
57
|
# File 'lib/isodoc/presentation_function/terms.rb', line 48
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)
designation_bookmarks(desgn, name)
desgn.children = name.children
end
|
#designation_boldface(desgn) ⇒ Object
59
60
61
62
63
|
# File 'lib/isodoc/presentation_function/terms.rb', line 59
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_bookmarks(desgn, name) ⇒ Object
98
99
100
101
102
|
# File 'lib/isodoc/presentation_function/terms.rb', line 98
def designation_bookmarks(desgn, name)
desgn.xpath(ns(".//bookmark")).each do |b|
name << b.remove
end
end
|
#designation_field(desgn, name) ⇒ Object
65
66
67
68
69
70
|
# File 'lib/isodoc/presentation_function/terms.rb', line 65
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
72
73
74
75
76
77
78
79
80
81
82
83
|
# File 'lib/isodoc/presentation_function/terms.rb', line 72
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
85
86
87
88
89
90
91
|
# File 'lib/isodoc/presentation_function/terms.rb', line 85
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
93
94
95
96
|
# File 'lib/isodoc/presentation_function/terms.rb', line 93
def designation_pronunciation(desgn, name)
f = desgn.at(ns("./expression/pronunciation")) or return
name << ", /#{to_xml(f.children)}/"
end
|
#display_order(docxml) ⇒ Object
133
134
135
136
137
138
139
140
141
142
143
144
|
# File 'lib/isodoc/presentation_function/section.rb', line 133
def display_order(docxml)
i = 0
d = @xrefs.clause_order(docxml)
%i(preface main annex back).each do |s|
d[s].each do |a|
i = if a[:multi]
display_order_xpath(docxml, a[:path], i)
else display_order_at(docxml, a[:path], i)
end
end
end
end
|
#display_order_at(docxml, xpath, idx) ⇒ Object
103
104
105
106
107
108
109
|
# File 'lib/isodoc/presentation_function/section.rb', line 103
def display_order_at(docxml, xpath, idx)
c = docxml.at(ns(xpath)) or return idx
idx += 1
idx = preceding_floating_titles(c, idx)
c["displayorder"] = idx
idx
end
|
#display_order_xpath(docxml, xpath, idx) ⇒ Object
111
112
113
114
115
116
117
118
|
# File 'lib/isodoc/presentation_function/section.rb', line 111
def display_order_xpath(docxml, xpath, idx)
docxml.xpath(ns(xpath)).each do |c|
idx += 1
idx = preceding_floating_titles(c, idx)
c["displayorder"] = idx
end
idx
end
|
#docid_prefixes(docxml) ⇒ Object
112
113
114
115
116
|
# File 'lib/isodoc/presentation_function/refs.rb', line 112
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
57
58
59
60
61
62
63
|
# File 'lib/isodoc/presentation_function/bibdata.rb', line 57
def edition_translate(bibdata)
x = bibdata.at(ns("./edition")) or return
/^\d+$/.match?(x.text) or return
@i18n.edition_ordinal or return
tag_translate(x, @lang, @i18n
.populate("edition_ordinal", { "var1" => x.text.to_i }))
end
|
#embedable_semantic_xml(xml) ⇒ Object
128
129
130
131
|
# File 'lib/isodoc/presentation_xml_convert.rb', line 128
def embedable_semantic_xml(xml)
xml = embedable_semantic_xml_tags(xml)
embedable_semantic_xml_attributes(xml)
end
|
#embedable_semantic_xml_attributes(xml) ⇒ Object
146
147
148
149
150
151
152
153
154
155
|
# File 'lib/isodoc/presentation_xml_convert.rb', line 146
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
|
133
134
135
136
137
138
139
140
141
142
143
144
|
# File 'lib/isodoc/presentation_xml_convert.rb', line 133
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
85
86
87
88
89
90
|
# File 'lib/isodoc/presentation_function/image.rb', line 85
def emf_encode(img)
svg_prep(img)
img.children = "<emf src='#{img['src']}'/>"
img["src"] = ""
img
end
|
#emf_to_svg(img) ⇒ Object
98
99
100
101
102
103
104
|
# File 'lib/isodoc/presentation_function/image.rb', line 98
def emf_to_svg(img)
datauri_src = img.at(ns("./emf/@src")).text
Vectory::Emf.from_datauri(datauri_src)
.to_svg
.content
.sub(/<\?[^>]+>/, "")
end
|
#eps2svg(img) ⇒ Object
64
65
66
67
68
69
70
71
72
|
# File 'lib/isodoc/presentation_function/image.rb', line 64
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
106
107
108
109
110
111
112
113
114
115
|
# File 'lib/isodoc/presentation_function/image.rb', line 106
def eps_to_svg(node)
if !node.text.strip.empty? || %r{^data:}.match?(node["src"])
return eps_to_svg_from_node(node)
end
target_path = imgfile_suffix(node["src"], "svg")
return target_path if File.exist?(target_path)
eps_to_svg_from_node(node, target_path)
end
|
#eps_to_svg_from_node(node, target_path = nil) ⇒ Object
117
118
119
120
121
122
|
# File 'lib/isodoc/presentation_function/image.rb', line 117
def eps_to_svg_from_node(node, target_path = nil)
svg = Vectory::Eps.from_node(node).to_svg
return svg.write(target_path).path if target_path
svg.write.path
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
|
#eref2link(docxml) ⇒ Object
186
187
188
189
190
191
192
193
194
195
|
# File 'lib/isodoc/presentation_function/erefs.rb', line 186
def eref2link(docxml)
docxml.xpath(ns("//eref | //origin[not(termref)] | //quote/source"))
.each do |e|
href = eref_target(e) or next
e.xpath(ns("./locality | ./localityStack")).each(&:remove)
if /^#/.match?(href) then eref2xref(e)
else eref2link1(e, href)
end
end
end
|
#eref2link1(node, href) ⇒ Object
205
206
207
208
209
|
# File 'lib/isodoc/presentation_function/erefs.rb', line 205
def eref2link1(node, href)
repl = "<link target='#{href}'>#{node.children}</link>"
node["type"] == "footnote" and repl = "<sup>#{repl}</sup>"
node.replace(repl)
end
|
#eref2xref(node) ⇒ Object
197
198
199
200
201
202
203
|
# File 'lib/isodoc/presentation_function/erefs.rb', line 197
def eref2xref(node)
node.name = "xref"
node["target"] = node["bibitemid"]
node.delete("bibitemid")
node.delete("citeas")
node["type"] == "footnote" and node.wrap("<sup></sup>")
end
|
#eref_localities(refs, target, node) ⇒ Object
25
26
27
28
29
30
31
32
33
|
# File 'lib/isodoc/presentation_function/erefs.rb', line 25
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
143
144
145
146
147
148
149
150
151
|
# File 'lib/isodoc/presentation_function/erefs.rb', line 143
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”)
163
164
165
166
167
168
169
170
171
172
|
# File 'lib/isodoc/presentation_function/erefs.rb', line 163
def eref_localities1(opt)
opt[:type] == "anchor" and return nil
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)
154
155
156
157
158
159
160
|
# File 'lib/isodoc/presentation_function/erefs.rb', line 154
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
35
36
37
38
39
40
41
42
43
44
|
# File 'lib/isodoc/presentation_function/erefs.rb', line 35
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
112
113
114
115
116
117
|
# File 'lib/isodoc/presentation_function/erefs.rb', line 112
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
174
175
176
177
178
179
180
181
182
183
184
|
# File 'lib/isodoc/presentation_function/erefs.rb', line 174
def eref_locality_populate(type, node, number)
node["droploc"] == "true" and return ""
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
119
120
121
122
123
124
125
126
127
128
|
# File 'lib/isodoc/presentation_function/erefs.rb', line 119
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
130
131
132
133
134
135
136
137
|
# File 'lib/isodoc/presentation_function/erefs.rb', line 130
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
101
102
103
104
105
106
107
108
109
110
|
# File 'lib/isodoc/presentation_function/erefs.rb', line 101
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 }
i == refs.size - 1 and next
m << eref_locality_delimiter(r)
end
ret.empty? ? ret : [", "] + ret
end
|
#eref_target(node) ⇒ Object
217
218
219
220
221
222
223
|
# File 'lib/isodoc/presentation_function/erefs.rb', line 217
def eref_target(node)
url = suffix_url(eref_url(node["bibitemid"]))
anchor = node.at(ns(".//locality[@type = 'anchor']"))
return url if url.nil? || /^#/.match?(url) || !anchor
"#{url}##{anchor.text.strip}"
end
|
#eref_url(id) ⇒ Object
225
226
227
228
229
230
231
232
|
# File 'lib/isodoc/presentation_function/erefs.rb', line 225
def eref_url(id)
@bibitem_lookup.nil? and return nil
b = @bibitem_lookup[id] or return nil
url = b.at(ns("./uri[@type = 'citation'][@language = '#{@lang}']")) ||
b.at(ns("./uri[@type = 'citation']")) and return url.text
b["hidden"] == "true" and return b.at(ns("./uri"))&.text
"##{id}"
end
|
#erefstack1(elem) ⇒ Object
17
18
19
20
21
22
23
|
# File 'lib/isodoc/presentation_function/erefs.rb', line 17
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
45
46
47
|
# File 'lib/isodoc/presentation_function/block.rb', line 45
def example(docxml)
docxml.xpath(ns("//example")).each { |f| example1(f) }
end
|
#example1(elem) ⇒ Object
49
50
51
52
53
54
55
56
|
# File 'lib/isodoc/presentation_function/block.rb', line 49
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
12
13
14
15
|
# File 'lib/isodoc/presentation_function/erefs.rb', line 12
def expand_citeas(text)
text.nil? and return text
HTMLEntities.new.decode(text.gsub("&#x", "&#"))
end
|
#extension_insert(xml, path = []) ⇒ Object
13
14
15
16
17
18
19
|
# File 'lib/isodoc/presentation_function/metadata.rb', line 13
def extension_insert(xml, path = [])
ins = extension_insert_pt(xml)
path.each do |n|
ins = ins.at(ns("./#{n}")) || ins.add_child("<#{n}/>").first
end
ins
end
|
#extension_insert_pt(xml) ⇒ Object
21
22
23
24
25
26
27
|
# File 'lib/isodoc/presentation_function/metadata.rb', line 21
def 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
|
168
169
170
171
172
173
174
175
176
|
# File 'lib/isodoc/presentation_function/inline.rb', line 168
def (docxml)
docxml.xpath(ns("//presentation-metadata/custom-charset-font"))
.each_with_object({}) do |line, m|
line.text.split(",").map(&:strip).each do |x|
kv = x.split(":", 2)
m[kv[0]] = kv[1]
end
end
end
|
7
8
9
10
11
12
13
|
# File 'lib/isodoc/presentation_function/image.rb', line 7
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
|
48
49
50
51
52
53
54
55
56
|
# File 'lib/isodoc/presentation_function/image.rb', line 48
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
|
58
59
60
61
62
|
# File 'lib/isodoc/presentation_function/image.rb', line 58
def figure_label(elem)
klass = elem["class"] || "figure"
klasslbl = @i18n.get[klass] || klass
lower2cap klasslbl
end
|
169
170
171
|
# File 'lib/isodoc/presentation_function/block.rb', line 169
def figuresource(elem)
source1(elem)
end
|
#floattitle(docxml) ⇒ Object
35
36
37
38
39
40
41
42
43
44
45
|
# File 'lib/isodoc/presentation_function/section.rb', line 35
def floattitle(docxml)
p = "//clause | //annex | //appendix | //introduction | //foreword | " \
"//preface/abstract | //acknowledgements | //terms | " \
"//definitions | //references | //colophon | //indexsect"
docxml.xpath(ns(p)).each do |f|
floattitle1(f)
end
docxml.xpath(ns("//sections | //preface | //colophon"))
.each { |f| floattitle1(f) }
end
|
#floattitle1(elem) ⇒ Object
47
48
49
50
51
52
|
# File 'lib/isodoc/presentation_function/section.rb', line 47
def floattitle1(elem)
elem.xpath(ns(".//floating-title")).each do |p|
p.name = "p"
p["type"] = "floating-title"
end
end
|
41
42
43
44
45
46
47
48
49
|
# File 'lib/isodoc/presentation_function/metadata.rb', line 41
def fonts_metadata(xmldoc)
ins = presmeta_insert_pt(xmldoc)
@fontist_fonts and CSV.parse_line(@fontist_fonts, col_sep: ";")
.map(&:strip).reverse.each do |f|
ins.next = presmeta("fonts", f)
end
@fontlicenseagreement and
ins.next = presmeta("font-license-agreement", @fontlicenseagreement)
end
|
28
29
30
|
# File 'lib/isodoc/presentation_function/block.rb', line 28
def formula(docxml)
docxml.xpath(ns("//formula")).each { |f| formula1(f) }
end
|
32
33
34
35
36
|
# File 'lib/isodoc/presentation_function/block.rb', line 32
def formula1(elem)
formula_where(elem.at(ns("./dl")))
lbl = @xrefs.anchor(elem["id"], :label, false)
prefix_name(elem, "", lbl, "name")
end
|
38
39
40
41
42
43
|
# File 'lib/isodoc/presentation_function/block.rb', line 38
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
115
116
117
118
119
120
121
122
123
|
# File 'lib/isodoc/presentation_function/xrefs.rb', line 115
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(l["target"], :container, false) ||
%w(termnote).include?(type) }
end
end
|
#get_linkend(node) ⇒ Object
12
13
14
15
16
17
18
19
20
21
22
23
|
# File 'lib/isodoc/presentation_function/inline.rb', line 12
def get_linkend(node)
node["style"] == "id" and anchor_id_postprocess(node)
xref_empty?(node) or return
target = docid_l10n(node["target"]) ||
expand_citeas(docid_l10n(node["citeas"]))
link = anchor_linkend(node, target)
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
48
49
50
51
52
53
|
# File 'lib/isodoc/presentation_function/bibdata.rb', line 48
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
25
26
27
28
29
30
31
|
# File 'lib/isodoc/presentation_function/refs.rb', line 25
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
146
147
148
149
|
# File 'lib/isodoc/presentation_function/xrefs.rb', line 146
def i18n_chain_boolean(value, entry)
@i18n.send("chain_#{entry[:conn]}").sub("%1", value)
.sub("%2", loc2xref(entry))
end
|
#i18n_safe(key) ⇒ Object
127
128
129
|
# File 'lib/isodoc/presentation_function/metadata.rb', line 127
def i18n_safe(key)
key.to_s.gsub(/\s|\./, "_")
end
|
#i18n_tag(key, value) ⇒ Object
122
123
124
125
|
# File 'lib/isodoc/presentation_function/metadata.rb', line 122
def i18n_tag(key, value)
"<localized-string key='#{key}' language='#{@lang}'>#{value}" \
"</localized-string>"
end
|
#i8n_name(hash, pref) ⇒ Object
131
132
133
134
135
136
137
138
139
140
141
|
# File 'lib/isodoc/presentation_function/metadata.rb', line 131
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
143
144
145
146
147
148
149
150
151
152
153
154
155
|
# File 'lib/isodoc/presentation_function/metadata.rb', line 143
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
185
186
187
188
|
# File 'lib/isodoc/presentation_function/refs.rb', line 185
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
28
29
30
31
32
33
|
# File 'lib/isodoc/presentation_function/image.rb', line 28
def imageconvert(docxml)
docxml.xpath(ns("//image")).each do |f|
eps2svg(f)
svg_emf_double(f)
end
end
|
#imgfile_suffix(uri, suffix) ⇒ Object
154
155
156
|
# File 'lib/isodoc/presentation_function/image.rb', line 154
def imgfile_suffix(uri, suffix)
"#{File.join(File.dirname(uri), File.basename(uri, '.*'))}.#{suffix}"
end
|
#index(docxml) ⇒ Object
99
100
101
|
# File 'lib/isodoc/presentation_function/section.rb', line 99
def index(docxml)
docxml.xpath(ns("//index | //index-xref | //indexsect")).each(&:remove)
end
|
#inline(docxml) ⇒ Object
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
# File 'lib/isodoc/presentation_xml_convert.rb', line 84
def inline(docxml)
bibitem_lookup(docxml) citeas docxml xref docxml
eref docxml origin docxml quotesource docxml eref2link docxml
mathml docxml
ruby docxml
variant docxml
identifier docxml
date docxml
passthrough docxml
inline_format docxml
end
|
104
105
106
107
|
# File 'lib/isodoc/presentation_function/inline.rb', line 104
def inline_format(docxml)
custom_charset(docxml)
text_transform(docxml)
end
|
#insert_biblio_tag(bib, ordinal, biblio, standard) ⇒ Object
136
137
138
139
140
141
142
143
144
145
146
|
# File 'lib/isodoc/presentation_function/refs.rb', line 136
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
125
126
127
128
129
130
131
|
# File 'lib/isodoc/presentation_function/xrefs.rb', line 125
def loc2xref(entry)
if entry[:target]
"<xref nested='true' target='#{entry[:target]}'>#{entry[:label]}</xref>"
else
entry[:label]
end
end
|
#locality_delimiter(_loc) ⇒ Object
139
140
141
|
# File 'lib/isodoc/presentation_function/erefs.rb', line 139
def locality_delimiter(_loc)
", "
end
|
#localize_maths(node, locale) ⇒ Object
symbols is merged into TwitterCldr::DataReaders::NumberDataReader.new(locale).symbols
19
20
21
22
23
24
25
26
|
# File 'lib/isodoc/presentation_function/math.rb', line 19
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
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
30
31
32
33
34
35
36
37
38
39
40
|
# File 'lib/isodoc/presentation_function/math.rb', line 30
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
42
43
44
45
46
47
48
|
# File 'lib/isodoc/presentation_function/math.rb', line 42
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
|
# File 'lib/isodoc/presentation_function/block.rb', line 7
def lower2cap(text)
/^[[:upper:]][[:upper:]]/.match?(text) and return text
text.capitalize
end
|
#mathml(docxml) ⇒ Object
9
10
11
12
13
14
15
|
# File 'lib/isodoc/presentation_function/math.rb', line 9
def mathml(docxml)
docxml.xpath("//m:math", MATHML).each { |f| mathml_linebreak(f) }
locale =
docxml.xpath("//m:math", MATHML).each do |f| mathml1(f, locale)
end
end
|
#mathml1(node, locale) ⇒ Object
111
112
113
114
|
# File 'lib/isodoc/presentation_function/math.rb', line 111
def mathml1(node, locale)
mathml_style_inherit(node)
mathml_number(node, locale)
end
|
#mathml_linebreak(node) ⇒ Object
116
117
118
119
120
121
122
123
124
125
126
127
|
# File 'lib/isodoc/presentation_function/math.rb', line 116
def mathml_linebreak(node)
node.at(".//*/@linebreak") or return
m = Plurimath::Math.parse(node.to_xml, :mathml)
.to_mathml(split_on_linebreak: true)
ret = Nokogiri::XML("<m>#{m}</m>").root
ret.elements.each_with_index do |e, i|
i.zero? or e.previous = "<br/>"
end
node.replace(<<~OUTPUT)
<math-with-linebreak>#{ret.children}</math-with-linebreak><math-no-linebreak>#{node.to_xml}</math-no-linebreak>
OUTPUT
end
|
#mathml_number(node, locale) ⇒ Object
129
130
131
132
133
134
|
# File 'lib/isodoc/presentation_function/math.rb', line 129
def mathml_number(node, locale)
justnumeral = numeric_mathml?(node)
justnumeral or asciimath_dup(node)
localize_maths(node, locale)
justnumeral and maths_just_numeral(node)
end
|
#mathml_number_to_number(node) ⇒ Object
152
153
154
155
156
157
158
159
160
|
# File 'lib/isodoc/presentation_function/math.rb', line 152
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
146
147
148
149
150
|
# File 'lib/isodoc/presentation_function/math.rb', line 146
def mathml_style_inherit(node)
node.at("./ancestor::xmlns:strong") or return
node.children =
"<mstyle mathvariant='bold'>#{node.children.to_xml}</mstyle>"
end
|
#maths_just_numeral(node) ⇒ Object
102
103
104
105
106
107
108
109
|
# File 'lib/isodoc/presentation_function/math.rb', line 102
def maths_just_numeral(node)
mn = node.at(".//m:mn", MATHML).children
if node.parent.name == "stem"
node.parent.replace(mn)
else
node.replace(mn)
end
end
|
#merge_preferred_eligible?(first, second) ⇒ Boolean
31
32
33
34
35
36
37
38
|
# File 'lib/isodoc/presentation_function/terms.rb', line 31
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
17
18
19
20
21
22
|
# File 'lib/isodoc/presentation_function/terms.rb', line 17
def merge_second_preferred(term)
pref = nil
term.xpath(ns("./preferred[expression/name]")).each_with_index do |p, i|
(i.zero? and pref = p) or merge_second_preferred1(pref, p)
end
end
|
#merge_second_preferred1(pref, second) ⇒ Object
24
25
26
27
28
29
|
# File 'lib/isodoc/presentation_function/terms.rb', line 24
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
|
3
4
5
6
7
8
9
10
11
|
# File 'lib/isodoc/presentation_function/metadata.rb', line 3
def metadata(docxml)
toc_metadata(docxml)
fonts_metadata(docxml)
preprocess_xslt_insert(docxml)
a = docxml.at(ns("//bibdata")) or return
a.next =
"<localized-strings>#{i8n_name(trim_hash(@i18n.get), '').join}" \
"</localized-strings>"
end
|
120
121
122
123
124
125
126
|
# File 'lib/isodoc/presentation_xml_convert.rb', line 120
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
|
#middle_title(docxml) ⇒ Object
5
6
7
8
9
10
11
|
# File 'lib/isodoc/presentation_function/section.rb', line 5
def middle_title(docxml)
s = docxml.at(ns("//sections")) or return
t = @meta.get[:doctitle]
t.nil? || t.empty? and return
s.children.first.previous =
"<p class='zzSTDTitle1'>#{t}</p>"
end
|
#move_norm_ref_to_sections(docxml) ⇒ Object
14
15
16
17
18
19
20
21
22
23
|
# File 'lib/isodoc/presentation_function/refs.rb', line 14
def move_norm_ref_to_sections(docxml)
docxml.at(ns(@xrefs.klass.norm_ref_xpath)) or return
s = docxml.at(ns("//sections")) ||
docxml.at(ns("//preface"))&.after("<sections/>")&.next_element ||
docxml.at(ns("//annex | //bibliography"))&.before("<sections/>")
&.previous_element or return
docxml.xpath(ns(@xrefs.klass.norm_ref_xpath)).each do |r|
s << r.remove
end
end
|
#multidef(elem) ⇒ Object
128
129
130
131
132
133
134
135
136
|
# File 'lib/isodoc/presentation_function/terms.rb', line 128
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
6
7
8
9
10
|
# File 'lib/isodoc/presentation_function/inline.rb', line 6
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
148
149
150
151
152
153
154
155
156
|
# File 'lib/isodoc/presentation_function/refs.rb', line 148
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
58
59
60
|
# File 'lib/isodoc/presentation_function/block.rb', line 58
def note(docxml)
docxml.xpath(ns("//note")).each { |f| note1(f) }
end
|
#note1(elem) ⇒ Object
62
63
64
65
66
67
68
69
70
|
# File 'lib/isodoc/presentation_function/block.rb', line 62
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
|
#numeric_mathml?(node) ⇒ Boolean
136
137
138
139
140
141
142
143
144
|
# File 'lib/isodoc/presentation_function/math.rb', line 136
def numeric_mathml?(node)
m = {}
node.traverse do |x|
%w(mstyle mrow math text).include?(x.name) and next
m[x.name] ||= 0
m[x.name] += 1
end
m.keys.size == 1 && m["mn"] == 1
end
|
#ol(docxml) ⇒ Object
127
128
129
130
131
|
# File 'lib/isodoc/presentation_function/block.rb', line 127
def ol(docxml)
docxml.xpath(ns("//ol")).each { |f| ol1(f) }
@xrefs.list_anchor_names(docxml.xpath(ns(@xrefs.sections_xpath)))
docxml.xpath(ns("//ol/li")).each { |f| ol_label(f) }
end
|
#ol1(elem) ⇒ Object
146
147
148
149
150
151
|
# File 'lib/isodoc/presentation_function/block.rb', line 146
def ol1(elem)
elem["type"] ||= ol_depth(elem).to_s
elem.xpath(ns("./li")).each do |li|
li["id"] ||= "_#{UUIDTools::UUID.random_create}"
end
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)
136
137
138
139
140
141
142
143
144
|
# File 'lib/isodoc/presentation_function/block.rb', line 136
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
|
#ol_label(elem) ⇒ Object
153
154
155
|
# File 'lib/isodoc/presentation_function/block.rb', line 153
def ol_label(elem)
elem["label"] = @xrefs.anchor(elem["id"], :label, false)
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
80
81
82
83
84
85
86
87
88
89
90
|
# File 'lib/isodoc/presentation_function/math.rb', line 80
def parse_localize_number
@localizenumber or return {}
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
|
#passthrough(docxml) ⇒ Object
153
154
155
156
157
158
|
# File 'lib/isodoc/presentation_function/inline.rb', line 153
def passthrough(docxml)
formats = @output_formats.keys
docxml.xpath(ns("//passthrough")).each do |p|
passthrough1(p, formats)
end
end
|
#passthrough1(elem, formats) ⇒ Object
160
161
162
163
164
165
166
|
# File 'lib/isodoc/presentation_function/inline.rb', line 160
def passthrough1(elem, formats)
(elem["formats"] && !elem["formats"].empty?) or elem["formats"] = "all"
f = elem["formats"].split(",")
(f - formats).size == f.size or elem["formats"] = "all"
elem["formats"] == "all" and elem["formats"] = formats.join(",")
elem["formats"] = ",#{elem['formats']},"
end
|
#passthrough_xslt ⇒ Object
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
|
# File 'lib/isodoc/presentation_function/metadata.rb', line 85
def passthrough_xslt
@output_formats.nil? and return nil
@output_formats.empty? and return nil
@output_formats.each_key.with_object([]) do |k, m|
m << <<~XSLT
<preprocess-xslt format="#{k}">
#{xslt_template(<<~XSLT1)
<xsl:template match="*[local-name() = 'passthrough']">
<xsl:if test="contains(@formats,',#{k},')"> <!-- delimited -->
#{COPY_XSLT}
</xsl:if>
</xsl:template>
XSLT1
}
</preprocess-xslt>
XSLT
m << <<~XSLT
<preprocess-xslt format="#{k}">
#{xslt_template(<<~XSLT1)
<xsl:template match="*[local-name() = 'math-with-linebreak']">
#{k == 'pdf' ? COPY_CHILDREN_XSLT : ''}
</xsl:template>
<xsl:template match="*[local-name() = 'math-no-linebreak']">
#{k == 'pdf' ? '' : COPY_CHILDREN_XSLT}
</xsl:template>
XSLT1
}
</preprocess-xslt>
XSLT
end.join("\n")
end
|
#permission(docxml) ⇒ Object
15
16
17
18
19
|
# File 'lib/isodoc/presentation_function/reqt.rb', line 15
def permission(docxml)
docxml.xpath(ns("//permission")).each do |f|
recommendation1(f, lower2cap(@i18n.permission))
end
end
|
#postprocess(result, filename, _dir) ⇒ Object
157
158
159
160
|
# File 'lib/isodoc/presentation_xml_convert.rb', line 157
def postprocess(result, filename, _dir)
to_xml_file(result, filename)
@files_to_delete.each { |f| FileUtils.rm_rf f }
end
|
#preceding_floating_titles(node, idx) ⇒ Object
120
121
122
123
124
125
126
127
128
129
130
131
|
# File 'lib/isodoc/presentation_function/section.rb', line 120
def preceding_floating_titles(node, idx)
out = node.xpath("./preceding-sibling::*")
.reverse.each_with_object([]) do |p, m|
%w(note admonition p).include?(p.name) or break m
m << p
end
out.reject { |c| c["displayorder"] }.reverse.each do |c|
c["displayorder"] = idx
idx += 1
end
idx
end
|
#preceding_floats(clause) ⇒ Object
202
203
204
205
206
207
208
209
210
211
212
213
|
# File 'lib/isodoc/presentation_function/section.rb', line 202
def preceding_floats(clause)
ret = []
p = clause
while prev = p.previous_element
if prev.name == "floating-title"
ret << prev
p = prev
else break
end
end
ret
end
|
#preface_move(clause, after, _doc) ⇒ Object
178
179
180
181
182
183
184
185
186
|
# File 'lib/isodoc/presentation_function/section.rb', line 178
def preface_move(clause, after, _doc)
clause or return
preface = clause.parent
float = preceding_floats(clause)
prev = nil
xpath = after.map { |n| "./self::xmlns:#{n}" }.join(" | ")
xpath.empty? and xpath = "./self::*[not(following-sibling::*)]"
preface_move1(clause, preface, float, prev, xpath)
end
|
#preface_move1(clause, preface, float, prev, xpath) ⇒ Object
188
189
190
191
192
193
194
195
196
197
198
199
200
|
# File 'lib/isodoc/presentation_function/section.rb', line 188
def preface_move1(clause, preface, float, prev, xpath)
preface.elements.each do |x|
((x.name == "floating-title" || x.at(xpath)) &&
xpath != "./self::*[not(following-sibling::*)]") or prev = x
x.at(xpath) or next
clause == prev and break
prev ||= preface.children.first
float << clause
float.each { |n| prev.next = n }
break
end
end
|
#preface_rearrange(doc) ⇒ Object
167
168
169
170
171
172
173
174
175
176
|
# File 'lib/isodoc/presentation_function/section.rb', line 167
def preface_rearrange(doc)
preface_move(doc.at(ns("//preface/abstract")),
%w(foreword introduction clause acknowledgements), doc)
preface_move(doc.at(ns("//preface/foreword")),
%w(introduction clause acknowledgements), doc)
preface_move(doc.at(ns("//preface/introduction")),
%w(clause acknowledgements), doc)
preface_move(doc.at(ns("//preface/acknowledgements")),
%w(), doc)
end
|
#prefix_bracketed_ref(text) ⇒ Object
172
173
174
|
# File 'lib/isodoc/presentation_function/refs.rb', line 172
def prefix_bracketed_ref(text)
"#{text}<tab/>"
end
|
#prefix_container(container, linkend, node, target) ⇒ Object
3
4
5
6
7
8
9
10
11
12
|
# File 'lib/isodoc/presentation_function/xrefs.rb', line 3
def prefix_container(container, linkend, node, target)
prefix_container?(container, node) or return linkend
container_container = @xrefs.anchor(container, :container, false)
container_label =
prefix_container(container_container,
anchor_xref(node, container, container: true),
node, target)
l10n(@i18n.nested_xref.sub("%1", container_label)
.sub("%2", linkend))
end
|
#prefix_container?(container, node) ⇒ Boolean
68
69
70
71
72
73
74
|
# File 'lib/isodoc/presentation_function/xrefs.rb', line 68
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
16
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/isodoc/presentation_function/block.rb', line 16
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
44
45
46
47
48
|
# File 'lib/isodoc/presentation_function/refs.rb', line 44
def prep_for_rendering(bib)
bib["suppress_identifier"] == true and
bib.xpath(ns("./docidentifier")).each(&:remove)
bib["type"] ||= "standard"
end
|
#preprocess_xslt_insert(docxml) ⇒ Object
61
62
63
64
65
66
67
68
|
# File 'lib/isodoc/presentation_function/metadata.rb', line 61
def preprocess_xslt_insert(docxml)
content = ""
p = passthrough_xslt and content += p
p = preprocess_xslt_read and content += File.read(p)
content.empty? and return
ins = extension_insert(docxml, %w(render))
ins << content
end
|
#preprocess_xslt_read ⇒ Object
read in from file, but with ‘<preprocess-xslt @format=“”>` wrapper
118
119
120
|
# File 'lib/isodoc/presentation_function/metadata.rb', line 118
def preprocess_xslt_read
html_doc_path("preprocess.xslt")
end
|
56
57
58
59
|
# File 'lib/isodoc/presentation_function/metadata.rb', line 56
def presmeta(name, value)
"<presentation-metadata><name>#{name}</name><value>#{value}</value>" \
"</presentation-metadata>"
end
|
51
52
53
54
|
# File 'lib/isodoc/presentation_function/metadata.rb', line 51
def presmeta_insert_pt(xmldoc)
xmldoc.at(ns("//presentation-metadata")) ||
xmldoc.at(ns("//metanorma-extension")) || xmldoc.at(ns("//bibdata"))
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
|
#rearrange_clauses(docxml) ⇒ Object
215
216
217
218
|
# File 'lib/isodoc/presentation_function/section.rb', line 215
def rearrange_clauses(docxml)
preface_rearrange(docxml) toc_title(docxml)
end
|
#recommendation(docxml) ⇒ Object
3
4
5
6
7
|
# File 'lib/isodoc/presentation_function/reqt.rb', line 3
def recommendation(docxml)
docxml.xpath(ns("//recommendation")).each do |f|
recommendation1(f, lower2cap(@i18n.recommendation))
end
end
|
#recommendation1(elem, type) ⇒ Object
21
22
23
24
25
|
# File 'lib/isodoc/presentation_function/reqt.rb', line 21
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
12
|
# 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)
move_norm_ref_to_sections(docxml)
@xrefs.parse_inclusions(refs: true).parse(docxml)
end
|
#references_render(docxml) ⇒ Object
33
34
35
36
37
38
39
40
41
42
|
# File 'lib/isodoc/presentation_function/refs.rb', line 33
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
@bibrender.render_all("<references>#{refs}</references>",
type: citestyle)
end
|
#reinsert_callout(xml) ⇒ Object
129
130
131
|
# File 'lib/isodoc/presentation_function/sourcecode.rb', line 129
def reinsert_callout(xml)
"<span class='c'>#{to_xml(xml)}</span>"
end
|
73
74
75
|
# File 'lib/isodoc/presentation_function/concepts.rb', line 73
def related(docxml)
docxml.xpath(ns("//related")).each { |f| related1(f) }
end
|
77
78
79
80
81
82
83
84
85
86
87
88
|
# File 'lib/isodoc/presentation_function/concepts.rb', line 77
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
9
10
11
12
13
|
# File 'lib/isodoc/presentation_function/reqt.rb', line 9
def requirement(docxml)
docxml.xpath(ns("//requirement")).each do |f|
recommendation1(f, lower2cap(@i18n.requirement))
end
end
|
#requirement_render(docxml) ⇒ Object
31
32
33
34
35
36
37
38
39
40
|
# File 'lib/isodoc/presentation_function/reqt.rb', line 31
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
42
43
44
45
|
# File 'lib/isodoc/presentation_function/reqt.rb', line 42
def requirement_render1(node)
node.replace(@reqt_models.model(node["model"])
.requirement_render1(node))
end
|
#requirement_render_preprocessing(docxml) ⇒ Object
27
|
# File 'lib/isodoc/presentation_function/reqt.rb', line 27
def requirement_render_preprocessing(docxml); end
|
#resolve_comma_connectives(locs) ⇒ Object
67
68
69
70
71
72
73
74
75
|
# File 'lib/isodoc/presentation_function/erefs.rb', line 67
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
77
78
79
80
81
82
83
84
85
86
87
|
# File 'lib/isodoc/presentation_function/erefs.rb', line 77
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
56
57
58
59
60
61
62
63
64
65
|
# File 'lib/isodoc/presentation_function/erefs.rb', line 56
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
89
90
91
92
93
94
95
96
97
98
99
|
# File 'lib/isodoc/presentation_function/erefs.rb', line 89
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
|
#rouge_css_location ⇒ Object
replace in local gem rather than specify overrides of default
21
22
23
24
|
# File 'lib/isodoc/presentation_function/sourcecode.rb', line 21
def rouge_css_location
File.read(File.join(File.dirname(__FILE__), "..", "base_style",
"rouge.css"))
end
|
#ruby(docxml) ⇒ Object
178
179
180
181
182
183
|
# File 'lib/isodoc/presentation_function/inline.rb', line 178
def ruby(docxml)
(docxml.xpath(ns("//ruby")) - docxml.xpath(ns("//ruby//ruby")))
.each do |r|
ruby1(r)
end
end
|
#ruby1(elem) ⇒ Object
185
186
187
188
189
190
191
192
|
# File 'lib/isodoc/presentation_function/inline.rb', line 185
def ruby1(elem)
v = elem.at(ns("./pronunciation | ./annotation")).remove
elem.xpath(ns("./ruby")).each do |r|
ruby1(r)
end
t = elem.children.to_xml
elem.replace("<ruby><rb>#{t}</rb><rt>#{v['value']}</rt></ruby>")
end
|
#section(docxml) ⇒ Object
parse annex after term, references, to deal with single-term and single-ref annexes
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
# File 'lib/isodoc/presentation_xml_convert.rb', line 50
def section(docxml)
references docxml
rearrange_clauses docxml middle_title docxml
annex docxml
clause docxml term docxml
index docxml
clausetitle docxml floattitle docxml toc docxml
display_order docxml
end
|
#semantic_xml_insert(xml) ⇒ Object
111
112
113
114
115
116
117
118
|
# File 'lib/isodoc/presentation_xml_convert.rb', line 111
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
71
72
73
74
75
76
77
|
# File 'lib/isodoc/presentation_function/section.rb', line 71
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
79
80
81
82
83
84
85
86
|
# File 'lib/isodoc/presentation_function/section.rb', line 79
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(docxml) ⇒ Object
157
158
159
160
161
162
163
|
# File 'lib/isodoc/presentation_function/block.rb', line 157
def source(docxml)
docxml.xpath(ns("//source/modification")).each do |f|
source_modification(f)
end
docxml.xpath(ns("//table/source")).each { |f| tablesource(f) }
docxml.xpath(ns("//figure/source")).each { |f| figuresource(f) }
end
|
#source1(elem) ⇒ Object
173
174
175
176
177
178
|
# File 'lib/isodoc/presentation_function/block.rb', line 173
def source1(elem)
while elem&.next_element&.name == "source"
elem << "; #{to_xml(elem.next_element.remove.children)}"
end
elem.children = l10n("[#{@i18n.source}: #{to_xml(elem.children).strip}]")
end
|
#source_highlight(elem) ⇒ Object
70
71
72
73
74
75
76
77
78
79
80
81
|
# File 'lib/isodoc/presentation_function/sourcecode.rb', line 70
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
152
153
154
155
156
157
|
# File 'lib/isodoc/presentation_function/sourcecode.rb', line 152
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
143
144
145
146
147
148
149
150
|
# File 'lib/isodoc/presentation_function/sourcecode.rb', line 143
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_modification(mod) ⇒ Object
180
181
182
|
# File 'lib/isodoc/presentation_function/block.rb', line 180
def source_modification(mod)
termsource_modification(mod.parent)
end
|
#source_remove_annotations(ret, elem) ⇒ Object
90
91
92
93
94
95
96
|
# File 'lib/isodoc/presentation_function/sourcecode.rb', line 90
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, line: c.line - elem.line }
end
ret
end
|
#source_remove_markup(elem) ⇒ Object
83
84
85
86
87
88
|
# File 'lib/isodoc/presentation_function/sourcecode.rb', line 83
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
109
110
111
112
113
114
115
116
117
|
# File 'lib/isodoc/presentation_function/sourcecode.rb', line 109
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+$/, " #{reinsert_callout(callouts[0][:xml])} ")
callouts.shift
end
end.join("\n")
end
|
#source_restore_callouts_table(table, callouts) ⇒ Object
119
120
121
122
123
124
125
126
127
|
# File 'lib/isodoc/presentation_function/sourcecode.rb', line 119
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 << " #{reinsert_callout(callouts[0][:xml])} "
callouts.shift
end
end
end
|
#source_restore_markup(wrapper, markup) ⇒ Object
98
99
100
101
|
# File 'lib/isodoc/presentation_function/sourcecode.rb', line 98
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
103
104
105
106
107
|
# File 'lib/isodoc/presentation_function/sourcecode.rb', line 103
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
41
42
43
44
45
46
47
48
|
# File 'lib/isodoc/presentation_function/sourcecode.rb', line 41
def sourcecode(docxml)
sourcehighlighter_css(docxml)
@highlighter = sourcehighlighter
@callouts = {}
docxml.xpath(ns("//sourcecode")).each do |f|
sourcecode1(f)
end
end
|
#sourcecode1(elem) ⇒ Object
50
51
52
53
54
55
|
# File 'lib/isodoc/presentation_function/sourcecode.rb', line 50
def sourcecode1(elem)
source_highlight(elem)
source_label(elem)
callouts(elem)
annotations(elem)
end
|
#sourcecode_table_to_elem(elem, tokens) ⇒ Object
133
134
135
136
137
138
139
140
141
|
# File 'lib/isodoc/presentation_function/sourcecode.rb', line 133
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
26
27
28
29
30
31
32
33
|
# File 'lib/isodoc/presentation_function/sourcecode.rb', line 26
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
|
# File 'lib/isodoc/presentation_function/sourcecode.rb', line 3
def sourcehighlighter_css(docxml)
ret = custom_css(docxml)
ret.empty? and return
ins = extension_insert(docxml)
ins << "<source-highlighter-css>#{ret}" \
"</source-highlighter-css>"
end
|
#suffix_url(url) ⇒ Object
211
212
213
214
215
|
# File 'lib/isodoc/presentation_function/erefs.rb', line 211
def suffix_url(url)
url.nil? || %r{^https?://|^#}.match?(url) and return url
File.extname(url).empty? or return url
url.sub(/#{File.extname(url)}$/, ".html")
end
|
#svg_emf_double(img) ⇒ Object
74
75
76
77
78
79
80
81
82
83
|
# File 'lib/isodoc/presentation_function/image.rb', line 74
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) or return
img.add_child("<emf/>")
img.elements.last["src"] = src
end
end
|
35
36
37
38
39
40
41
42
43
44
45
46
|
# File 'lib/isodoc/presentation_function/image.rb', line 35
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_impose_height_attr(node) ⇒ Object
146
147
148
149
150
151
152
|
# File 'lib/isodoc/presentation_function/image.rb', line 146
def svg_impose_height_attr(node)
e = node.elements&.first or return
(e.name == "svg" &&
(!node["height"] || node["height"] == "auto")) or return
node["height"] = e["height"]
node["width"] = e["width"]
end
|
#svg_prep(img) ⇒ Object
92
93
94
95
96
|
# File 'lib/isodoc/presentation_function/image.rb', line 92
def svg_prep(img)
img["mimetype"] = "image/svg+xml"
%r{^data:}.match?(img["src"]) or
img["src"] = Vectory::Emf.from_path(img["src"]).to_uri.content
end
|
#svg_to_emf(node) ⇒ Object
124
125
126
127
128
129
130
131
132
133
134
135
136
137
|
# File 'lib/isodoc/presentation_function/image.rb', line 124
def svg_to_emf(node)
@output_formats[:doc] or return
svg_impose_height_attr(node)
if node.elements&.first&.name == "svg" || %r{^data:}.match?(node["src"])
return svg_to_emf_from_node(node)
end
target_path = imgfile_suffix(node["src"], "emf")
return target_path if File.exist?(target_path)
svg_to_emf_from_node(node, target_path)
end
|
#svg_to_emf_from_node(node, target_path = nil) ⇒ Object
139
140
141
142
143
144
|
# File 'lib/isodoc/presentation_function/image.rb', line 139
def svg_to_emf_from_node(node, target_path = nil)
emf = Vectory::Svg.from_node(node).to_emf
return emf.write(target_path).to_uri.content if target_path
emf.to_uri.content
end
|
#svg_wrap(elem) ⇒ Object
15
16
17
18
19
20
|
# File 'lib/isodoc/presentation_function/image.rb', line 15
def svg_wrap(elem)
return if elem.parent.name == "image"
elem.wrap("<image src='' mimetype='image/svg+xml' height='auto' " \
"width='auto'></image>")
end
|
22
23
24
25
26
|
# File 'lib/isodoc/presentation_function/image.rb', line 22
def (elem)
if f = elem.at(ns("./figure")) then elem.replace(f)
else elem.remove
end
end
|
#table(docxml) ⇒ Object
91
92
93
94
|
# File 'lib/isodoc/presentation_function/block.rb', line 91
def table(docxml)
table_long_strings_cleanup(docxml)
docxml.xpath(ns("//table")).each { |f| table1(f) }
end
|
#table1(elem) ⇒ Object
96
97
98
99
100
101
102
|
# File 'lib/isodoc/presentation_function/block.rb', line 96
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
|
#table_long_strings_cleanup(docxml) ⇒ Object
104
105
106
107
108
109
110
111
112
113
|
# File 'lib/isodoc/presentation_function/block.rb', line 104
def table_long_strings_cleanup(docxml)
@break_up_urls_in_tables or return
docxml.xpath(ns("//td | //th")).each do |d|
d.traverse do |n|
n.text? or next
ret = Metanorma::Utils::break_up_long_str(n.text)
n.content = ret
end
end
end
|
#tablesource(elem) ⇒ Object
165
166
167
|
# File 'lib/isodoc/presentation_function/block.rb', line 165
def tablesource(elem)
source1(elem)
end
|
#tag_translate(tag, lang, value) ⇒ Object
65
66
67
68
69
70
|
# File 'lib/isodoc/presentation_function/bibdata.rb', line 65
def tag_translate(tag, lang, value)
tag["language"] = ""
tag.next = tag.dup
tag.next["language"] = lang
tag.next.children = value
end
|
#term(docxml) ⇒ Object
88
89
90
91
92
|
# File 'lib/isodoc/presentation_function/section.rb', line 88
def term(docxml)
docxml.xpath(ns("//term")).each do |f|
term1(f)
end
end
|
#term1(elem) ⇒ Object
94
95
96
97
|
# File 'lib/isodoc/presentation_function/section.rb', line 94
def term1(elem)
lbl = @xrefs.anchor(elem["id"], :label) or return
prefix_name(elem, "", "#{lbl}#{clausedelim}", "name")
end
|
#termdefinition(docxml) ⇒ Object
117
118
119
120
121
|
# File 'lib/isodoc/presentation_function/terms.rb', line 117
def termdefinition(docxml)
docxml.xpath(ns("//term[definition]")).each do |f|
termdefinition1(f)
end
end
|
#termdefinition1(elem) ⇒ Object
123
124
125
126
|
# File 'lib/isodoc/presentation_function/terms.rb', line 123
def termdefinition1(elem)
unwrap_definition(elem)
multidef(elem) if elem.xpath(ns("./definition")).size > 1
end
|
#termexample(docxml) ⇒ Object
104
105
106
|
# File 'lib/isodoc/presentation_function/terms.rb', line 104
def termexample(docxml)
docxml.xpath(ns("//termexample")).each { |f| example1(f) }
end
|
#termnote(docxml) ⇒ Object
108
109
110
|
# File 'lib/isodoc/presentation_function/terms.rb', line 108
def termnote(docxml)
docxml.xpath(ns("//termnote")).each { |f| termnote1(f) }
end
|
#termnote1(elem) ⇒ Object
112
113
114
115
|
# File 'lib/isodoc/presentation_function/terms.rb', line 112
def termnote1(elem)
lbl = l10n(@xrefs.anchor(elem["id"], :label) || "???")
prefix_name(elem, "", lower2cap(lbl), "name")
end
|
#terms(docxml) ⇒ Object
101
102
103
104
105
106
107
108
109
|
# File 'lib/isodoc/presentation_xml_convert.rb', line 101
def terms(docxml)
termexample docxml
termnote docxml
termdefinition docxml
designation docxml
termsource docxml
concept docxml
related docxml
end
|
#termsource(docxml) ⇒ Object
147
148
149
150
|
# File 'lib/isodoc/presentation_function/terms.rb', line 147
def termsource(docxml)
docxml.xpath(ns("//termsource")).each { |f| termsource_modification(f) }
docxml.xpath(ns("//termsource")).each { |f| termsource1(f) }
end
|
#termsource1(elem) ⇒ Object
152
153
154
155
156
157
|
# File 'lib/isodoc/presentation_function/terms.rb', line 152
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_add_modification_text(mod) ⇒ Object
165
166
167
168
169
170
171
|
# File 'lib/isodoc/presentation_function/terms.rb', line 165
def termsource_add_modification_text(mod)
mod or return
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
|
#termsource_modification(elem) ⇒ Object
159
160
161
162
163
|
# File 'lib/isodoc/presentation_function/terms.rb', line 159
def termsource_modification(elem)
origin = elem.at(ns("./origin"))
s = termsource_status(elem["status"]) and origin.next = l10n(", #{s}")
termsource_add_modification_text(elem.at(ns("./modification")))
end
|
#termsource_status(status) ⇒ Object
173
174
175
176
177
178
|
# File 'lib/isodoc/presentation_function/terms.rb', line 173
def termsource_status(status)
case status
when "modified" then @i18n.modified
when "adapted" then @i18n.adapted
end
end
|
#text_transform(docxml) ⇒ Object
109
110
111
112
113
|
# File 'lib/isodoc/presentation_function/inline.rb', line 109
def text_transform(docxml)
docxml.xpath(ns("//span[contains(@style, 'text-transform')]")).each do |s|
text_transform1(s)
end
end
|
#text_transform1(span) ⇒ Object
115
116
117
118
119
120
121
122
|
# File 'lib/isodoc/presentation_function/inline.rb', line 115
def text_transform1(span)
m = span["style"].split(/;\s*/)
i = m.index { |x| /^text-transform/.match?(x) }
value = m[i].sub(/^text-transform:/, "")
change_case(span, value, true)
m[i] = "text-transform:none"
span["style"] = m.join(";")
end
|
#to_xml_file(result, filename) ⇒ Object
162
163
164
|
# File 'lib/isodoc/presentation_xml_convert.rb', line 162
def to_xml_file(result, filename)
File.open(filename, "w:UTF-8") { |f| f.write(result) }
end
|
#toc(docxml) ⇒ Object
238
239
240
|
# File 'lib/isodoc/presentation_function/section.rb', line 238
def toc(docxml)
toc_refs(docxml)
end
|
29
30
31
32
33
34
35
36
37
38
39
|
# File 'lib/isodoc/presentation_function/metadata.rb', line 29
def toc_metadata(docxml)
@tocfigures || @toctables || @tocrecommendations or return
ins = extension_insert(docxml)
@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
|
#toc_refs(docxml) ⇒ Object
242
243
244
245
246
247
|
# File 'lib/isodoc/presentation_function/section.rb', line 242
def toc_refs(docxml)
docxml.xpath(ns("//toc//xref[text()]")).each do |x|
lbl = @xrefs.anchor(x["target"], :label) or next
x.children.first.previous = "#{lbl}<tab/>"
end
end
|
#toc_title(docxml) ⇒ Object
220
221
222
223
224
225
226
227
|
# File 'lib/isodoc/presentation_function/section.rb', line 220
def toc_title(docxml)
docxml.at(ns("//preface/clause[@type = 'toc']")) and return
ins = toc_title_insert_pt(docxml) or return
id = UUIDTools::UUID.random_create.to_s
ins.previous = <<~CLAUSE
<clause type = 'toc' id='_#{id}'><title depth='1'>#{@i18n.table_of_contents}</title></clause>
CLAUSE
end
|
#toc_title_insert_pt(docxml) ⇒ Object
229
230
231
232
233
234
235
236
|
# File 'lib/isodoc/presentation_function/section.rb', line 229
def toc_title_insert_pt(docxml)
ins = docxml.at(ns("//preface")) ||
docxml.at(ns("//sections | //annex | //bibliography"))
&.before("<preface> </preface>")
&.previous_element or return nil
ins.children.empty? and ins << " "
ins.children.first
end
|
#trim_hash(hash) ⇒ Object
162
163
164
165
166
167
168
169
|
# File 'lib/isodoc/presentation_function/metadata.rb', line 162
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
171
172
173
174
175
176
177
178
179
180
181
182
|
# File 'lib/isodoc/presentation_function/metadata.rb', line 171
def trim_hash1(hash)
hash.is_a?(Hash) or return hash
hash.each_with_object({}) do |(k, v), g|
blank?(v) and next
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
|
74
75
76
77
78
|
# File 'lib/isodoc/presentation_function/math.rb', line 74
def
locale = TwitterCldr.supported_locale?(@lang.to_sym) ? @lang.to_sym : :en
(locale)
locale
end
|
61
62
63
|
# File 'lib/isodoc/presentation_function/math.rb', line 61
def
{}
end
|
65
66
67
68
69
70
71
72
|
# File 'lib/isodoc/presentation_function/math.rb', line 65
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>
27
28
29
30
31
32
|
# File 'lib/isodoc/presentation_function/inline.rb', line 27
def unnest_linkend(node)
node.at(ns("./xref[@nested]")) or return
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
138
139
140
141
142
143
144
145
|
# File 'lib/isodoc/presentation_function/terms.rb', line 138
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(xml) ⇒ Object
67
68
69
70
71
72
73
74
75
76
|
# File 'lib/isodoc/presentation_function/inline.rb', line 67
def variant(xml)
b = xml.xpath(ns("//bibdata//variant"))
(xml.xpath(ns("//variant")) - b).each { |f| variant1(f) }
(xml.xpath(ns("//variant[@remove = 'true']")) - b).each(&:remove)
(xml.xpath(ns("//variant")) - b).each do |v|
v.next&.name == "variant" or next
v.next = "/"
end
(xml.xpath(ns("//variant")) - b).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
|
#xslt_template(content) ⇒ Object
75
76
77
78
79
80
81
82
83
|
# File 'lib/isodoc/presentation_function/metadata.rb', line 75
def xslt_template(content)
<<~XSLT
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/1999/xhtml" version="1.0">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="no"/>
<xsl:template match="@* | node()">#{COPY_XSLT}</xsl:template>
#{content}
</xsl:stylesheet>
XSLT
end
|