summaryrefslogtreecommitdiff
path: root/lib/banzai/filter/table_of_contents_filter.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/banzai/filter/table_of_contents_filter.rb')
-rw-r--r--lib/banzai/filter/table_of_contents_filter.rb5
1 files changed, 3 insertions, 2 deletions
diff --git a/lib/banzai/filter/table_of_contents_filter.rb b/lib/banzai/filter/table_of_contents_filter.rb
index ade4d260be1..a2c8e92e560 100644
--- a/lib/banzai/filter/table_of_contents_filter.rb
+++ b/lib/banzai/filter/table_of_contents_filter.rb
@@ -56,7 +56,8 @@ module Banzai
private
def anchor_tag(href)
- %Q{<a id="user-content-#{href}" class="anchor" href="##{href}" aria-hidden="true"></a>}
+ escaped_href = CGI.escape(href) # account for non-ASCII characters
+ %Q{<a id="user-content-#{href}" class="anchor" href="##{escaped_href}" aria-hidden="true"></a>}
end
def push_toc(children, root: false)
@@ -80,7 +81,7 @@ module Banzai
def initialize(node: nil, href: nil, previous_header: nil)
@node = node
- @href = href
+ @href = CGI.escape(href) if href
@children = []
@parent = find_parent(previous_header)