Merge branch '57634-issue-when-viewing-a-document-with-footnotes-actionview-template-error-undefined-method-at_css-for-nil-nilclass' into 'master'
Issue when viewing a document with footnotes Closes #57634 See merge request gitlab-org/gitlab-ce!25199
This commit is contained in:
commit
69c19b392e
2 changed files with 18 additions and 7 deletions
|
@ -29,22 +29,31 @@ module Banzai
|
||||||
# Sanitization stripped off the section wrapper - add it back in
|
# Sanitization stripped off the section wrapper - add it back in
|
||||||
first_footnote.parent.wrap('<section class="footnotes">')
|
first_footnote.parent.wrap('<section class="footnotes">')
|
||||||
rand_suffix = "-#{random_number}"
|
rand_suffix = "-#{random_number}"
|
||||||
|
modified_footnotes = {}
|
||||||
|
|
||||||
doc.css('sup > a[id]').each do |link_node|
|
doc.css('sup > a[id]').each do |link_node|
|
||||||
ref_num = link_node[:id].delete_prefix(FOOTNOTE_LINK_ID_PREFIX)
|
ref_num = link_node[:id].delete_prefix(FOOTNOTE_LINK_ID_PREFIX)
|
||||||
footnote_node = doc.at_css("li[id=#{fn_id(ref_num)}]")
|
footnote_node = doc.at_css("li[id=#{fn_id(ref_num)}]")
|
||||||
backref_node = footnote_node.at_css("a[href=\"##{fnref_id(ref_num)}\"]")
|
|
||||||
|
|
||||||
if ref_num =~ INTEGER_PATTERN && footnote_node && backref_node
|
if INTEGER_PATTERN.match?(ref_num) && (footnote_node || modified_footnotes[ref_num])
|
||||||
link_node[:href] += rand_suffix
|
link_node[:href] += rand_suffix
|
||||||
link_node[:id] += rand_suffix
|
link_node[:id] += rand_suffix
|
||||||
footnote_node[:id] += rand_suffix
|
|
||||||
backref_node[:href] += rand_suffix
|
|
||||||
|
|
||||||
# Sanitization stripped off class - add it back in
|
# Sanitization stripped off class - add it back in
|
||||||
link_node.parent.append_class('footnote-ref')
|
link_node.parent.append_class('footnote-ref')
|
||||||
|
|
||||||
|
unless modified_footnotes[ref_num]
|
||||||
|
footnote_node[:id] += rand_suffix
|
||||||
|
backref_node = footnote_node.at_css("a[href=\"##{fnref_id(ref_num)}\"]")
|
||||||
|
|
||||||
|
if backref_node
|
||||||
|
backref_node[:href] += rand_suffix
|
||||||
backref_node.append_class('footnote-backref')
|
backref_node.append_class('footnote-backref')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
modified_footnotes[ref_num] = true
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
doc
|
doc
|
||||||
|
|
|
@ -11,6 +11,7 @@ describe Banzai::Filter::FootnoteFilter do
|
||||||
let(:footnote) do
|
let(:footnote) do
|
||||||
<<~EOF
|
<<~EOF
|
||||||
<p>first<sup><a href="#fn1" id="fnref1">1</a></sup> and second<sup><a href="#fn2" id="fnref2">2</a></sup></p>
|
<p>first<sup><a href="#fn1" id="fnref1">1</a></sup> and second<sup><a href="#fn2" id="fnref2">2</a></sup></p>
|
||||||
|
<p>same reference<sup><a href="#fn1" id="fnref1">1</a></sup></p>
|
||||||
<ol>
|
<ol>
|
||||||
<li id="fn1">
|
<li id="fn1">
|
||||||
<p>one <a href="#fnref1">↩</a></p>
|
<p>one <a href="#fnref1">↩</a></p>
|
||||||
|
@ -25,6 +26,7 @@ describe Banzai::Filter::FootnoteFilter do
|
||||||
let(:filtered_footnote) do
|
let(:filtered_footnote) do
|
||||||
<<~EOF
|
<<~EOF
|
||||||
<p>first<sup class="footnote-ref"><a href="#fn1-#{identifier}" id="fnref1-#{identifier}">1</a></sup> and second<sup class="footnote-ref"><a href="#fn2-#{identifier}" id="fnref2-#{identifier}">2</a></sup></p>
|
<p>first<sup class="footnote-ref"><a href="#fn1-#{identifier}" id="fnref1-#{identifier}">1</a></sup> and second<sup class="footnote-ref"><a href="#fn2-#{identifier}" id="fnref2-#{identifier}">2</a></sup></p>
|
||||||
|
<p>same reference<sup class="footnote-ref"><a href="#fn1-#{identifier}" id="fnref1-#{identifier}">1</a></sup></p>
|
||||||
<section class="footnotes"><ol>
|
<section class="footnotes"><ol>
|
||||||
<li id="fn1-#{identifier}">
|
<li id="fn1-#{identifier}">
|
||||||
<p>one <a href="#fnref1-#{identifier}" class="footnote-backref">↩</a></p>
|
<p>one <a href="#fnref1-#{identifier}" class="footnote-backref">↩</a></p>
|
||||||
|
|
Loading…
Reference in a new issue