Module: Asciidoctor::Standoc::Inline
- Included in:
- Converter
- Defined in:
- lib/asciidoctor/standoc/inline.rb
Instance Method Summary collapse
- #inline_anchor(node) ⇒ Object
- #inline_anchor_bibref(node) ⇒ Object
- #inline_anchor_link(node) ⇒ Object
- #inline_anchor_ref(node) ⇒ Object
- #inline_anchor_xref(node) ⇒ Object
- #inline_break(node) ⇒ Object
- #inline_callout(node) ⇒ Object
- #inline_footnote(node) ⇒ Object
- #inline_quoted(node) ⇒ Object
- #page_break(_node) ⇒ Object
- #refid?(x) ⇒ Boolean
- #stem_parse(text, xml) ⇒ Object
- #thematic_break(_node) ⇒ Object
Instance Method Details
#inline_anchor(node) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/asciidoctor/standoc/inline.rb', line 11 def inline_anchor(node) case node.type when :ref inline_anchor_ref node when :xref inline_anchor_xref node when :link inline_anchor_link node when :bibref inline_anchor_bibref node end end |
#inline_anchor_bibref(node) ⇒ Object
53 54 55 56 57 58 59 60 61 62 |
# File 'lib/asciidoctor/standoc/inline.rb', line 53 def inline_anchor_bibref(node) eref_contents = node.target == node.text ? nil : node.text eref_attributes = { id: node.target } @refids << node.target noko do |xml| xml.ref **attr_code(eref_attributes) do |r| r << eref_contents end end.join end |
#inline_anchor_link(node) ⇒ Object
42 43 44 45 46 47 48 49 50 51 |
# File 'lib/asciidoctor/standoc/inline.rb', line 42 def inline_anchor_link(node) contents = node.text contents = "" if node.target.gsub(%r{^mailto:}, "") == node.text attributes = { "target": node.target } noko do |xml| xml.link **attr_code(attributes) do |l| l << contents end end.join end |
#inline_anchor_ref(node) ⇒ Object
24 25 26 27 28 |
# File 'lib/asciidoctor/standoc/inline.rb', line 24 def inline_anchor_ref(node) noko do |xml| xml.bookmark nil, **attr_code(id: node.id) end.join end |
#inline_anchor_xref(node) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/asciidoctor/standoc/inline.rb', line 30 def inline_anchor_xref(node) matched = /^fn(:\s*(?<text>.*))?$/.match node.text f = matched.nil? ? "inline" : "footnote" c = matched.nil? ? node.text : matched[:text] t = node.target.gsub(/^#/, "").gsub(%r{(\.xml|\.adoc)(#.*$)}, "\\2") noko do |xml| xml.xref **attr_code(target: t, type: f) do |x| x << c end end.join end |
#inline_break(node) ⇒ Object
80 81 82 83 84 85 |
# File 'lib/asciidoctor/standoc/inline.rb', line 80 def inline_break(node) noko do |xml| xml << node.text xml.br end.join("\n") end |
#inline_callout(node) ⇒ Object
64 65 66 67 68 |
# File 'lib/asciidoctor/standoc/inline.rb', line 64 def inline_callout(node) noko do |xml| xml.callout node.text end.join end |
#inline_footnote(node) ⇒ Object
70 71 72 73 74 75 76 77 78 |
# File 'lib/asciidoctor/standoc/inline.rb', line 70 def inline_footnote(node) @fn_number ||= 0 noko do |xml| @fn_number += 1 xml.fn **{ reference: @fn_number } do |fn| fn.p { |p| p << node.text } end end.join("\n") end |
#inline_quoted(node) ⇒ Object
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/asciidoctor/standoc/inline.rb', line 107 def inline_quoted(node) noko do |xml| case node.type when :emphasis then xml.em node.text when :strong then xml.strong node.text when :monospaced then xml.tt node.text when :double then xml << "\"#{node.text}\"" when :single then xml << "'#{node.text}'" when :superscript then xml.sup node.text when :subscript then xml.sub node.text when :asciimath then stem_parse(node.text, xml) else case node.role # the following three are legacy, they are now handled by macros when "alt" then xml.admitted { |a| a << node.text } when "deprecated" then xml.deprecates { |a| a << node.text } when "domain" then xml.domain { |a| a << node.text } when "strike" then xml.strike node.text when "smallcap" then xml.smallcap node.text when "keyword" then xml.keyword node.text else xml << node.text end end end.join end |
#page_break(_node) ⇒ Object
87 88 89 |
# File 'lib/asciidoctor/standoc/inline.rb', line 87 def page_break(_node) noko { |xml| xml.pagebreak }.join("\n") end |
#refid?(x) ⇒ Boolean
7 8 9 |
# File 'lib/asciidoctor/standoc/inline.rb', line 7 def refid?(x) @refids.include? x end |
#stem_parse(text, xml) ⇒ Object
95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/asciidoctor/standoc/inline.rb', line 95 def stem_parse(text, xml) if /<([^:>&]+:)?math(\s+[^>&]+)?> | <([^:>&]+:)?math(\s+[^>&]+)?>/x.match text math = HTMLEntities.new.encode(text, :basic, :hexadecimal). gsub(/&gt;/, ">").gsub(/\&lt;/, "<").gsub(/&amp;/, "&"). gsub(/>/, ">").gsub(/</, "<").gsub(/&/, "&") xml.stem math, **{ type: "MathML" } else xml.stem text, **{ type: "AsciiMath" } end end |
#thematic_break(_node) ⇒ Object
91 92 93 |
# File 'lib/asciidoctor/standoc/inline.rb', line 91 def thematic_break(_node) noko { |xml| xml.hr }.join("\n") end |