Module: Asciidoctor::Standoc::Utils
- Included in:
- Converter
- Defined in:
- lib/asciidoctor/standoc/utils.rb
Defined Under Namespace
Classes: EmptyAttr
Constant Summary collapse
- NOKOHEAD =
"<!DOCTYPE html SYSTEM\n\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n<html xmlns=\"http://www.w3.org/1999/xhtml\">\n<head> <title></title> <meta charset=\"UTF-8\" /> </head>\n<body> </body> </html>\n".freeze
- SUBCLAUSE_XPATH =
"//clause[not(parent::sections)]"\ "[not(ancestor::boilerplate)]".freeze
Instance Method Summary collapse
- #attr_code(attributes) ⇒ Object
- #convert(node, transform = nil, opts = {}) ⇒ Object
- #default_script(lang) ⇒ Object
- #dl_to_attrs(elem, dlist, name) ⇒ Object
- #dl_to_elems(ins, elem, dlist, name) ⇒ Object
- #document_ns_attributes(_doc) ⇒ Object
- #isodoc(lang, script, i18nyaml = nil) ⇒ Object
-
#noko(&block) ⇒ Object
block for processing XML document fragments as XHTML, to allow for HTMLentities Unescape special chars used in Asciidoctor substitution processing.
- #term_expr(elem) ⇒ Object
-
#wrap_in_para(node, out) ⇒ Object
if the contents of node are blocks, output them to out; else, wrap them in <p>.
Instance Method Details
#attr_code(attributes) ⇒ Object
42 43 44 45 46 |
# File 'lib/asciidoctor/standoc/utils.rb', line 42 def attr_code(attributes) attributes.compact.transform_values do |v| v.is_a?(String) ? HTMLEntities.new.decode(v) : v end end |
#convert(node, transform = nil, opts = {}) ⇒ Object
11 12 13 14 |
# File 'lib/asciidoctor/standoc/utils.rb', line 11 def convert(node, transform = nil, opts = {}) transform ||= node.node_name opts.empty? ? (send transform, node) : (send transform, node, opts) end |
#default_script(lang) ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/asciidoctor/standoc/utils.rb', line 67 def default_script(lang) case lang when "ar", "fa" then "Arab" when "ur" then "Aran" when "ru", "bg" then "Cyrl" when "hi" then "Deva" when "el" then "Grek" when "zh" then "Hans" when "ko" then "Kore" when "he" then "Hebr" when "ja" then "Jpan" else "Latn" end end |
#dl_to_attrs(elem, dlist, name) ⇒ Object
83 84 85 86 87 |
# File 'lib/asciidoctor/standoc/utils.rb', line 83 def dl_to_attrs(elem, dlist, name) e = dlist.at("./dt[text()='#{name}']") or return val = e.at("./following::dd/p") || e.at("./following::dd") or return elem[name] = val.text end |
#dl_to_elems(ins, elem, dlist, name) ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/asciidoctor/standoc/utils.rb', line 89 def dl_to_elems(ins, elem, dlist, name) a = elem.at("./#{name}[last()]") ins = a if a dlist.xpath("./dt[text()='#{name}']").each do |e| v = e.at("./following::dd") e = v.elements and e.size == 1 && e.first.name == "p" and v = e.first v.name = name ins.next = v ins = ins.next end ins end |
#document_ns_attributes(_doc) ⇒ Object
16 17 18 |
# File 'lib/asciidoctor/standoc/utils.rb', line 16 def document_ns_attributes(_doc) nil end |
#isodoc(lang, script, i18nyaml = nil) ⇒ Object
60 61 62 63 64 65 |
# File 'lib/asciidoctor/standoc/utils.rb', line 60 def isodoc(lang, script, i18nyaml = nil) conv = html_converter(EmptyAttr.new) i18n = conv.i18n_init(lang, script, i18nyaml) conv.(lang, script, i18n) conv end |
#noko(&block) ⇒ Object
block for processing XML document fragments as XHTML, to allow for HTMLentities Unescape special chars used in Asciidoctor substitution processing
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/asciidoctor/standoc/utils.rb', line 31 def noko(&block) doc = ::Nokogiri::XML.parse(NOKOHEAD) fragment = doc.fragment("") ::Nokogiri::XML::Builder.with fragment, &block fragment.to_xml(encoding: "US-ASCII", indent: 0).lines.map do |l| l.gsub(/>\n$/, ">").gsub(/\s*\n$/m, " ").gsub("–", "\u0096") .gsub("—", "\u0097").gsub("–", "\u0096") .gsub("—", "\u0097") end end |
#term_expr(elem) ⇒ Object
102 103 104 |
# File 'lib/asciidoctor/standoc/utils.rb', line 102 def term_expr(elem) "<expression><name>#{elem}</name></expression>" end |
#wrap_in_para(node, out) ⇒ Object
if the contents of node are blocks, output them to out; else, wrap them in <p>
50 51 52 53 54 55 |
# File 'lib/asciidoctor/standoc/utils.rb', line 50 def wrap_in_para(node, out) if node.blocks? then out << node.content else out.p { |p| p << node.content } end end |