Commit ff64584c authored by Sean McGivern's avatar Sean McGivern

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
parents 9aa81c0a ce32f71b
---
title: Remove leading / trailing spaces from heading when generating header ids
merge_request: 27025
author: Willian Balmant
type: fixed
...@@ -31,6 +31,7 @@ module Banzai ...@@ -31,6 +31,7 @@ module Banzai
if header_content = node.children.first if header_content = node.children.first
id = node id = node
.text .text
.strip
.downcase .downcase
.gsub(PUNCTUATION_REGEXP, '') # remove punctuation .gsub(PUNCTUATION_REGEXP, '') # remove punctuation
.tr(' ', '-') # replace spaces with dash .tr(' ', '-') # replace spaces with dash
......
...@@ -58,6 +58,11 @@ describe Banzai::Filter::TableOfContentsFilter do ...@@ -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' expect(doc.css('h1 a').first.attr('href')).to eq '#this-header-is-filled-with-punctuation'
end 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 it 'appends a unique number to duplicates' do
doc = filter(header(1, 'One') + header(2, 'One')) doc = filter(header(1, 'One') + header(2, 'One'))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment