Commit 955d013a authored by GitLab Bot's avatar GitLab Bot

Automatic merge of gitlab-org/gitlab-ce master

parents 3ffc71d5 f741a7dd
---
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