Skip to content
Snippets Groups Projects
Commit 88ee1825 authored by Brett Walker's avatar Brett Walker :octagonal_sign:
Browse files

Make `user-content-` prefix into constant

parent a3456c18
No related branches found
No related tags found
1 merge request!149150Make `user-content-` prefix into constant
......@@ -62,8 +62,11 @@ def remove_non_footnote_ids
return unless node.name == 'a' || node.name == 'li'
return unless node.has_attribute?('id')
return if node.name == 'a' && node['id'] =~ Banzai::Filter::FootnoteFilter::FOOTNOTE_LINK_REFERENCE_PATTERN
return if node.name == 'li' && node['id'] =~ Banzai::Filter::FootnoteFilter::FOOTNOTE_LI_REFERENCE_PATTERN
return if node.name == 'a' &&
node['id'].start_with?(Banzai::Filter::FootnoteFilter::FOOTNOTE_LINK_ID_PREFIX)
return if node.name == 'li' &&
node['id'].start_with?(Banzai::Filter::FootnoteFilter::FOOTNOTE_ID_PREFIX)
node.remove_attribute('id')
end
......
......@@ -55,7 +55,11 @@ def call
def anchor_tag(href)
escaped_href = CGI.escape(href) # account for non-ASCII characters
%(<a id="user-content-#{href}" class="anchor" href="##{escaped_href}" aria-hidden="true"></a>)
<<~TAG.squish
<a id="#{Banzai::Renderer::USER_CONTENT_ID_PREFIX}#{href}"
class="anchor" href="##{escaped_href}" aria-hidden="true"></a>
TAG
end
def push_toc(children, root: false)
......
......@@ -2,6 +2,8 @@
module Banzai
module Renderer
USER_CONTENT_ID_PREFIX = 'user-content-'
# Convert a Markdown String into an HTML-safe String of HTML
#
# Note that while the returned HTML will have been sanitized of dangerous
......
......@@ -17,7 +17,7 @@ module Asciidoc
DEFAULT_ADOC_ATTRS = {
'showtitle' => true,
'sectanchors' => true,
'idprefix' => 'user-content-',
'idprefix' => Banzai::Renderer::USER_CONTENT_ID_PREFIX,
'idseparator' => '-',
'env' => 'gitlab',
'env-gitlab' => '',
......
......@@ -20,7 +20,9 @@ def convert_inline_quoted(node)
end
def convert_inline_anchor(node)
node.id = "user-content-#{node.id}" if node.id && !node.id.start_with?('user-content-')
if node.id && !node.id.start_with?(Banzai::Renderer::USER_CONTENT_ID_PREFIX)
node.id = "#{Banzai::Renderer::USER_CONTENT_ID_PREFIX}#{node.id}"
end
super(node)
end
......
......@@ -37,7 +37,7 @@
visit dashboard_projects_path
end
it 'returns message when starred projects fitler returns no results' do
it 'returns message when starred projects filter returns no results' do
fill_in 'project-filter-form-field', with: 'Beta\n'
expect(page).to have_content('There are no projects available to be displayed here')
......
......@@ -184,7 +184,7 @@
is_expected.to match_array([pipeline1, pipeline3])
end
it 'does not fitler out child pipelines' do
it 'does not filter out child pipelines' do
is_expected.to include(pipeline3)
end
end
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment