module Asciidoctor::Standoc::Utils

Constants

NOKOHEAD
SUBCLAUSE_XPATH

Public Instance Methods

attr_code(attributes) click to toggle source
# File lib/asciidoctor/standoc/utils.rb, line 42
def attr_code(attributes)
  attributes = attributes.reject { |_, val| val.nil? }.map
  attributes.map do |k, v|
    [k, (v.is_a? String) ? HTMLEntities.new.decode(v) : v]
  end.to_h
end
convert(node, transform = nil, opts = {}) click to toggle source
# 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) click to toggle source
# File lib/asciidoctor/standoc/utils.rb, line 68
def default_script(lang)
  case lang
  when "ar", "fa"
    "Arab"
  when "ur"
    "Aran"
  when "ru", "bg"
    "Cyrl"
  when "hi"
    "Deva"
  when "el"
    "Grek"
  when "zh"
    "Hans"
  when "ko"
    "Kore"
  when "he"
    "Hebr"
  when "ja"
    "Jpan"
  else
    "Latn"
  end
end
document_ns_attributes(_doc) click to toggle source
# File lib/asciidoctor/standoc/utils.rb, line 16
def document_ns_attributes(_doc)
  nil
end
isodoc(lang, script, i18nyaml = nil) click to toggle source
# File lib/asciidoctor/standoc/utils.rb, line 61
def isodoc(lang, script, i18nyaml = nil)
  conv = html_converter(EmptyAttr.new)
  i18n = conv.i18n_init(lang, script, i18nyaml)
  conv.metadata_init(lang, script, i18n)
  conv
end
noko(&block) click to toggle source

block for processing XML document fragments as XHTML, to allow for HTMLentities Unescape special chars used in Asciidoctor substitution processing

# 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
wrap_in_para(node, out) click to toggle source

if the contents of node are blocks, output them to out; else, wrap them in <p>

# File lib/asciidoctor/standoc/utils.rb, line 51
def wrap_in_para(node, out)
  if node.blocks? then out << node.content
  else
    out.p { |p| p << node.content }
  end
end