Module: IsoDoc::HtmlFunction::Html
- Included in:
- IsoDoc::HeadlessHtmlConvert, IsoDoc::HtmlConvert, PdfConvert
- Defined in:
- lib/isodoc/html_function/html.rb,
lib/isodoc/html_function/postprocess.rb,
lib/isodoc/html_function/postprocess_cover.rb,
lib/isodoc/html_function/postprocess_footnotes.rb
Constant Summary collapse
- MATHJAX_ADDR =
"https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/latest.js".freeze
- MATHJAX =
<<~"MATHJAX".freeze <script type="text/x-mathjax-config"> MathJax.Hub.Config({ "HTML-CSS": { preferredFont: "STIX" }, asciimath2jax: { delimiters: [['OPEN', 'CLOSE']] } }); </script> <script src="#{MATHJAX_ADDR}?config=MML_HTMLorMML-full" async="async"></script> MATHJAX
Instance Method Summary collapse
- #authority_cleanup(docxml) ⇒ Object
- #authority_cleanup1(docxml, klass) ⇒ Object
- #convert1(docxml, filename, dir) ⇒ Object
- #coverpage_note_cleanup(docxml) ⇒ Object
- #datauri(img) ⇒ Object
- #footnote_backlinks(docxml) ⇒ Object
- #footnote_backlinks1(xref, footnote) ⇒ Object
- #footnote_format(docxml) ⇒ Object
- #googlefonts ⇒ Object
- #heading_anchor(hdr, id) ⇒ Object
- #heading_anchors(html) ⇒ Object
- #html5(doc) ⇒ Object
- #html_button ⇒ Object
- #html_cleanup(html) ⇒ Object
- #html_cover(docxml) ⇒ Object
- #html_footnote_filter(docxml) ⇒ Object
- #html_head ⇒ Object
- #html_intro(docxml) ⇒ Object
- #html_list_clean(html) ⇒ Object
- #html_main(docxml) ⇒ Object
- #html_preface(docxml) ⇒ Object
-
#html_toc(docxml) ⇒ Object
needs to be same output as toclevel.
- #html_toc_entries(docxml, path) ⇒ Object
- #html_toc_entries_prep(docxml, path) ⇒ Object
- #html_toc_entry(level, header) ⇒ Object
- #html_toc_init(docxml) ⇒ Object
- #htmlstyle(docxml) ⇒ Object
- #htmlstylesheet(file) ⇒ Object
- #image_body_parse(node, attrs, out) ⇒ Object
- #image_suffix(img) ⇒ Object
- #inject_script(doc) ⇒ Object
- #make_body1(body, _docxml) ⇒ Object
- #make_body2(body, _docxml) ⇒ Object
- #mathjax(open, close) ⇒ Object
- #mathml(docxml) ⇒ Object
- #move_image1(img) ⇒ Object
-
#move_images(docxml) ⇒ Object
presupposes that the image source is local.
- #postprocess(result, filename, _dir) ⇒ Object
- #remove_placeholder_paras(html) ⇒ Object
- #resize_images(docxml) ⇒ Object
- #script_cdata(result) ⇒ Object
- #sourcecode_cleanup(html) ⇒ Object
- #sourcecode_parse(node, out) ⇒ Object
- #table_attrs(node) ⇒ Object
- #term_header(docxml) ⇒ Object
- #toc_exclude_class ⇒ Object
- #toclevel ⇒ Object
-
#toclevel_classes ⇒ Object
array of arrays, one per level, containing XPath fragments for the elems matching that ToC level.
- #toHTML(result, filename) ⇒ Object
- #underline_parse(node, out) ⇒ Object
- #update_footnote_filter(fnote, xref, idx, seen) ⇒ Object
Instance Method Details
#authority_cleanup(docxml) ⇒ Object
62 63 64 65 66 67 |
# File 'lib/isodoc/html_function/postprocess_cover.rb', line 62 def (docxml) %w(copyright license legal feedback).each do |t| (docxml, t) end coverpage_note_cleanup(docxml) end |
#authority_cleanup1(docxml, klass) ⇒ Object
53 54 55 56 57 58 59 60 |
# File 'lib/isodoc/html_function/postprocess_cover.rb', line 53 def (docxml, klass) dest = docxml.at("//div[@id = 'boilerplate-#{klass}-destination']") auth = docxml.at("//div[@id = 'boilerplate-#{klass}' or " \ "@class = 'boilerplate-#{klass}']") auth&.xpath(".//h1[not(text())] | .//h2[not(text())]")&.each(&:remove) auth&.xpath(".//h1 | .//h2")&.each { |h| h["class"] = "IntroTitle" } dest and auth and dest.replace(auth.remove) end |
#convert1(docxml, filename, dir) ⇒ Object
7 8 9 10 11 12 13 14 15 16 |
# File 'lib/isodoc/html_function/html.rb', line 7 def convert1(docxml, filename, dir) noko do |xml| xml.html lang: @lang.to_s do |html| info docxml, nil populate_css html.head { |head| define_head head, filename, dir } make_body(html, docxml) end end.join("\n") end |
#coverpage_note_cleanup(docxml) ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/isodoc/html_function/postprocess_cover.rb', line 69 def coverpage_note_cleanup(docxml) if dest = docxml.at("//div[@id = 'coverpage-note-destination']") auth = docxml.xpath("//*[@coverpage]") if auth.empty? then dest.remove else auth.each do |x| dest << x.remove end end end docxml.xpath("//*[@coverpage]").each { |x| x.delete("coverpage") } end |
#datauri(img) ⇒ Object
104 105 106 |
# File 'lib/isodoc/html_function/postprocess.rb', line 104 def datauri(img) img["src"] = Vectory::Utils::datauri(img["src"], @localdir) end |
#footnote_backlinks(docxml) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/isodoc/html_function/postprocess_footnotes.rb', line 40 def footnote_backlinks(docxml) seen = {} docxml.xpath('//a[@class = "FootnoteRef"]').each_with_index do |x, i| (seen[x["href"]] and next) or seen[x["href"]] = true fn = docxml.at(%<//*[@id = '#{x['href'].sub(/^#/, '')}']>) || next footnote_backlinks1(x, fn) x["id"] ||= "fnref:#{i + 1}" fn.add_child "<a href='##{x['id']}'>↩</a>" end docxml end |
#footnote_backlinks1(xref, footnote) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/isodoc/html_function/postprocess_footnotes.rb', line 27 def footnote_backlinks1(xref, footnote) xdup = xref.dup xdup.remove["id"] if footnote.elements.empty? #footnote.children.empty? and footnote << " " #footnote.children.first.previous = xdup footnote.add_first_child xdup else #footnote.elements.first.children.first.previous = xdup footnote.elements.first.add_first_child xdup end end |
#footnote_format(docxml) ⇒ Object
52 53 54 55 56 57 58 59 60 61 |
# File 'lib/isodoc/html_function/postprocess_footnotes.rb', line 52 def footnote_format(docxml) docxml.xpath("//a[@class = 'FootnoteRef']/sup").each do |x| footnote_reference_format(x) end docxml.xpath("//a[@class = 'TableFootnoteRef'] | "\ "//span[@class = 'TableFootnoteRef']").each do |x| table_footnote_reference_format(x) end docxml end |
#googlefonts ⇒ Object
36 37 38 39 40 41 |
# File 'lib/isodoc/html_function/html.rb', line 36 def googlefonts <<~HEAD.freeze <link href="https://fonts.googleapis.com/css?family=Overpass:300,300i,600,900" rel="stylesheet"/> <link href="https://fonts.googleapis.com/css?family=Lato:400,400i,700,900" rel="stylesheet"/> HEAD end |
#heading_anchor(hdr, id) ⇒ Object
45 46 47 48 49 |
# File 'lib/isodoc/html_function/postprocess.rb', line 45 def heading_anchor(hdr, id) hdr.children = <<~HTML.strip <a class='anchor' href='##{id}'/><a class='header' href='##{id}'>#{hdr.children.to_xml}</a> HTML end |
#heading_anchors(html) ⇒ Object
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/isodoc/html_function/postprocess.rb', line 34 def heading_anchors(html) html.xpath("//h1 | //h2 | //h3 | //h4 | //h5 | //h6 | //h7 | //h8 "\ "//span[@class = 'inline-header']").each do |h| h.at("./ancestor::div[@id='toc']") and next div = h.xpath("./ancestor::div[@id]") div.empty? and next heading_anchor(h, div[-1]["id"]) end html end |
#html5(doc) ⇒ Object
22 23 24 25 |
# File 'lib/isodoc/html_function/postprocess.rb', line 22 def html5(doc) doc.sub(%r{<!DOCTYPE html [^<>]+>}, "<!DOCTYPE html>") .sub(%r{<\?xml[^<>]+>}, "") end |
#html_button ⇒ Object
62 63 64 65 66 67 |
# File 'lib/isodoc/html_function/html.rb', line 62 def return "" if @bare '<button onclick="topFunction()" id="myBtn" ' \ 'title="Go to top">Top</button>'.freeze end |
#html_cleanup(html) ⇒ Object
27 28 29 30 31 32 |
# File 'lib/isodoc/html_function/postprocess.rb', line 27 def html_cleanup(html) html = term_header(html_footnote_filter(html_preface(htmlstyle(html)))) html = footnote_format(footnote_backlinks(html)) html = mathml(html_list_clean(remove_placeholder_paras(html))) html_toc(heading_anchors(sourcecode_cleanup(html))) end |
#html_cover(docxml) ⇒ Object
82 83 84 85 86 87 88 89 |
# File 'lib/isodoc/html_function/postprocess_cover.rb', line 82 def html_cover(docxml) doc = to_xhtml_fragment(File.read(@htmlcoverpage, encoding: "UTF-8")) d = docxml.at('//div[@class="title-section"]') #d.children.first.add_previous_sibling( d.add_first_child( populate_template(doc.to_xml(encoding: "US-ASCII"), :html), ) end |
#html_footnote_filter(docxml) ⇒ Object
17 18 19 20 21 22 23 24 25 |
# File 'lib/isodoc/html_function/postprocess_footnotes.rb', line 17 def html_footnote_filter(docxml) seen = {} i = 1 docxml.xpath('//a[@class = "FootnoteRef"]').each do |x| fn = docxml.at(%<//*[@id = '#{x['href'].sub(/^#/, '')}']>) || next i, seen = update_footnote_filter(fn, x, i, seen) end docxml end |
#html_head ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/isodoc/html_function/html.rb', line 43 def html_head <<~HEAD.freeze <title>#{@meta&.get&.dig(:doctitle)}</title> <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <!--TOC script import--> <script type="text/javascript" src="https://cdn.rawgit.com/jgallen23/toc/0.3.2/dist/toc.min.js"></script> <script type="text/javascript">#{toclevel}</script> <!--Google fonts--> <link rel="preconnect" href="https://fonts.gstatic.com"/> #{googlefonts} <!--Font awesome import for the link icon--> <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.0.8/css/solid.css" integrity="sha384-v2Tw72dyUXeU3y4aM2Y0tBJQkGfplr39mxZqlTBDUZAb9BGoC40+rdFCG0m10lXk" crossorigin="anonymous"/> <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.0.8/css/fontawesome.css" integrity="sha384-q3jl8XQu1OpdLgGFvNRnPdj5VIlCvgsDQTQB6owSOHWlAurxul7f+JpUOVdAiJ5P" crossorigin="anonymous"/> <style class="anchorjs"></style> HEAD end |
#html_intro(docxml) ⇒ Object
91 92 93 94 95 96 97 98 |
# File 'lib/isodoc/html_function/postprocess_cover.rb', line 91 def html_intro(docxml) doc = to_xhtml_fragment(File.read(@htmlintropage, encoding: "UTF-8")) d = docxml.at('//div[@class="prefatory-section"]') #d.children.first.add_previous_sibling( d.add_first_child( populate_template(doc.to_xml(encoding: "US-ASCII"), :html), ) end |
#html_list_clean(html) ⇒ Object
70 71 72 73 74 75 76 77 |
# File 'lib/isodoc/html_function/postprocess.rb', line 70 def html_list_clean(html) html.xpath("//ol/div | //ul/div").each do |div| li = div.xpath("./preceding-sibling::li")&.last || div.at("./following-sibling::li") div.parent = li end html end |
#html_main(docxml) ⇒ Object
69 70 71 72 73 74 |
# File 'lib/isodoc/html_function/html.rb', line 69 def html_main(docxml) docxml.at("//head").add_child(html_head) d = docxml.at('//div[@class="main-section"]') d.name = "main" d.children.empty? or d.children.first.previous = end |
#html_preface(docxml) ⇒ Object
42 43 44 45 46 47 48 49 50 51 |
# File 'lib/isodoc/html_function/postprocess_cover.rb', line 42 def html_preface(docxml) @htmlcoverpage && !@htmlcoverpage.empty? && !@bare and html_cover(docxml) @htmlintropage && !@htmlintropage.empty? && !@bare and html_intro(docxml) docxml.at("//body") << mathjax(@openmathdelim, @closemathdelim) html_main(docxml) (docxml) docxml end |
#html_toc(docxml) ⇒ Object
needs to be same output as toclevel
125 126 127 128 129 130 131 132 133 134 |
# File 'lib/isodoc/html_function/postprocess_cover.rb', line 125 def html_toc(docxml) idx = html_toc_init(docxml) or return docxml path = toclevel_classes.map do |x| x.map { |l| "//main//#{l}#{toc_exclude_class}" } end toc = html_toc_entries(docxml, path) .map { |k| k[:entry] }.join("\n") idx << "<ul>#{toc}</ul>" docxml end |
#html_toc_entries(docxml, path) ⇒ Object
144 145 146 147 148 149 150 151 152 |
# File 'lib/isodoc/html_function/postprocess_cover.rb', line 144 def html_toc_entries(docxml, path) headers = html_toc_entries_prep(docxml, path) path.each_with_index.with_object([]) do |(p, i), m| docxml.xpath(p.join(" | ")).each do |h| m << { entry: html_toc_entry("h#{i + 1}", h), line: headers[h["id"]] } end end.sort_by { |k| k[:line] } end |
#html_toc_entries_prep(docxml, path) ⇒ Object
154 155 156 157 158 159 160 |
# File 'lib/isodoc/html_function/postprocess_cover.rb', line 154 def html_toc_entries_prep(docxml, path) docxml.xpath(path.join(" | ")) .each_with_index.with_object({}) do |(h, i), m| h["id"] ||= "_#{UUIDTools::UUID.random_create}" m[h["id"]] = i end end |
#html_toc_entry(level, header) ⇒ Object
100 101 102 103 104 105 106 107 |
# File 'lib/isodoc/html_function/postprocess_cover.rb', line 100 def html_toc_entry(level, header) content = header.at("./following-sibling::p" \ "[@class = 'variant-title-toc']") || header id = header.at(".//a[@class = 'anchor']/@href")&.text&.sub(/^#/, "") || header["id"] %(<li class="#{level}"><a href="##{id}">\ #{header_strip(content)}</a></li>) end |
#html_toc_init(docxml) ⇒ Object
136 137 138 139 140 141 142 |
# File 'lib/isodoc/html_function/postprocess_cover.rb', line 136 def html_toc_init(docxml) dest = docxml.at("//div[@id = 'toc']") or return if source = docxml.at("//div[@class = 'TOC']") dest << to_xml(source.remove.children) end dest end |
#htmlstyle(docxml) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/isodoc/html_function/postprocess_cover.rb', line 28 def htmlstyle(docxml) return docxml unless @htmlstylesheet head = docxml.at("//*[local-name() = 'head']") head << htmlstylesheet(@htmlstylesheet) s = htmlstylesheet(@htmlstylesheet_override) and head << s s = @meta.get[:code_css] and head << "<style><!--#{s.gsub(/sourcecode/, 'pre.sourcecode')}--></style>" @bare and head << "<style>body {margin-left: 2em; margin-right: 2em;}</style>" docxml end |
#htmlstylesheet(file) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/isodoc/html_function/postprocess_cover.rb', line 15 def htmlstylesheet(file) return if file.nil? file.open if file.is_a?(Tempfile) stylesheet = file.read xml = Nokogiri::XML("<style/>") xml.children.first << Nokogiri::XML::Comment .new(xml, "\n#{stylesheet}\n") file.close file.unlink if file.is_a?(Tempfile) xml.root.to_s end |
#image_body_parse(node, attrs, out) ⇒ Object
101 102 103 104 105 106 107 108 109 110 |
# File 'lib/isodoc/html_function/html.rb', line 101 def image_body_parse(node, attrs, out) if svg = node.at("./m:svg", "m" => "http://www.w3.org/2000/svg") %i(height width).each do |k| v = attrs[k] and v != "auto" and !v.empty? and svg[k.to_s] = v end out.parent.add_child(svg) else super end end |
#image_suffix(img) ⇒ Object
108 109 110 111 112 113 114 |
# File 'lib/isodoc/html_function/postprocess.rb', line 108 def image_suffix(img) type = img["mimetype"]&.sub(%r{^[^/*]+/}, "") matched = /\.(?<suffix>[^. \r\n\t]+)$/.match img["src"] type and !type.empty? and return type !matched.nil? and matched[:suffix] and return matched[:suffix] "png" end |
#inject_script(doc) ⇒ Object
167 168 169 170 171 172 173 174 175 176 |
# File 'lib/isodoc/html_function/postprocess_cover.rb', line 167 def inject_script(doc) return doc unless @scripts scripts = File.read(@scripts, encoding: "UTF-8") scripts_override = "" @scripts_override and scripts_override = File.read(@scripts_override, encoding: "UTF-8") a = doc.split(%r{</body>}) "#{a[0]}#{scripts}#{scripts_override}</body>#{a[1]}" end |
#make_body1(body, _docxml) ⇒ Object
18 19 20 21 22 23 24 25 |
# File 'lib/isodoc/html_function/html.rb', line 18 def make_body1(body, _docxml) return if @bare body.div class: "title-section" do |div1| div1.p { |p| p << " " } # placeholder end section_break(body) end |
#make_body2(body, _docxml) ⇒ Object
27 28 29 30 31 32 33 34 |
# File 'lib/isodoc/html_function/html.rb', line 27 def make_body2(body, _docxml) return if @bare body.div class: "prefatory-section" do |div2| div2.p { |p| p << " " } # placeholder end section_break(body) end |
#mathjax(open, close) ⇒ Object
190 191 192 |
# File 'lib/isodoc/html_function/postprocess_cover.rb', line 190 def mathjax(open, close) MATHJAX.gsub("OPEN", open).gsub("CLOSE", close) end |
#mathml(docxml) ⇒ Object
79 80 81 |
# File 'lib/isodoc/html_function/postprocess.rb', line 79 def mathml(docxml) IsoDoc::HtmlFunction::MathvariantToPlain.new(docxml).convert end |
#move_image1(img) ⇒ Object
116 117 118 119 120 121 122 123 124 |
# File 'lib/isodoc/html_function/postprocess.rb', line 116 def move_image1(img) suffix = image_suffix(img) uuid = UUIDTools::UUID.random_create.to_s fname = "#{uuid}.#{suffix}" new_full_filename = File.join(tmpimagedir, fname) local_filename = image_localfile(img) FileUtils.cp local_filename, new_full_filename img["src"] = File.join(rel_tmpimagedir, fname) end |
#move_images(docxml) ⇒ Object
presupposes that the image source is local
94 95 96 97 98 99 100 101 102 |
# File 'lib/isodoc/html_function/postprocess.rb', line 94 def move_images(docxml) FileUtils.rm_rf tmpimagedir FileUtils.mkdir tmpimagedir docxml.xpath("//*[local-name() = 'img'][@src]").each do |i| /^data:/.match? i["src"] and next @datauriimage ? datauri(i) : move_image1(i) end docxml end |
#postprocess(result, filename, _dir) ⇒ Object
9 10 11 12 13 |
# File 'lib/isodoc/html_function/postprocess.rb', line 9 def postprocess(result, filename, _dir) result = from_xhtml(cleanup(to_xhtml(textcleanup(result)))) toHTML(result, filename) @files_to_delete.each { |f| FileUtils.rm_rf f } end |
#remove_placeholder_paras(html) ⇒ Object
63 64 65 66 67 68 |
# File 'lib/isodoc/html_function/postprocess.rb', line 63 def remove_placeholder_paras(html) %w(title-section prefatory-section).each do |s| html&.at("//div[@class = '#{s}']/p[last()]")&.remove end html end |
#resize_images(docxml) ⇒ Object
83 84 85 86 87 88 89 90 91 |
# File 'lib/isodoc/html_function/postprocess.rb', line 83 def resize_images(docxml) docxml.xpath("//*[local-name() = 'img' or local-name() = 'svg']") .each do |i| loc = image_localfile(i) or next i["width"], i["height"] = Vectory::ImageResize.new .call(i, loc, @maxheight, @maxwidth) end docxml end |
#script_cdata(result) ⇒ Object
8 9 10 11 12 13 |
# File 'lib/isodoc/html_function/postprocess_cover.rb', line 8 def script_cdata(result) result.gsub(%r{<script([^<>]*)>\s*<!\[CDATA\[}m, "<script\\1>") .gsub(%r{\]\]>\s*</script>}, "</script>") .gsub(%r{<!\[CDATA\[\s*<script([^<>]*)>}m, "<script\\1>") .gsub(%r{</script>\s*\]\]>}, "</script>") end |
#sourcecode_cleanup(html) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/isodoc/html_function/postprocess.rb', line 51 def sourcecode_cleanup(html) ann = ".//div[@class = 'annotation']" html.xpath("//pre[#{ann}] | //div[@class = 'sourcecode'][#{ann}]") .each do |p| ins = p.after("<pre class='sourcecode'/>").next_element p.xpath(ann).each do |d| ins << d.remove.children end end html end |
#sourcecode_parse(node, out) ⇒ Object
76 77 78 79 80 81 82 83 84 85 |
# File 'lib/isodoc/html_function/html.rb', line 76 def sourcecode_parse(node, out) name = node.at(ns("./fmt-name")) tag = node.at(ns(".//sourcecode | .//table")) ? "div" : "pre" attr = sourcecode_attrs(node).merge(class: "sourcecode") out.send tag, **attr do |div| sourcecode_parse1(node, div) end annotation_parse(node, out) sourcecode_name_parse(node, out, name) end |
#table_attrs(node) ⇒ Object
95 96 97 98 99 |
# File 'lib/isodoc/html_function/html.rb', line 95 def table_attrs(node) ret = super node.at(ns("./colgroup")) and ret[:style] += "table-layout:fixed;" ret end |
#term_header(docxml) ⇒ Object
126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/isodoc/html_function/postprocess.rb', line 126 def term_header(docxml) %w(h1 h2 h3 h4 h5 h6 h7 h8).each do |h| docxml.xpath("//p[@class = 'TermNum'][../#{h}]").each do |p| p.name = "h#{h[1].to_i + 1}" id = p["id"] p["id"] = "_#{UUIDTools::UUID.random_create}" p.wrap("<div id='#{id}'></div>") end end docxml end |
#toc_exclude_class ⇒ Object
162 163 164 165 |
# File 'lib/isodoc/html_function/postprocess_cover.rb', line 162 def toc_exclude_class "[not(@class = 'TermNum')][not(@class = 'noTOC')]" \ "[string-length(normalize-space(.))>0]" end |
#toclevel ⇒ Object
115 116 117 118 119 120 121 122 |
# File 'lib/isodoc/html_function/postprocess_cover.rb', line 115 def toclevel ret = toclevel_classes.flatten.map do |l| "#{l}:not(:empty):not(.TermNum):not(.noTOC)" end <<~HEAD.freeze function toclevel() { return "#{ret.join(',')}";} HEAD end |
#toclevel_classes ⇒ Object
array of arrays, one per level, containing XPath fragments for the elems matching that ToC level
111 112 113 |
# File 'lib/isodoc/html_function/postprocess_cover.rb', line 111 def toclevel_classes (1..@htmlToClevels).reduce([]) { |m, i| m << ["h#{i}"] } end |
#toHTML(result, filename) ⇒ Object
15 16 17 18 19 20 |
# File 'lib/isodoc/html_function/postprocess.rb', line 15 def toHTML(result, filename) result = from_xhtml(html_cleanup(to_xhtml(result))) result = from_xhtml(move_images(resize_images(to_xhtml(result)))) result = html5(script_cdata(inject_script(result))) File.open(filename, "w:UTF-8") { |f| f.write(result) } end |
#underline_parse(node, out) ⇒ Object
87 88 89 90 91 92 93 |
# File 'lib/isodoc/html_function/html.rb', line 87 def underline_parse(node, out) style = node["style"] ? " #{node['style']}" : "" attr = { style: "text-decoration: underline#{style}" } out.span **attr do |e| node.children.each { |n| parse(n, e) } end end |
#update_footnote_filter(fnote, xref, idx, seen) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/isodoc/html_function/postprocess_footnotes.rb', line 4 def update_footnote_filter(fnote, xref, idx, seen) if seen[fnote.text] xref.at("./sup").content = seen[fnote.text][:num].to_s fnote.remove unless xref["href"] == seen[fnote.text][:href] xref["href"] = seen[fnote.text][:href] else seen[fnote.text] = { num: idx, href: xref["href"] } xref.at("./sup").content = idx.to_s idx += 1 end [idx, seen] end |