Module: Asciidoctor::Standoc::Blocks
- Included in:
- Converter
- Defined in:
- lib/asciidoctor/standoc/blocks.rb
Instance Method Summary collapse
- #admonition(node) ⇒ Object
- #admonition_attrs(node) ⇒ Object
- #datauri(uri) ⇒ Object
- #example(node) ⇒ Object
- #figure_title(node, f) ⇒ Object
- #id_attr(node = nil) ⇒ Object
- #image(node) ⇒ Object
- #image_attributes(node) ⇒ Object
- #listing(node) ⇒ Object
- #literal(node) ⇒ Object
- #note(n) ⇒ Object
-
#open(node) ⇒ Object
open block is a container of multiple blocks, treated as a single block.
- #paragraph(node) ⇒ Object
- #preamble(node) ⇒ Object
- #quote(node) ⇒ Object
- #quote_attribution(node, out) ⇒ Object
- #quote_attrs(node) ⇒ Object
- #sidebar(node) ⇒ Object
- #sidebar_attrs(node) ⇒ Object
-
#stem(node) ⇒ Object
NOTE: html escaping is performed by Nokogiri.
- #term_example(node) ⇒ Object
- #termnote(n) ⇒ Object
Instance Method Details
#admonition(node) ⇒ Object
90 91 92 93 94 95 96 97 98 |
# File 'lib/asciidoctor/standoc/blocks.rb', line 90 def admonition(node) return termnote(node) if in_terms? return note(node) if node.attr("name") == "note" noko do |xml| xml.admonition **admonition_attrs(node) do |a| wrap_in_para(node, a) end end.join("\n") end |
#admonition_attrs(node) ⇒ Object
80 81 82 83 84 85 86 87 88 |
# File 'lib/asciidoctor/standoc/blocks.rb', line 80 def admonition_attrs(node) name = node.attr("name") if type = node.attr("type") ["danger", "safety precautions"].each do |t| name = t if type.casecmp(t).zero? end end { id: Utils::anchor_or_uuid(node), type: name } end |
#datauri(uri) ⇒ Object
127 128 129 130 131 132 133 |
# File 'lib/asciidoctor/standoc/blocks.rb', line 127 def datauri(uri) types = MIME::Types.type_for(@localdir + uri) type = types ? types.first.to_s : 'text/plain; charset="utf-8"' bin = File.read(@localdir + uri, encoding: "utf-8") data = Base64.strict_encode64(bin) "data:#{type};base64,#{data}" end |
#example(node) ⇒ Object
108 109 110 111 112 113 114 115 |
# File 'lib/asciidoctor/standoc/blocks.rb', line 108 def example(node) return term_example(node) if in_terms? noko do |xml| xml.example **id_attr(node) do |ex| wrap_in_para(node, ex) end end.join("\n") end |
#figure_title(node, f) ⇒ Object
145 146 147 148 149 |
# File 'lib/asciidoctor/standoc/blocks.rb', line 145 def figure_title(node, f) unless node.title.nil? f.name { |name| name << node.title } end end |
#id_attr(node = nil) ⇒ Object
9 10 11 |
# File 'lib/asciidoctor/standoc/blocks.rb', line 9 def id_attr(node = nil) { id: Utils::anchor_or_uuid(node) } end |
#image(node) ⇒ Object
151 152 153 154 155 156 157 158 |
# File 'lib/asciidoctor/standoc/blocks.rb', line 151 def image(node) noko do |xml| xml.figure **id_attr(node) do |f| figure_title(node, f) f.image **attr_code(image_attributes(node)) end end end |
#image_attributes(node) ⇒ Object
135 136 137 138 139 140 141 142 143 |
# File 'lib/asciidoctor/standoc/blocks.rb', line 135 def image_attributes(node) uri = node.image_uri node.attr("target") types = MIME::Types.type_for(uri) { src: @datauriimage ? datauri(uri) : uri, id: Utils::anchor_or_uuid, imagetype: types.first.sub_type.upcase, height: node.attr("height") || "auto", width: node.attr("width") || "auto" } end |
#listing(node) ⇒ Object
195 196 197 198 199 200 201 202 203 |
# File 'lib/asciidoctor/standoc/blocks.rb', line 195 def listing(node) # NOTE: html escaping is performed by Nokogiri noko do |xml| xml.sourcecode(**id_attr(node)) do |s| figure_title(node, s) s << node.content end end end |
#literal(node) ⇒ Object
24 25 26 27 28 29 30 31 |
# File 'lib/asciidoctor/standoc/blocks.rb', line 24 def literal(node) noko do |xml| xml.figure **id_attr(node) do |f| figure_title(node, f) f.pre node.lines.join("\n"), **{ id: Utils::anchor_or_uuid } end end end |
#note(n) ⇒ Object
72 73 74 75 76 77 78 |
# File 'lib/asciidoctor/standoc/blocks.rb', line 72 def note(n) noko do |xml| xml.note **id_attr(n) do |c| wrap_in_para(n, c) end end.join("\n") end |
#open(node) ⇒ Object
open block is a container of multiple blocks, treated as a single block. We append each contained block to its parent
16 17 18 19 20 21 22 |
# File 'lib/asciidoctor/standoc/blocks.rb', line 16 def open(node) result = [] node.blocks.each do |b| result << send(b.context, b) end result end |
#paragraph(node) ⇒ Object
160 161 162 163 164 165 166 167 168 169 |
# File 'lib/asciidoctor/standoc/blocks.rb', line 160 def paragraph(node) return termsource(node) if node.role == "source" attrs = { align: node.attr("align"), id: Utils::anchor_or_uuid(node) } noko do |xml| xml.p **attr_code(attrs) do |xml_t| xml_t << node.content end end.join("\n") end |
#preamble(node) ⇒ Object
117 118 119 120 121 122 123 124 125 |
# File 'lib/asciidoctor/standoc/blocks.rb', line 117 def preamble(node) noko do |xml| xml.foreword do |xml_abstract| xml_abstract.title { |t| t << "Foreword" } content = node.content xml_abstract << content end end.join("\n") end |
#quote(node) ⇒ Object
186 187 188 189 190 191 192 193 |
# File 'lib/asciidoctor/standoc/blocks.rb', line 186 def quote(node) noko do |xml| xml.quote **attr_code(quote_attrs(node)) do |q| quote_attribution(node, q) wrap_in_para(node, q) end end end |
#quote_attribution(node, out) ⇒ Object
175 176 177 178 179 180 181 182 183 184 |
# File 'lib/asciidoctor/standoc/blocks.rb', line 175 def quote_attribution(node, out) if node.attr("citetitle") 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. { |a| a << node.attr("attribution") } end end |
#quote_attrs(node) ⇒ Object
171 172 173 |
# File 'lib/asciidoctor/standoc/blocks.rb', line 171 def quote_attrs(node) { id: Utils::anchor_or_uuid(node), align: node.attr("align") } end |
#sidebar(node) ⇒ Object
55 56 57 58 59 60 61 62 |
# File 'lib/asciidoctor/standoc/blocks.rb', line 55 def (node) return unless draft? noko do |xml| xml.review **attr_code((node)) do |r| wrap_in_para(node, r) end end end |
#sidebar_attrs(node) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/asciidoctor/standoc/blocks.rb', line 43 def (node) date = node.attr("date") || Date.today.iso8601.gsub(/\+.*$/, "") date += "T00:00:00Z" unless /T/.match date { reviewer: node.attr("reviewer") || node.attr("source") || "(Unknown)", id: Utils::anchor_or_uuid(node), date: date, from: node.attr("from"), to: node.attr("to") || node.attr("from"), } end |
#stem(node) ⇒ Object
NOTE: html escaping is performed by Nokogiri
34 35 36 37 38 39 40 41 |
# File 'lib/asciidoctor/standoc/blocks.rb', line 34 def stem(node) stem_content = node.lines.join("\n") noko do |xml| xml.formula **id_attr(node) do |s| stem_parse(stem_content, s) end end end |
#term_example(node) ⇒ Object
100 101 102 103 104 105 106 |
# File 'lib/asciidoctor/standoc/blocks.rb', line 100 def term_example(node) noko do |xml| xml.termexample **id_attr(node) do |ex| wrap_in_para(node, ex) end end.join("\n") end |
#termnote(n) ⇒ Object
64 65 66 67 68 69 70 |
# File 'lib/asciidoctor/standoc/blocks.rb', line 64 def termnote(n) noko do |xml| xml.termnote **id_attr(n) do |ex| wrap_in_para(n, ex) end end.join("\n") end |