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
Boxiang Sun
gitlab-ce
Commits
2075ef7d
Commit
2075ef7d
authored
Apr 10, 2019
by
Willian Balmant
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
No leading/trailing spaces when generating heading ids (Fixes #57528)
Update based on comments in MR #27025
parent
b6ca523c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
7 additions
and
2 deletions
+7
-2
lib/banzai/filter/table_of_contents_filter.rb
lib/banzai/filter/table_of_contents_filter.rb
+2
-2
spec/lib/banzai/filter/table_of_contents_filter_spec.rb
spec/lib/banzai/filter/table_of_contents_filter_spec.rb
+5
-0
No files found.
lib/banzai/filter/table_of_contents_filter.rb
View file @
2075ef7d
...
...
@@ -17,8 +17,8 @@ module Banzai
# :toc - String containing Table of Contents data as a `ul` element with
# `li` child elements.
class
TableOfContentsFilter
<
HTML
::
Pipeline
::
Filter
PUNCTUATION_REGEXP
=
/[^\p{Word}\- ]/u
LEADING_OR_TRAILING_SPACE_REGEXP
=
/^\p{Space}
|\p{Space}$/
PUNCTUATION_REGEXP
=
/[^\p{Word}\- ]/u
.
freeze
LEADING_OR_TRAILING_SPACE_REGEXP
=
/^\p{Space}
+|\p{Space}+$/
.
freeze
def
call
return
doc
if
context
[
:no_header_anchors
]
...
...
spec/lib/banzai/filter/table_of_contents_filter_spec.rb
View file @
2075ef7d
...
...
@@ -58,6 +58,11 @@ describe Banzai::Filter::TableOfContentsFilter do
expect
(
doc
.
css
(
'h1 a'
).
first
.
attr
(
'href'
)).
to
eq
'#this-header-is-filled-with-punctuation'
end
it
'removes any leading or trailing spaces'
do
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'
end
it
'appends a unique number to duplicates'
do
doc
=
filter
(
header
(
1
,
'One'
)
+
header
(
2
,
'One'
))
...
...
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