diff options
author | Sean McGivern <sean@gitlab.com> | 2019-05-06 07:41:10 +0000 |
---|---|---|
committer | Sean McGivern <sean@gitlab.com> | 2019-05-06 07:41:10 +0000 |
commit | ff64584cfaddb170cfa3a5c647ee4783cdb6058e (patch) | |
tree | dba03fa530ebdf9437d79e3494c2c1c755a47600 | |
parent | 9aa81c0a95b0e54bbafca4755e95f27ee1eeb759 (diff) | |
parent | ce32f71bd6a6844276bbc6299c5ddc13bac743e4 (diff) | |
download | gitlab-ce-ff64584cfaddb170cfa3a5c647ee4783cdb6058e.tar.gz |
Merge branch 'patch-49' into 'master'
No leading/trailing spaces when generating heading ids (Fixes #57528)
Closes #57528
See merge request gitlab-org/gitlab-ce!27025
-rw-r--r-- | changelogs/unreleased/patch-49.yml | 5 | ||||
-rw-r--r-- | lib/banzai/filter/table_of_contents_filter.rb | 1 | ||||
-rw-r--r-- | spec/lib/banzai/filter/table_of_contents_filter_spec.rb | 5 |
3 files changed, 11 insertions, 0 deletions
diff --git a/changelogs/unreleased/patch-49.yml b/changelogs/unreleased/patch-49.yml new file mode 100644 index 00000000000..2c8af1e5c48 --- /dev/null +++ b/changelogs/unreleased/patch-49.yml @@ -0,0 +1,5 @@ +--- +title: Remove leading / trailing spaces from heading when generating header ids +merge_request: 27025 +author: Willian Balmant +type: fixed diff --git a/lib/banzai/filter/table_of_contents_filter.rb b/lib/banzai/filter/table_of_contents_filter.rb index 1a68d773048..ade4d260be1 100644 --- a/lib/banzai/filter/table_of_contents_filter.rb +++ b/lib/banzai/filter/table_of_contents_filter.rb @@ -31,6 +31,7 @@ module Banzai if header_content = node.children.first id = node .text + .strip .downcase .gsub(PUNCTUATION_REGEXP, '') # remove punctuation .tr(' ', '-') # replace spaces with dash diff --git a/spec/lib/banzai/filter/table_of_contents_filter_spec.rb b/spec/lib/banzai/filter/table_of_contents_filter_spec.rb index 7213cd58ea7..4a9880ac85a 100644 --- a/spec/lib/banzai/filter/table_of_contents_filter_spec.rb +++ b/spec/lib/banzai/filter/table_of_contents_filter_spec.rb @@ -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\tTitle 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')) |