kaushalmodi/ox-hugo

Insert   before footnote numbers

kaushalmodi opened this issue · 8 comments

This is a cool feature someone thought of on the Hugo discourse forum. Should be easy to implement.


https://discourse.gohugo.io/t/is-it-possible-to-enforce-the-footnote-number-to-render-on-same-line-as-preceding-symbol/9085

For the following markdown:

A line with a footnote.[^target]

[^target]: The footnote text

, depending on the line width, the period may be rendered at the end of a line and the footnote >number on the next line.

One solution to keep the footnote number on the same line as the period is to manually insert a span >with no-wrapping whitespace:

A line with a <span style="with-space: nowrap">footnote.[^terminal]</span>

[^target]: The footnote text

Probably, would be simple to always insert &nbsp; before the footnote number if it ends up at EOL.

Ideally should be fixed in blackfriday: russross/blackfriday#405

OK, need to make that regexp less strict.. the footnote ref could even be in the middle of the line, and depending on the screen width, we could end up with that footnote ref at the BOL of the next line.. So, need to always make the footnote ref stick to the word before it using &nbsp;.

Sorry for causing any trouble. It turned out this was only an issue with a specific Hugo theme, see https://discourse.gohugo.io/t/is-it-possible-to-enforce-the-footnote-number-to-render-on-same-line-as-preceding-symbol/9085/14

@kamar535 No trouble at all. Your question helped me add a new feature to ox-hugo :)

@kaushalmodi But the feature is not needed since it was a mere CSS issue and inserting a &nbsp; serves no purpose.

No, the issue is real.

Paste the below in your markdown file:

a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a
a [^fn:1] . B b b.

ab a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a
a [^fn:1] . B b b.

abc a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a
a a [^fn:1] . B b b.
abcd a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a
a a [^fn:1] . B b b.

abcde a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a
a a a [^fn:1] . B b b.


[^fn:1]: First footnote

and then change the browser window width so that the footnote ref wraps to the next line.. you will see the problem.

image


Fix

Here's the fixed version of that that ox-hugo creates:

a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a
a&nbsp;[^fn:1]. B b b.

ab a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a
a&nbsp;[^fn:1]. B b b.

abc a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a
a a&nbsp;[^fn:1]. B b b.
abcd a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a
a a&nbsp;[^fn:1]. B b b.

abcde a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a
a a a&nbsp;[^fn:1]. B b b.


[^fn:1]: First footnote

Now try the same with the fixed version.

Here's what it looks after that fix:

image

Aha. By habit I never put any white space before any [^fn] I either do foo bar[^fn:1] baz., foo bar baz.[^fn:1] so I never thought about it is an issue. But yes, this might actually be handy in the cases where there is white space before the [^fn:n].

Agree. I also never put a space before the fn ref or the period. But reading your question there made me think of all the pathological cases that could result in the wrapping to happen in that unwanted manner. As I am developing this package for mass consumption, I might as well not leave any room for surprises :).