diff --git a/lib/docs/filters/core/math.rb b/lib/docs/filters/core/math.rb index e7d3b03b15..5aff68a72d 100644 --- a/lib/docs/filters/core/math.rb +++ b/lib/docs/filters/core/math.rb @@ -4,15 +4,20 @@ module Docs # Replaces Sphinx/MathJax math markup with native MathML, rendered at # scrape time by MathRenderer (KaTeX): # \(...\) and
\[...\]
+ # Display environments such as align* are emitted without delimiters. class MathFilter < Filter TEX_DELIMITERS_RGX = /\\\((.*?)\\\)|\\\[(.*?)\\\]/m + TEX_ENVIRONMENT_RGX = /\A\s*\\begin\{(\w+\*?)\}.*\\end\{\1\}\s*\z/m def call items = css('span.math', 'div.math').filter_map do |node| node.css('.eqno').remove content = node.content - next unless content =~ TEX_DELIMITERS_RGX - [node, split(content)] + if content =~ TEX_DELIMITERS_RGX + [node, split(content)] + elsif content =~ TEX_ENVIRONMENT_RGX + [node, [[content.strip, true]]] + end end render(items) doc diff --git a/test/lib/docs/filters/core/math_test.rb b/test/lib/docs/filters/core/math_test.rb index d5b1f6d086..f790aef51a 100644 --- a/test/lib/docs/filters/core/math_test.rb +++ b/test/lib/docs/filters/core/math_test.rb @@ -52,6 +52,14 @@ def tex_of(node) assert_match %r{\Asee and \z}, filter_output_string end + it "renders a bare environment as display math" do + @body = %(
\n\\begin{align*} a &= b \\\\ c &= d \\end{align*}
) + assert_equal 1, math_nodes.length + assert_equal 'block', math_nodes.first['display'] + assert_equal '\begin{align*} a &= b \\\\ c &= d \end{align*}', tex_of(math_nodes.first) + assert_includes math_nodes.first.to_s, '