Module: IsoDoc::Function::Cleanup
- Included in:
- Common
- Defined in:
- lib/isodoc/function/cleanup.rb
Instance Method Summary collapse
-
#admonition_cleanup(docxml) ⇒ Object
todo PRESENTATION XML.
- #cleanup(docxml) ⇒ Object
-
#empty_tags(html) ⇒ Object
Atomic group (?>…) prevents catastrophic backtracking across ‘>` characters.
- #example_cleanup(docxml) ⇒ Object
- #figure_cleanup(docxml) ⇒ Object
- #inline_header_cleanup(docxml) ⇒ Object
- #merge_fnref_into_fn_text(elem) ⇒ Object
- #passthrough_cleanup(docxml) ⇒ Object
- #symbols_cleanup(docxml) ⇒ Object
- #table_cleanup(docxml) ⇒ Object
-
#table_footnote_cleanup(docxml) ⇒ Object
preempt html2doc putting MsoNormal under TableFootnote class.
- #table_footnote_cleanup_propagate(docxml) ⇒ Object
- #textcleanup(docxml) ⇒ Object
Instance Method Details
#admonition_cleanup(docxml) ⇒ Object
todo PRESENTATION XML
28 29 30 31 32 33 34 35 36 |
# File 'lib/isodoc/function/cleanup.rb', line 28 def admonition_cleanup(docxml) docxml.xpath("//div[@class = 'Admonition'][title]").each do |d| title = d.at("./title") n = title.next_element n&.children&.first &.add_previous_sibling("#{title.remove.text}—") end docxml end |
#cleanup(docxml) ⇒ Object
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/isodoc/function/cleanup.rb', line 16 def cleanup(docxml) @i18n ||= i18n_init(@lang, @script, @locale) comment_cleanup(docxml) inline_header_cleanup(docxml) figure_cleanup(docxml) table_cleanup(docxml) symbols_cleanup(docxml) example_cleanup(docxml) admonition_cleanup(docxml) end |
#empty_tags(html) ⇒ Object
Atomic group (?>…) prevents catastrophic backtracking across ‘>` characters. Quoted alternatives listed first so `/` inside attribute values (e.g. URLs in href=“…”) is consumed as part of the quoted string, not rejected by [^>/]. Includes Word HTML tags
98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/isodoc/function/cleanup.rb', line 98 def (html) void_elements = %w[area base br col embed hr img input link meta source track wbr wrapblock] html.gsub(%r{<([\w:]+)((?>"[^"]*"|'[^']*'|[^>/])*)\s*/>}) do if void_elements.include?($1) $& else "<#{$1}#{$2}></#{$1}>" end end end |
#example_cleanup(docxml) ⇒ Object
38 39 40 41 42 43 |
# File 'lib/isodoc/function/cleanup.rb', line 38 def example_cleanup(docxml) docxml.xpath("//table[@class = 'example']//p[not(@class)]").each do |p| p["class"] = "example" end docxml end |
#figure_cleanup(docxml) ⇒ Object
45 |
# File 'lib/isodoc/function/cleanup.rb', line 45 def figure_cleanup(docxml); end |
#inline_header_cleanup(docxml) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/isodoc/function/cleanup.rb', line 47 def inline_header_cleanup(docxml) docxml.xpath('//span[@class="zzMoveToFollowing"]').each do |x| x.delete("class") n = x.next_element if n.nil? x.name = "p" else n.add_first_child(x.remove) end end docxml end |
#merge_fnref_into_fn_text(elem) ⇒ Object
60 61 62 63 64 65 |
# File 'lib/isodoc/function/cleanup.rb', line 60 def merge_fnref_into_fn_text(elem) fn = elem.at('.//span[@class="TableFootnoteRef"]/..') or return n = fn.next_element n or return n.children.first.add_previous_sibling(fn.remove) end |
#passthrough_cleanup(docxml) ⇒ Object
8 9 10 11 12 13 14 |
# File 'lib/isodoc/function/cleanup.rb', line 8 def passthrough_cleanup(docxml) docxml.split(%r{(<passthrough>|</passthrough>)}).each_slice(4) .map do |a| a.size > 2 and a[2] = HTMLEntities.new.decode(a[2]) [a[0], a[2]] end.join end |
#symbols_cleanup(docxml) ⇒ Object
91 |
# File 'lib/isodoc/function/cleanup.rb', line 91 def symbols_cleanup(docxml); end |
#table_cleanup(docxml) ⇒ Object
86 87 88 89 |
# File 'lib/isodoc/function/cleanup.rb', line 86 def table_cleanup(docxml) table_footnote_cleanup(docxml) docxml end |
#table_footnote_cleanup(docxml) ⇒ Object
preempt html2doc putting MsoNormal under TableFootnote class
68 69 70 71 72 73 74 75 76 77 |
# File 'lib/isodoc/function/cleanup.rb', line 68 def table_footnote_cleanup(docxml) docxml.xpath("//tfoot[descendant::aside]").each do |t| t.xpath(".//aside").each do |a| merge_fnref_into_fn_text(a) a.name = "div" a["class"] = "TableFootnote" end end table_footnote_cleanup_propagate(docxml) end |
#table_footnote_cleanup_propagate(docxml) ⇒ Object
79 80 81 82 83 84 |
# File 'lib/isodoc/function/cleanup.rb', line 79 def table_footnote_cleanup_propagate(docxml) docxml.xpath("//p[not(self::*[@class])]" \ "[ancestor::*[@class = 'TableFootnote']]").each do |p| p["class"] = "TableFootnote" end end |
#textcleanup(docxml) ⇒ Object
4 5 6 |
# File 'lib/isodoc/function/cleanup.rb', line 4 def textcleanup(docxml) passthrough_cleanup(docxml) end |