Module: Asciidoctor::Standoc::Base
- Included in:
- Converter
- Defined in:
- lib/asciidoctor/standoc/base.rb
Constant Summary collapse
- XML_ROOT_TAG =
"standard-document".freeze
- XML_NAMESPACE =
"https://www.metanorma.org/ns/standoc".freeze
- TERM_REFERENCE_RE_STR =
<<~REGEXP.freeze ^(?<xref><(xref|concept)[^>]+>([^<]*</(xref|concept)>)?) (,\s(?<text>.*))? $ REGEXP
- TERM_REFERENCE_RE =
Regexp.new(TERM_REFERENCE_RE_STR.gsub(/\s/, "").gsub(/_/, "\\s"), Regexp::IGNORECASE | Regexp::MULTILINE)
Instance Method Summary collapse
- #add_term_source(xml_t, seen_xref, m) ⇒ Object
- #clean_exit ⇒ Object
- #content(node) ⇒ Object
- #default_fonts(node) ⇒ Object
- #doc_converter(node) ⇒ Object
- #doc_extract_attributes(node) ⇒ Object
- #doctype(node) ⇒ Object
- #document(node) ⇒ Object
- #draft? ⇒ Boolean
- #extract_termsource_refs(text, node) ⇒ Object
- #front(node, xml) ⇒ Object
- #html_converter(node) ⇒ Object
- #html_extract_attributes(node) ⇒ Object
- #init(node) ⇒ Object
- #makexml(node) ⇒ Object
- #makexml1(node) ⇒ Object
- #middle(node, xml) ⇒ Object
- #skip(node, name = nil) ⇒ Object
- #term_source_attrs(seen_xref) ⇒ Object
- #termsource(node) ⇒ Object
- #xml_namespace ⇒ Object
- #xml_root_tag ⇒ Object
Instance Method Details
#add_term_source(xml_t, seen_xref, m) ⇒ Object
201 202 203 204 205 206 207 208 209 210 211 |
# File 'lib/asciidoctor/standoc/base.rb', line 201 def add_term_source(xml_t, seen_xref, m) if seen_xref.children[0].name == "concept" xml_t.origin { |o| o << seen_xref.children[0].to_xml } else xml_t.origin seen_xref.children[0].content, **attr_code(term_source_attrs(seen_xref)) end m[:text] && xml_t.modification do |mod| mod.p { |p| p << m[:text].sub(/^\s+/, "") } end end |
#clean_exit ⇒ Object
153 154 155 156 |
# File 'lib/asciidoctor/standoc/base.rb', line 153 def clean_exit @log.write(@localdir + @filename + ".err") unless @novalid @files_to_delete.each { |f| FileUtils.rm f } end |
#content(node) ⇒ Object
41 42 43 |
# File 'lib/asciidoctor/standoc/base.rb', line 41 def content(node) node.content end |
#default_fonts(node) ⇒ Object
130 131 132 133 134 135 136 137 138 139 |
# File 'lib/asciidoctor/standoc/base.rb', line 130 def default_fonts(node) b = node.attr("body-font") || (node.attr("script") == "Hans" ? '"SimSun",serif' : '"Cambria",serif') h = node.attr("header-font") || (node.attr("script") == "Hans" ? '"SimHei",sans-serif' : '"Cambria",serif') m = node.attr("monospace-font") || '"Courier New",monospace' "$bodyfont: #{b};\n$headerfont: #{h};\n$monospacefont: #{m};\n" end |
#doc_converter(node) ⇒ Object
97 98 99 |
# File 'lib/asciidoctor/standoc/base.rb', line 97 def doc_converter(node) IsoDoc::WordConvert.new(doc_extract_attributes(node)) end |
#doc_extract_attributes(node) ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/asciidoctor/standoc/base.rb', line 76 def doc_extract_attributes(node) { script: node.attr("script"), bodyfont: node.attr("body-font"), headerfont: node.attr("header-font"), monospacefont: node.attr("monospace-font"), i18nyaml: node.attr("i18nyaml"), scope: node.attr("scope"), wordstylesheet: node.attr("wordstylesheet"), standardstylesheet: node.attr("standardstylesheet"), header: node.attr("header"), wordcoverpage: node.attr("wordcoverpage"), wordintropage: node.attr("wordintropage"), ulstyle: node.attr("ulstyle"), olstyle: node.attr("olstyle"), htmltoclevels: node.attr("htmltoclevels") || node.attr("toclevels"), doctoclevels: node.attr("doctoclevels") || node.attr("toclevels"), break_up_urls_in_tables: node.attr("break-up-urls-in-tables"), } end |
#doctype(node) ⇒ Object
179 180 181 |
# File 'lib/asciidoctor/standoc/base.rb', line 179 def doctype(node) node.attr("doctype") end |
#document(node) ⇒ Object
141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/asciidoctor/standoc/base.rb', line 141 def document(node) init(node) ret = makexml(node).to_xml(indent: 2) unless node.attr("nodoc") || !node.attr("docfile") File.open(@filename + ".xml", "w:UTF-8") { |f| f.write(ret) } html_converter(node).convert(@filename + ".xml") doc_converter(node).convert(@filename + ".xml") end clean_exit ret end |
#draft? ⇒ Boolean
175 176 177 |
# File 'lib/asciidoctor/standoc/base.rb', line 175 def draft? @draft end |
#extract_termsource_refs(text, node) ⇒ Object
222 223 224 225 226 227 |
# File 'lib/asciidoctor/standoc/base.rb', line 222 def extract_termsource_refs(text, node) matched = TERM_REFERENCE_RE.match text matched.nil? and @log.add("AsciiDoc Input", node, "term reference not in expected format: #{text}") matched end |
#front(node, xml) ⇒ Object
183 184 185 186 187 |
# File 'lib/asciidoctor/standoc/base.rb', line 183 def front(node, xml) xml.bibdata **attr_code(type: "standard") do |b| node, b end end |
#html_converter(node) ⇒ Object
72 73 74 |
# File 'lib/asciidoctor/standoc/base.rb', line 72 def html_converter(node) IsoDoc::HtmlConvert.new(html_extract_attributes(node)) end |
#html_extract_attributes(node) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/asciidoctor/standoc/base.rb', line 52 def html_extract_attributes(node) { script: node.attr("script"), bodyfont: node.attr("body-font"), headerfont: node.attr("header-font"), monospacefont: node.attr("monospace-font"), i18nyaml: node.attr("i18nyaml"), scope: node.attr("scope"), htmlstylesheet: node.attr("htmlstylesheet"), htmlcoverpage: node.attr("htmlcoverpage"), htmlintropage: node.attr("htmlintropage"), scripts: node.attr("scripts"), scripts_pdf: node.attr("scripts-pdf"), datauriimage: node.attr("data-uri-image"), htmltoclevels: node.attr("htmltoclevels") || node.attr("toclevels"), doctoclevels: node.attr("doctoclevels") || node.attr("toclevels"), break_up_urls_in_tables: node.attr("break-up-urls-in-tables"), } end |
#init(node) ⇒ Object
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/asciidoctor/standoc/base.rb', line 101 def init(node) @fn_number ||= 0 @draft = false @refids = Set.new @anchors = {} @draft = node.attributes.has_key?("draft") @novalid = node.attr("novalid") @smartquotes = node.attr("smartquotes") != "false" @keepasciimath = node.attr("mn-keep-asciimath") && node.attr("mn-keep-asciimath") != "false" @fontheader = default_fonts(node) @files_to_delete = [] @filename = node.attr("docfile") ? File.basename(node.attr("docfile")).gsub(/\.adoc$/, "") : "" @localdir = Utils::localdir(node) @no_isobib_cache = node.attr("no-isobib-cache") @no_isobib = node.attr("no-isobib") @bibdb = nil @seen_headers = [] @datauriimage = node.attr("data-uri-image") @boilerplateauthority = node.attr("boilerplate-authority") @log = Asciidoctor::Standoc::Log.new init_bib_caches(node) init_iev_caches(node) lang = (node.attr("language") || "en") script = (node.attr("script") || "en") i18n_init(lang, script) end |
#makexml(node) ⇒ Object
167 168 169 170 171 172 173 |
# File 'lib/asciidoctor/standoc/base.rb', line 167 def makexml(node) result = makexml1(node) ret1 = cleanup(Nokogiri::XML(result)) ret1.root.add_namespace(nil, xml_namespace) validate(ret1) unless @novalid ret1 end |
#makexml1(node) ⇒ Object
158 159 160 161 162 163 164 165 |
# File 'lib/asciidoctor/standoc/base.rb', line 158 def makexml1(node) result = ["<?xml version='1.0' encoding='UTF-8'?>", "<#{xml_root_tag}>"] result << noko { |ixml| front node, ixml } result << noko { |ixml| middle node, ixml } result << "</#{xml_root_tag}>" textcleanup(result) end |
#middle(node, xml) ⇒ Object
189 190 191 192 193 |
# File 'lib/asciidoctor/standoc/base.rb', line 189 def middle(node, xml) xml.sections do |s| s << node.content if node.blocks? end end |
#skip(node, name = nil) ⇒ Object
45 46 47 48 49 50 |
# File 'lib/asciidoctor/standoc/base.rb', line 45 def skip(node, name = nil) name = name || node.node_name w = "converter missing for #{name} node in Metanorma backend" @log.add("AsciiDoc Input", node, w) nil end |
#term_source_attrs(seen_xref) ⇒ Object
195 196 197 198 199 |
# File 'lib/asciidoctor/standoc/base.rb', line 195 def term_source_attrs(seen_xref) { bibitemid: seen_xref.children[0]["target"], format: seen_xref.children[0]["format"], type: "inline" } end |
#termsource(node) ⇒ Object
229 230 231 232 233 234 235 236 237 238 |
# File 'lib/asciidoctor/standoc/base.rb', line 229 def termsource(node) matched = extract_termsource_refs(node.content, node) || return noko do |xml| attrs = { status: matched[:text] ? "modified" : "identical" } xml.termsource **attrs do |xml_t| seen_xref = Nokogiri::XML.fragment(matched[:xref]) add_term_source(xml_t, seen_xref, matched) end end.join("\n") end |
#xml_namespace ⇒ Object
37 38 39 |
# File 'lib/asciidoctor/standoc/base.rb', line 37 def xml_namespace self.class::XML_NAMESPACE end |
#xml_root_tag ⇒ Object
33 34 35 |
# File 'lib/asciidoctor/standoc/base.rb', line 33 def xml_root_tag self.class::XML_ROOT_TAG end |