lib/html2doc/math.rb in html2doc-1.5.5 vs lib/html2doc/math.rb in html2doc-1.6.0
- old
+ new
@@ -3,32 +3,9 @@
require "htmlentities"
require "nokogiri"
require "plane1converter"
class Html2Doc
- def asciimath_to_mathml1(expr, retain_asciimath)
- ret = Plurimath::Math.parse(HTMLEntities.new.decode(expr), "asciimath").to_mathml
- .gsub(/<math>/, "<math xmlns='http://www.w3.org/1998/Math/MathML'>").strip
- retain_asciimath and
- ret += "<asciimath>#{@c.encode(@c.decode(expr), :basic)}</asciimath>"
- ret
- rescue StandardError => e
- puts "parsing: #{expr}"
- puts e.message
- raise e
- end
-
- def asciimath_to_mathml(doc, delims, retain_asciimath: false)
- return doc if delims.nil? || delims.size < 2
-
- m = doc.split(/(#{Regexp.escape(delims[0])}|#{Regexp.escape(delims[1])})/)
- m.each_slice(4).map.with_index do |(*a), i|
- progress_conv(i, 500, (m.size / 4).floor, 1000, "AsciiMath")
- a[2].nil? or a[2] = asciimath_to_mathml1(a[2], retain_asciimath)
- a.size > 1 ? a[0] + a[2] : a[0]
- end.join
- end
-
def progress_conv(idx, step, total, threshold, msg)
return unless (idx % step).zero? && total > threshold && idx.positive?
warn "#{msg} #{idx} of #{total}"
end