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

Adjust EPUB footnotes with backlink before text #8672

Closed
wants to merge 1 commit into from

Conversation

lewer
Copy link
Contributor

@lewer lewer commented Mar 6, 2023

Currently, pandoc footnotes leads to buggy display with kindle (see #4491)

This PR aims at fixing #5583.

I have taken @Porges code.

The PR makes pandoc's footnotes compliant with https://kindlegen.s3.amazonaws.com/AmazonKindlePublishingGuidelines.pdf (see p. 34, Method 2)

I don't code in haskell, so please review carefully. In particular, the code introduces an empty line between the hrtag and the first footnote, empty line that should not be there but that I don't know how to remove. Any help with this? Thanks.

@@ -557,13 +557,7 @@ footnoteSection refLocation startCounter notes = do
container $ do
nl
hrtag
-- Keep the previous output exactly the same if we don't
-- have multiple notes sections
if startCounter == 1
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've assumed that this can be dropped as long as ordered lists are not used anymore, is it really the case?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it can't be dropped. This plays a significant role when you use --reference-location=block (or section), which causes the footnotes to be printed at the end of each block (or section). In that case we need to make sure that the numbering continues appropriately in each new footnote section.

Comment on lines -130 to +132
, "<ol>"
, "<li id=\"fn1\"><p>Down here.<a href=\"#fnref1\" class=\"footnote-back\">↩︎</a></p></li>"
, "<li id=\"fn2\"><p>The second note.<a href=\"#fnref2\" class=\"footnote-back\">↩︎</a></p></li>"
, "</ol>"
, ""
, "<div id=\"fn1\"><p><a href=\"#fnref1\" class=\"footnote-back\">1.</a> Down here.</p></div>"
, "<div id=\"fn2\"><p><a href=\"#fnref2\" class=\"footnote-back\">2.</a> The second note.</p></div>"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think I like this change. Using ordered lists gives us much better formatting (content of a note is aligned), and it will work well even if the note is, say, a code block.

@jgm
Copy link
Owner

jgm commented Mar 6, 2023

Pandoc's current system complies with http://kb.daisy.org/publishing/docs/html/notes.html which says that, when endnotes are used (as with pandoc), the backlink should come at the end of the note. I gather this still causes a problem on Kindle? Can you explain what the problem is, exactly?

I'm willing to consider a system that moves the backlink to the front, although that seems inferior from a reader's perspective. (After reading the note, you don't want to have to scroll to the beginning of the note to find the backlink.) Perhaps this could be configurable.

Making the backlink the note number itself requires moving away from the use of <ol>, and that has other disadvantages. (You lose the nice alignment that ols give you, and you have to figure out how to insert the note number into, potentially, any type of block -- what if the note starts with a code block, for example?) If we wanted to pursue this, I'd say the first step would be to work out what the HTML (and CSS) should look like (in general, not just for a simple paragraph note).

@Porges
Copy link

Porges commented Mar 6, 2023

@jgm The problems with Kindle are described in #4491. The same issue also describes how back links at the start are recommended by different accessibility guidelines.

@jgm
Copy link
Owner

jgm commented Mar 6, 2023

Yes, but the guidelines recommend backlinks at the end for endnotes...like the ones we provide by default. (See the link above.)

@jgm
Copy link
Owner

jgm commented Mar 6, 2023

Anyway, I just wanted to confirm that the problem described in #4491 still affects Kindle software. (After all, they've now had 4 years to fix it...)

@lewer
Copy link
Contributor Author

lewer commented Mar 6, 2023

I'm willing to consider a system that moves the backlink to the front, although that seems inferior from a reader's perspective. (After reading the note, you don't want to have to scroll to the beginning of the note to find the backlink.)

It's also true the other way around: when you click on a note and figure out that you don't want to read it, you don't want to have to scroll to the end of the note to find the backlink ;-)

I don't have an opinion about div rather than ol or aside for footnotes (and it seems that guidelines don't have a clear opinion about that neither...), but kindle is not the only one who struggles displaying correctly pandoc's footnotes. Look at this screenshot taken from Google Play Books: the second endnote appears with note number 1. in the popup

I agree that ol offers the advantage of native nice alignment. But epub readers offer popup endnotes/footnotes, which do not seem to go well with ol. Even if guidelines differ between kb.daisy.org, amazon, ibooks, they all seem to converge towards using the aside tag, as pointed out by @Porges here

What about an option that selects between endnote (default, current behavior) and footnote (aside instead of ol, backlink at the beginning)?

@jgm
Copy link
Owner

jgm commented Mar 7, 2023

What about an option that selects between endnote (default, current behavior) and footnote (aside instead of ol, backlink at the beginning)?

That's certainly possible. We could also make the "footnote" behavior the default when generating HTML for epub. (And maybe if we did that we wouldn't need to make it user-configurable -- though perhaps some people would enjoy having the footnote behavior for web pages too?)

We'd still need to figure out a good way of constructing the footnote div and inserting the number (again, keeping in mind that it won't necessarily begin with paragraph text). I suppose the simplest thing would be to put the number in a paragraph by itself if the note begins with something other than paragraph text.

@lewer
Copy link
Contributor Author

lewer commented Mar 7, 2023

We could also make the "footnote" behavior the default when generating HTML for epub. (And maybe if we did that we wouldn't need to make it user-configurable -- though perhaps some people would enjoy having the footnote behavior for web pages too?)

I was thinking the same. Maybe for a first PR, not user-configurable, to keep it simple. And later if needed, an option could be added for that.

We'd still need to figure out a good way of constructing the footnote div and inserting the number (again, keeping in mind that it won't necessarily begin with paragraph text). I suppose the simplest thing would be to put the number in a paragraph by itself if the note begins with something other than paragraph text.

I agree.

I don't think there's a lot to do, the code written by @Porges already builds the footnote div and putting the note in a separate paragraph isn't complicated. What still needs to be done I think, is adding a "behavior" option to the function which generates the footnote section, and calling it with "behavior = footnotes" from epub writer. Maybe also a bit of CSS to display it nicely.

I can try, but I'm not familiar with Haskell so I don't promise anything. @Porges, do you have time to tackle this it? Otherwise I'll do it.

@lewer lewer marked this pull request as draft March 7, 2023 09:40
@jgm
Copy link
Owner

jgm commented Mar 7, 2023

The HTML writer has a state variable stEPUBVersion that will have a Just value if the writer is being used to produce EPUB. So that's the thing to look at to switch between the behaviors.

@jgm
Copy link
Owner

jgm commented Mar 8, 2023

I'll have a go at this.

jgm added a commit that referenced this pull request Mar 8, 2023
Many EPUB readers are thrown off by pandoc's current footnote
output.  Both the ol and the fact that the footnote backlink is
at the end of the note seem to pose problems.

With this commit, we now create a list of aside (or div) elements,
instead of an ordered list. Each element begins with a note number
that is linked back to the note reference.  (So, the backlink occurs
at the beginning rather than the end.)

References:

- https://kindlegen.s3.amazonaws.com/AmazonKindlePublishingGuidelines.pdf
- http://kb.daisy.org/publishing/docs/html/notes.html

See #8672, closes #5583.

Thanks to @Porges and @lewer.
@jgm
Copy link
Owner

jgm commented Mar 8, 2023

See new PR #8676 - please test if you can.

jgm added a commit that referenced this pull request Mar 8, 2023
Many EPUB readers are thrown off by pandoc's current footnote
output.  Both the ol and the fact that the footnote backlink is
at the end of the note seem to pose problems.

With this commit, we now create a list of aside (or div) elements,
instead of an ordered list. Each element begins with a note number
that is linked back to the note reference.  (So, the backlink occurs
at the beginning rather than the end.)

References:

- https://kindlegen.s3.amazonaws.com/AmazonKindlePublishingGuidelines.pdf
- http://kb.daisy.org/publishing/docs/html/notes.html

See #8672, closes #5583.

Thanks to @Porges and @lewer.
@jgm
Copy link
Owner

jgm commented Mar 8, 2023

Now that I've merged the other PR, this one is obsolete. Thank you!

@jgm jgm closed this Mar 8, 2023
@lewer lewer deleted the backlink-before branch March 8, 2023 20:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants