From 6ed3edfa7775ae724bc4f910bb2454248ea95f9f Mon Sep 17 00:00:00 2001 From: Pepijn Van Eeckhoudt Date: Sat, 17 May 2014 21:54:56 +0200 Subject: Add asciimath to mathml converter to support asciimath in docbook converter --- asciidoctor.gemspec | 2 ++ lib/asciidoctor/converter/docbook5.rb | 6 ++++-- test/blocks_test.rb | 8 +++----- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/asciidoctor.gemspec b/asciidoctor.gemspec index 576f2bb3..be5a8922 100644 --- a/asciidoctor.gemspec +++ b/asciidoctor.gemspec @@ -30,9 +30,11 @@ A fast, open source text processor and publishing toolchain, written in Ruby, fo #s.extra_rdoc_files = %w(CHANGELOG.adoc LICENSE.adoc README.adoc) s.extra_rdoc_files = %w(LICENSE.adoc) + # asciimath is needed for testing AsciiMath in DocBook backend # erubis is needed for testing use of alternative eRuby impls # tilt, slim and haml are needed for testing custom templates # coderay is needed for testing syntax highlighting + s.add_development_dependency 'asciimath', '~> 1.0.1' s.add_development_dependency 'coderay', '~> 1.1.0' s.add_development_dependency 'cucumber', '~> 1.3.1' s.add_development_dependency 'erubis', '~> 2.7.0' diff --git a/lib/asciidoctor/converter/docbook5.rb b/lib/asciidoctor/converter/docbook5.rb index ab2ceee6..6c487207 100644 --- a/lib/asciidoctor/converter/docbook5.rb +++ b/lib/asciidoctor/converter/docbook5.rb @@ -256,9 +256,11 @@ module Asciidoctor if node.style == 'latexmath' equation_data = %( ) - # asciimath + elsif node.style == 'asciimath' && (!(defined? @asciimath_loaded) ? + (@asciimath_loaded = Helpers.require_library 'asciimath', true, :warn) : @asciimath_loaded) + equation_data = ::AsciiMath.parse(equation).to_mathml 'mml:', 'xmlns:mml' => 'http://www.w3.org/1998/Math/MathML' else - # DocBook backends can't handle AsciiMath, so output raw expression in text object + # Unsupported math style, so output raw expression in text object equation_data = %() end if node.title? diff --git a/test/blocks_test.rb b/test/blocks_test.rb index 6b5b8179..5d6f3a7d 100644 --- a/test/blocks_test.rb +++ b/test/blocks_test.rb @@ -1285,11 +1285,9 @@ x+b/(2a)<+-sqrt((b^2)/(4a^2)-c/a) ++++ EOS - expect = <<-'EOS' - - - - EOS + expect = %( +x+b2a<±b24a2ca +) output = render_embedded_string input, :backend => :docbook assert_equal expect.strip, output.strip -- cgit v1.2.3