summaryrefslogtreecommitdiff
path: root/lib/banzai
diff options
context:
space:
mode:
authorRobert Speicher <robert@gitlab.com>2016-12-22 14:23:37 +0000
committerRobert Speicher <robert@gitlab.com>2016-12-22 14:23:37 +0000
commit7e26afe6e8cb0f7b2b93968cb77ad06cf1631ee5 (patch)
treec974a1a66e751ea5c2f497ebeb9101956246a653 /lib/banzai
parentdeb3cd7153f6ad5ee9ec14c1d360102d8d6102c3 (diff)
parente46f2c53a282367581c5e4cb611a60dc20a59133 (diff)
downloadgitlab-ce-7e26afe6e8cb0f7b2b93968cb77ad06cf1631ee5.tar.gz
Merge branch 'inline-math-dollar' into 'master'
Don't render inline math when dollar signs are inside markup See merge request !8259
Diffstat (limited to 'lib/banzai')
-rw-r--r--lib/banzai/filter/math_filter.rb11
1 files changed, 3 insertions, 8 deletions
diff --git a/lib/banzai/filter/math_filter.rb b/lib/banzai/filter/math_filter.rb
index cb037f89337..b6e784c886b 100644
--- a/lib/banzai/filter/math_filter.rb
+++ b/lib/banzai/filter/math_filter.rb
@@ -5,12 +5,6 @@ module Banzai
# HTML filter that adds class="code math" and removes the dollar sign in $`2+2`$.
#
class MathFilter < HTML::Pipeline::Filter
- # This picks out <code>...</code>.
- INLINE_MATH = 'descendant-or-self::code'.freeze
-
- # Pick out a code block which is declared math
- DISPLAY_MATH = "descendant-or-self::pre[contains(@class, 'math') and contains(@class, 'code')]".freeze
-
# Attribute indicating inline or display math.
STYLE_ATTRIBUTE = 'data-math-style'.freeze
@@ -22,13 +16,14 @@ module Banzai
DOLLAR_SIGN = '$'.freeze
def call
- doc.xpath(INLINE_MATH).each do |code|
+ doc.css('code').each do |code|
closing = code.next
opening = code.previous
# We need a sibling before and after.
# They should end and start with $ respectively.
if closing && opening &&
+ closing.text? && opening.text? &&
closing.content.first == DOLLAR_SIGN &&
opening.content.last == DOLLAR_SIGN
@@ -39,7 +34,7 @@ module Banzai
end
end
- doc.xpath(DISPLAY_MATH).each do |el|
+ doc.css('pre.code.math').each do |el|
el[STYLE_ATTRIBUTE] = 'display'
el[:class] += " #{TAG_CLASS}"
end