Module: Asciidoctor::Standoc::Base
- Included in:
- Converter
- Defined in:
- lib/asciidoctor/standoc/base.rb
Constant Summary collapse
- TERM_REFERENCE_RE_STR =
<<~REGEXP.freeze ^(?<xref><xref[^>]+>([^<]*</xref>)?) (,\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
- #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
- #init_bib_caches(node) ⇒ Object
- #init_iev_caches(node) ⇒ Object
- #makexml(node) ⇒ Object
- #makexml1(node) ⇒ Object
- #middle(node, xml) ⇒ Object
- #skip(node, name = nil) ⇒ Object
- #term_source_attr(seen_xref) ⇒ Object
- #termsource(node) ⇒ Object
Instance Method Details
#add_term_source(xml_t, seen_xref, m) ⇒ Object
190 191 192 193 194 195 196 |
# File 'lib/asciidoctor/standoc/base.rb', line 190 def add_term_source(xml_t, seen_xref, m) xml_t.origin seen_xref.children[0].content, **attr_code(term_source_attr(seen_xref)) m[:text] && xml_t.modification do |mod| mod.p { |p| p << m[:text].sub(/^\s+/, "") } end end |
#content(node) ⇒ Object
23 24 25 |
# File 'lib/asciidoctor/standoc/base.rb', line 23 def content(node) node.content end |
#default_fonts(node) ⇒ Object
125 126 127 128 129 130 131 132 133 134 |
# File 'lib/asciidoctor/standoc/base.rb', line 125 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
73 74 75 |
# File 'lib/asciidoctor/standoc/base.rb', line 73 def doc_converter(node) IsoDoc::WordConvert.new(doc_extract_attributes(node)) end |
#doc_extract_attributes(node) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/asciidoctor/standoc/base.rb', line 55 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"), } end |
#doctype(node) ⇒ Object
168 169 170 |
# File 'lib/asciidoctor/standoc/base.rb', line 168 def doctype(node) node.attr("doctype") end |
#document(node) ⇒ Object
136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/asciidoctor/standoc/base.rb', line 136 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 @files_to_delete.each { |f| FileUtils.rm f } ret end |
#draft? ⇒ Boolean
164 165 166 |
# File 'lib/asciidoctor/standoc/base.rb', line 164 def draft? @draft end |
#extract_termsource_refs(text, node) ⇒ Object
207 208 209 210 211 212 213 |
# File 'lib/asciidoctor/standoc/base.rb', line 207 def extract_termsource_refs(text, node) matched = TERM_REFERENCE_RE.match text if matched.nil? Utils::warning(node, "term reference not in expected format", text) end matched end |
#front(node, xml) ⇒ Object
172 173 174 175 176 |
# File 'lib/asciidoctor/standoc/base.rb', line 172 def front(node, xml) xml.bibdata **attr_code(type: doctype(node)) do |b| node, b end end |
#html_converter(node) ⇒ Object
51 52 53 |
# File 'lib/asciidoctor/standoc/base.rb', line 51 def html_converter(node) IsoDoc::HtmlConvert.new(html_extract_attributes(node)) end |
#html_extract_attributes(node) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/asciidoctor/standoc/base.rb', line 34 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"), } end |
#init(node) ⇒ Object
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/asciidoctor/standoc/base.rb', line 77 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" @fontheader = default_fonts(node) @files_to_delete = [] @filename = node.attr("docfile") ? node.attr("docfile").gsub(/\.adoc$/, "").gsub(%r{^.*/}, "") : "" @localdir = %r{/}.match(node.attr("docfile")) ? node.attr("docfile").sub(%r{/[^/]+$}, "/") : "./" @no_isobib_cache = node.attr("no-isobib-cache") @no_isobib = node.attr("no-isobib") @bibdb = nil @seen_headers = [] @datauriimage = node.attr("data-uri-image") init_bib_caches(node) init_iev_caches(node) end |
#init_bib_caches(node) ⇒ Object
100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/asciidoctor/standoc/base.rb', line 100 def init_bib_caches(node) unless (@no_isobib_cache || @no_isobib) globalname = global_bibliocache_name unless node.attr("local-cache-only") localname = local_bibliocache_name(node.attr("local-cache") || node.attr("local-cache-only")) if node.attr("flush-caches") FileUtils.rm_f globalname unless globalname.nil? FileUtils.rm_f localname unless localname.nil? end end @bibdb = Relaton::Db.new(globalname, localname) unless @no_isobib end |
#init_iev_caches(node) ⇒ Object
112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/asciidoctor/standoc/base.rb', line 112 def init_iev_caches(node) unless (@no_isobib_cache || @no_isobib) globalname = ievcache_name(true) unless node.attr("local-cache-only") localname = ievcache_name(false) if node.attr("local-cache") || node.attr("local-cache-only") if node.attr("flush-caches") FileUtils.rm_f globalname unless globalname.nil? FileUtils.rm_f localname unless localname.nil? end end @iev = Iev::Db.new(globalname, localname) unless @no_isobib end |
#makexml(node) ⇒ Object
156 157 158 159 160 161 162 |
# File 'lib/asciidoctor/standoc/base.rb', line 156 def makexml(node) result = makexml1(node) ret1 = cleanup(Nokogiri::XML(result)) ret1.root.add_namespace(nil, "http://riboseinc.com/isoxml") validate(ret1) unless @novalid ret1 end |
#makexml1(node) ⇒ Object
148 149 150 151 152 153 154 |
# File 'lib/asciidoctor/standoc/base.rb', line 148 def makexml1(node) result = ["<?xml version='1.0' encoding='UTF-8'?>\n<standard-document>"] result << noko { |ixml| front node, ixml } result << noko { |ixml| middle node, ixml } result << "</standard-document>" textcleanup(result.flatten * "\n") end |
#middle(node, xml) ⇒ Object
178 179 180 181 182 |
# File 'lib/asciidoctor/standoc/base.rb', line 178 def middle(node, xml) xml.sections do |s| s << node.content if node.blocks? end end |
#skip(node, name = nil) ⇒ Object
27 28 29 30 31 32 |
# File 'lib/asciidoctor/standoc/base.rb', line 27 def skip(node, name = nil) name = name || node.node_name w = "converter missing for #{name} node in ISO backend" Utils::warning(node, w, nil) nil end |
#term_source_attr(seen_xref) ⇒ Object
184 185 186 187 188 |
# File 'lib/asciidoctor/standoc/base.rb', line 184 def term_source_attr(seen_xref) { bibitemid: seen_xref.children[0]["target"], format: seen_xref.children[0]["format"], type: "inline" } end |
#termsource(node) ⇒ Object
215 216 217 218 219 220 221 222 223 224 |
# File 'lib/asciidoctor/standoc/base.rb', line 215 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 |