Method: MathematicalTreeprocessor#handle_inline_stem

Defined in:
lib/asciidoctor-mathematical/extension.rb

#handle_inline_stem(node, text, mathematical, image_output_dir, image_target_dir, format, inline) ⇒ Object



112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# File 'lib/asciidoctor-mathematical/extension.rb', line 112

def handle_inline_stem(node, text, mathematical, image_output_dir, image_target_dir, format, inline)
  document = node.document
  source_modified = false

  return [text, source_modified] unless document.attr? 'stem'

  to_html = document.basebackend? 'html'

  default_equation_type = document.attr('stem').include?('tex') ? :latexmath : :asciimath

  # TODO skip passthroughs in the source (e.g., +stem:[x^2]+)
  if text && text.include?(':') && (text.include?('stem:') || text.include?('math:'))
    text = text.gsub(StemInlineMacroRx) do
      if (m = $~)[0].start_with? '\\'
        next m[0][1..-1]
      end

      next '' if (eq_data = m[3].rstrip).empty?

      equation_type = default_equation_type if (equation_type = m[1].to_sym) == :stem
      if equation_type == :asciimath
        eq_data = AsciiMath.parse(eq_data).to_latex
      else # :latexmath
        eq_data = eq_data.gsub('\]', ']')
        subs = m[2].nil_or_empty? ? (to_html ? [:specialcharacters] : []) : (node.resolve_pass_subs m[2])
        eq_data = node.apply_subs eq_data, subs unless subs.empty?
      end

      source_modified = true
      img_target, img_width, img_height = make_equ_image eq_data, nil, true, mathematical, image_output_dir, image_target_dir, format, inline
      if inline
        %(pass:[<span class="steminline">#{img_target}</span>])
      else
        %(image:#{img_target}[width=#{img_width},height=#{img_height}])
      end
    end
  end

  [text, source_modified]
end