Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

resolves #4383 allow the footnote tooltips to be localized #4510

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.adoc
Expand Up @@ -36,6 +36,7 @@ Enhancements::
* Set logdev to $stderr if no arguments are passed to Logger constructor (#4250)
* Add support for skipping TOML front matter (Hugo) when `skip-front-matter` attribute is set (#4300) (*@abhinav*)
* Add support for Wistia using the video macro
* Allow the footnote toolips to be localized using the `view-footnote-tip` and `unresolved-footnoteref-tip` attributes (#4383)

Compliance::

Expand Down
2 changes: 2 additions & 0 deletions data/locale/attributes-en.adoc
Expand Up @@ -21,3 +21,5 @@ ifdef::preface-title[:preface-title: Preface]
:untitled-label: Untitled
:version-label: Version
:warning-caption: Warning
:view-footnote-tip: View footnote.
:unresolved-footnoteref-tip: Unresolved footnote reference.
7 changes: 4 additions & 3 deletions lib/asciidoctor/converter/html5.rb
Expand Up @@ -1190,14 +1190,15 @@ def convert_inline_callout node

def convert_inline_footnote node
if (index = node.attr 'index')
view_footnote_tip = node.document.attr 'view-footnote-tip', 'View footnote.'
if node.type == :xref
%(<sup class="footnoteref">[<a class="footnote" href="#_footnotedef_#{index}" title="View footnote.">#{index}</a>]</sup>)
%(<sup class="footnoteref">[<a class="footnote" href="#_footnotedef_#{index}" title="#{view_footnote_tip}">#{index}</a>]</sup>)
else
id_attr = node.id ? %( id="_footnote_#{node.id}") : ''
%(<sup class="footnote"#{id_attr}>[<a id="_footnoteref_#{index}" class="footnote" href="#_footnotedef_#{index}" title="View footnote.">#{index}</a>]</sup>)
%(<sup class="footnote"#{id_attr}>[<a id="_footnoteref_#{index}" class="footnote" href="#_footnotedef_#{index}" title="#{view_footnote_tip}">#{index}</a>]</sup>)
end
elsif node.type == :xref
%(<sup class="footnoteref red" title="Unresolved footnote reference.">[#{node.text}]</sup>)
%(<sup class="footnoteref red" title="#{node.document.attr 'unresolved-footnoteref-tip', 'Unresolved footnote reference.'}">[#{node.text}]</sup>)
end
end

Expand Down
13 changes: 13 additions & 0 deletions test/substitutions_test.rb
Expand Up @@ -1324,6 +1324,19 @@
assert_equal ['1. second footnote', '1. first footnote', '2. third footnote'], footnote_defs.map(&:text).map(&:strip)
end

test 'footnote localization' do
using_memory_logger do |logger|
attributes = {
'view-footnote-tip' => 'Voir la note de bas de page.',
'unresolved-footnoteref-tip' => 'Référence de note de bas de page non résolue.',
}
para = block_from_string 'Sentence textfootnote:[An example footnote.].footnote:ex1[]', attributes: attributes
output = para.sub_macros para.source
assert_equal 'Sentence text<sup class="footnote">[<a id="_footnoteref_1" class="footnote" href="#_footnotedef_1" title="Voir la note de bas de page.">1</a>]</sup>.<sup class="footnoteref red" title="Référence de note de bas de page non résolue.">[ex1]</sup>', output
assert_message logger, :WARN, 'invalid footnote reference: ex1'
end
end

test 'a single-line index term macro with a primary term should be registered as an index reference' do
sentence = "The tiger (Panthera tigris) is the largest cat species.\n"
macros = ['indexterm:[Tigers]', '(((Tigers)))']
Expand Down