Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Léo-Paul Géneau
gitlab-ce
Commits
e46f2c53
Commit
e46f2c53
authored
Dec 22, 2016
by
Douwe Maan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Don't render inline math when dollar signs are inside markup
parent
6d9c1d3e
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
10 additions
and
8 deletions
+10
-8
lib/banzai/filter/math_filter.rb
lib/banzai/filter/math_filter.rb
+3
-8
spec/lib/banzai/filter/math_filter_spec.rb
spec/lib/banzai/filter/math_filter_spec.rb
+7
-0
No files found.
lib/banzai/filter/math_filter.rb
View file @
e46f2c53
...
...
@@ -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
...
...
spec/lib/banzai/filter/math_filter_spec.rb
View file @
e46f2c53
...
...
@@ -79,6 +79,13 @@ describe Banzai::Filter::MathFilter, lib: true do
expect
(
doc
.
to_s
).
to
eq
input
end
it
'ignores dollar signs if they are inside another element'
do
input
=
'<p>We check strictly <em>$</em><code>2+2</code><em>$</em></p>'
doc
=
filter
(
input
)
expect
(
doc
.
to_s
).
to
eq
input
end
# Display math
it
'adds data-math-style display attribute to display math'
do
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment