Module: Asciidoctor::Standoc::Utils
- Included in:
- Converter
- Defined in:
- lib/asciidoctor/standoc/utils.rb
Defined Under Namespace
Classes: EmptyAttr
Constant Summary collapse
- NOKOHEAD =
<<~HERE.freeze <!DOCTYPE html SYSTEM "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title></title> <meta charset="UTF-8" /> </head> <body> </body> </html> HERE
- SUBCLAUSE_XPATH =
"//clause[not(parent::sections)]"\ "[not(ancestor::boilerplate)]".freeze
Instance Method Summary collapse
- #attr_code(attributes) ⇒ Object
- #convert(node, transform = nil, opts = {}) ⇒ Object
- #datauri2mime(uri) ⇒ Object
- #datauri2mime1(file, imgdata) ⇒ 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.
-
#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
44 45 46 47 48 49 |
# File 'lib/asciidoctor/standoc/utils.rb', line 44 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 = {}) ⇒ Object
13 14 15 16 |
# File 'lib/asciidoctor/standoc/utils.rb', line 13 def convert(node, transform = nil, opts = {}) transform ||= node.node_name opts.empty? ? (send transform, node) : (send transform, node, opts) end |
#datauri2mime(uri) ⇒ Object
60 61 62 63 64 65 66 67 68 |
# File 'lib/asciidoctor/standoc/utils.rb', line 60 def datauri2mime(uri) %r{^data:image/(?<imgtype>[^;]+);base64,(?<imgdata>.+)$} =~ uri type = nil imgtype = "png" unless /^[a-z0-9]+$/.match imgtype Tempfile.open(["imageuri", ".#{imgtype}"]) do |file| type = datauri2mime1(file, imgdata) end [type] end |
#datauri2mime1(file, imgdata) ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/asciidoctor/standoc/utils.rb', line 70 def datauri2mime1(file, imgdata) type = nil begin file.binmode file.write(Base64.strict_decode64(imgdata)) file.rewind type = MimeMagic.by_magic(file) ensure file.close! end type end |
#document_ns_attributes(_doc) ⇒ Object
18 19 20 |
# File 'lib/asciidoctor/standoc/utils.rb', line 18 def document_ns_attributes(_doc) nil end |
#isodoc(lang, script, i18nyaml = nil) ⇒ Object
86 87 88 89 90 91 |
# File 'lib/asciidoctor/standoc/utils.rb', line 86 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
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/asciidoctor/standoc/utils.rb', line 33 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) ⇒ Object
if the contents of node are blocks, output them to out; else, wrap them in <p>
53 54 55 56 57 58 |
# File 'lib/asciidoctor/standoc/utils.rb', line 53 def wrap_in_para(node, out) if node.blocks? then out << node.content else out.p { |p| p << node.content } end end |