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
b6ca523c
Commit
b6ca523c
authored
Apr 04, 2019
by
Willian Balmant
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
No leading/trailing spaces when generating heading ids (Fixes #57528)
parent
3ccb4d95
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
2 additions
and
0 deletions
+2
-0
lib/banzai/filter/table_of_contents_filter.rb
lib/banzai/filter/table_of_contents_filter.rb
+2
-0
No files found.
lib/banzai/filter/table_of_contents_filter.rb
View file @
b6ca523c
...
@@ -18,6 +18,7 @@ module Banzai
...
@@ -18,6 +18,7 @@ module Banzai
# `li` child elements.
# `li` child elements.
class
TableOfContentsFilter
<
HTML
::
Pipeline
::
Filter
class
TableOfContentsFilter
<
HTML
::
Pipeline
::
Filter
PUNCTUATION_REGEXP
=
/[^\p{Word}\- ]/u
PUNCTUATION_REGEXP
=
/[^\p{Word}\- ]/u
LEADING_OR_TRAILING_SPACE_REGEXP
=
/^\p{Space}|\p{Space}$/
def
call
def
call
return
doc
if
context
[
:no_header_anchors
]
return
doc
if
context
[
:no_header_anchors
]
...
@@ -31,6 +32,7 @@ module Banzai
...
@@ -31,6 +32,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
.
downcase
.
downcase
.
gsub
(
PUNCTUATION_REGEXP
,
''
)
# remove punctuation
.
gsub
(
PUNCTUATION_REGEXP
,
''
)
# remove punctuation
.
tr
(
' '
,
'-'
)
# replace spaces with dash
.
tr
(
' '
,
'-'
)
# replace spaces with dash
...
...
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