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
b27b8dc0
Commit
b27b8dc0
authored
Apr 11, 2019
by
Willian Balmant
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use strip to remove leading/trailing spaces
Change based on comments in MR #27025
parent
2075ef7d
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
2 additions
and
3 deletions
+2
-3
lib/banzai/filter/table_of_contents_filter.rb
lib/banzai/filter/table_of_contents_filter.rb
+1
-2
spec/lib/banzai/filter/table_of_contents_filter_spec.rb
spec/lib/banzai/filter/table_of_contents_filter_spec.rb
+1
-1
No files found.
lib/banzai/filter/table_of_contents_filter.rb
View file @
b27b8dc0
...
@@ -18,7 +18,6 @@ module Banzai
...
@@ -18,7 +18,6 @@ module Banzai
# `li` child elements.
# `li` child elements.
class
TableOfContentsFilter
<
HTML
::
Pipeline
::
Filter
class
TableOfContentsFilter
<
HTML
::
Pipeline
::
Filter
PUNCTUATION_REGEXP
=
/[^\p{Word}\- ]/u
.
freeze
PUNCTUATION_REGEXP
=
/[^\p{Word}\- ]/u
.
freeze
LEADING_OR_TRAILING_SPACE_REGEXP
=
/^\p{Space}+|\p{Space}+$/
.
freeze
def
call
def
call
return
doc
if
context
[
:no_header_anchors
]
return
doc
if
context
[
:no_header_anchors
]
...
@@ -32,7 +31,7 @@ module Banzai
...
@@ -32,7 +31,7 @@ module Banzai
if
header_content
=
node
.
children
.
first
if
header_content
=
node
.
children
.
first
id
=
node
id
=
node
.
text
.
text
.
gsub
(
LEADING_OR_TRAILING_SPACE_REGEXP
,
''
)
# remove leading and trailing spaces
.
strip
.
downcase
.
downcase
.
gsub
(
PUNCTUATION_REGEXP
,
''
)
# remove punctuation
.
gsub
(
PUNCTUATION_REGEXP
,
''
)
# remove punctuation
.
tr
(
' '
,
'-'
)
# replace spaces with dash
.
tr
(
' '
,
'-'
)
# replace spaces with dash
...
...
spec/lib/banzai/filter/table_of_contents_filter_spec.rb
View file @
b27b8dc0
...
@@ -59,7 +59,7 @@ describe Banzai::Filter::TableOfContentsFilter do
...
@@ -59,7 +59,7 @@ describe Banzai::Filter::TableOfContentsFilter do
end
end
it
'removes any leading or trailing spaces'
do
it
'removes any leading or trailing spaces'
do
doc
=
filter
(
header
(
1
,
"
\r\n
\t
Title with spaces
\r\n\t
"
))
doc
=
filter
(
header
(
1
,
"
\r\n
\t
Title with spaces
\r\n\t
"
))
expect
(
doc
.
css
(
'h1 a'
).
first
.
attr
(
'href'
)).
to
eq
'#title-with-spaces'
expect
(
doc
.
css
(
'h1 a'
).
first
.
attr
(
'href'
)).
to
eq
'#title-with-spaces'
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