lib/asciidoctor/iso/blocks.rb in asciidoctor-iso-0.6.1 vs lib/asciidoctor/iso/blocks.rb in asciidoctor-iso-0.7.0

- old
+ new

@@ -2,57 +2,55 @@ require "uri" module Asciidoctor module ISO module Blocks - def id_attr(node = nil) { id: Utils::anchor_or_uuid(node) } end + # open block is a container of multiple blocks, + # treated as a single block. + # We append each contained block to its parent def open(node) - # open block is a container of multiple blocks, - # treated as a single block. - # We append each contained block to its parent result = [] - if node.blocks? - node.blocks.each do |b| - result << send(b.context, b) - end - else - result = paragraph(node) + node.blocks.each do |b| + result << send(b.context, b) end result end + def literal(node) + open(node) + end + + # NOTE: html escaping is performed by Nokogiri def stem(node) - # NOTE: html escaping is performed by Nokogiri stem_content = node.lines.join("\n") noko do |xml| xml.formula **id_attr(node) do |s| s.stem stem_content, **{ type: "AsciiMath" } style(node, stem_content) end end end def sidebar_attrs(node) - date = node.attr("date") || DateTime.now.iso8601.gsub(/\+.*$/, "") + date = node.attr("date") || Date.today.iso8601.gsub(/\+.*$/, "") date += "T0000" unless /T/.match? date - { + { reviewer: node.attr("reviewer") || node.attr("source") || "(Unknown)", id: Utils::anchor_or_uuid(node), date: date.gsub(/[:-]/, ""), from: node.attr("from"), to: node.attr("to") || node.attr("from"), } end def sidebar(node) - return unless is_draft - content = Utils::flatten_rawtext(node.content).join("\n") - noko do |xml| + return unless draft? + noko do |xml| xml.review **attr_code(sidebar_attrs(node)) do |r| wrap_in_para(node, r) end end end @@ -76,13 +74,14 @@ end.join("\n") end def admonition_attrs(node) name = node.attr("name") - type = node.attr("type") and + if type = node.attr("type") ["danger", "safety precautions"].each do |t| - name = t if type.casecmp(t).zero? + name = t if type.casecmp(t).zero? + end end { id: Utils::anchor_or_uuid(node), type: name } end def admonition(node) @@ -110,10 +109,12 @@ return term_example(node) if in_terms noko do |xml| xml.example **id_attr(node) do |ex| content = node.content ex << content + text = Utils::flatten_rawtext(content).join("\n") + termexample_style(node, text) end end.join("\n") end def preamble(node) @@ -129,21 +130,29 @@ end def image_attributes(node) uri = node.image_uri node.attr("target") types = MIME::Types.type_for(uri) - { src: uri, + { src: uri, id: Utils::anchor_or_uuid, imagetype: types.first.sub_type.upcase, height: node.attr("height"), width: node.attr("width") } end + def figure_title(node, f) + if node.title.nil? + style_warning(node, "Figure should have title", nil) + else + f.name { |name| name << node.title } + end + end + def image(node) noko do |xml| xml.figure **id_attr(node) do |f| - f.name { |name| name << node.title } unless node.title.nil? + figure_title(node, f) f.image **attr_code(image_attributes(node)) end end end @@ -163,12 +172,12 @@ { id: Utils::anchor_or_uuid(node), align: node.attr("align") } end def quote_attribution(node, out) if node.attr("citetitle") - m = /^(?<cite>[^,]+)(,(?<text>.*$))?$/.match node.attr("citetitle") - out.source m[:text], + m = /^(?<cite>[^,]+)(,(?<text>.*$))?$/m.match node.attr("citetitle") + out.source m[:text], **attr_code(target: m[:cite], type: "inline") end if node.attr("attribution") out.author { |a| a << node.attr("attribution") } end @@ -184,20 +193,11 @@ end def listing(node) # NOTE: html escaping is performed by Nokogiri noko do |xml| - if node.parent.context != :example - xml.example **id_attr(node) do |e| - e.sourcecode **id_attr(node) do |s| - s << node.content - end - end - else - xml.sourcecode **id_attr(node) do |s| - s << node.content - end - end + xml.sourcecode(**id_attr(node)) { |s| s << node.content } + # xml.sourcecode(**id_attr(node)) { |s| s << node.lines.join("\n") } end end end end end