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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
cc036417
Commit
cc036417
authored
Jan 10, 2019
by
Brett Walker
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Updates based on review comments
parent
459d6f98
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
16 additions
and
9 deletions
+16
-9
lib/banzai/filter/footnote_filter.rb
lib/banzai/filter/footnote_filter.rb
+7
-7
lib/banzai/filter/sanitization_filter.rb
lib/banzai/filter/sanitization_filter.rb
+2
-2
spec/lib/banzai/filter/sanitization_filter_spec.rb
spec/lib/banzai/filter/sanitization_filter_spec.rb
+7
-0
No files found.
lib/banzai/filter/footnote_filter.rb
View file @
cc036417
...
...
@@ -16,25 +16,25 @@ module Banzai
# can be used for a single render). So you get `id=fn1-4335` and `id=fn2-4335`.
#
class
FootnoteFilter
<
HTML
::
Pipeline
::
Filter
INTEGER_PATTERN
=
/\A\d+\
Z
/
.
freeze
INTEGER_PATTERN
=
/\A\d+\
z
/
.
freeze
def
call
return
doc
unless
first_footnote
=
doc
.
at_css
(
'ol > li[id=fn1]'
)
# Sanitization stripped off the section wrapper - add it back in
first_footnote
.
parent
.
wrap
(
'<section class="footnotes">'
)
rand_suffix
=
"-
#{
random_number
}
"
doc
.
css
(
'sup > a[id]'
).
each
do
|
link_node
|
ref_num
=
link_node
[
:id
].
delete_prefix
(
'fnref'
)
footnote_node
=
doc
.
at_css
(
"li[id=fn
#{
ref_num
}
]"
)
backref_node
=
doc
.
at_css
(
"li[id=fn
#{
ref_num
}
]
a[href=
\"
#fnref
#{
ref_num
}
\"
]"
)
backref_node
=
footnote_node
.
at_css
(
"
a[href=
\"
#fnref
#{
ref_num
}
\"
]"
)
if
ref_num
=~
INTEGER_PATTERN
&&
footnote_node
&&
backref_node
rand_ref_num
=
"
#{
ref_num
}
-
#{
random_number
}
"
link_node
[
:href
]
=
"#fn
#{
rand_ref_num
}
"
link_node
[
:id
]
=
"fnref
#{
rand_ref_num
}
"
footnote_node
[
:id
]
=
"fn
#{
rand_ref_num
}
"
backref_node
[
:href
]
=
"#fnref
#{
rand_ref_num
}
"
link_node
[
:href
]
+=
rand_suffix
link_node
[
:id
]
+=
rand_suffix
footnote_node
[
:id
]
+=
rand_suffix
backref_node
[
:href
]
+=
rand_suffix
# Sanitization stripped off class - add it back in
link_node
.
parent
.
append_class
(
'footnote-ref'
)
...
...
lib/banzai/filter/sanitization_filter.rb
View file @
cc036417
...
...
@@ -10,8 +10,8 @@ module Banzai
UNSAFE_PROTOCOLS
=
%w(data javascript vbscript)
.
freeze
TABLE_ALIGNMENT_PATTERN
=
/text-align: (?<alignment>center|left|right)/
.
freeze
FOOTNOTE_LINK_REFERENCE_PATTERN
=
/\Afnref\d\z/
.
freeze
FOOTNOTE_LI_REFERENCE_PATTERN
=
/\Afn\d\z/
.
freeze
FOOTNOTE_LINK_REFERENCE_PATTERN
=
/\Afnref\d
+
\z/
.
freeze
FOOTNOTE_LI_REFERENCE_PATTERN
=
/\Afn\d
+
\z/
.
freeze
def
whitelist
strong_memoize
(
:whitelist
)
do
...
...
spec/lib/banzai/filter/sanitization_filter_spec.rb
View file @
cc036417
...
...
@@ -335,6 +335,13 @@ describe Banzai::Filter::SanitizationFilter do
expect
(
act
.
to_html
).
to
eq
exp
end
end
it
'allows footnotes numbered higher than 9'
do
exp
=
%q{<a href="#fn15" id="fnref15">link</a><ol><li id="fn15">footnote</li></ol>}
act
=
filter
(
exp
)
expect
(
act
.
to_html
).
to
eq
exp
end
end
end
end
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