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

Linebreaks in footnotes #104

Open
maelle opened this issue Apr 5, 2024 · 2 comments
Open

Linebreaks in footnotes #104

maelle opened this issue Apr 5, 2024 · 2 comments
Labels
bug Something isn't working pending fix A fix has been proposed and is awaiting approval upstream This issue cannot be addressed directly in {tinkr}}

Comments

@maelle
Copy link
Member

maelle commented Apr 5, 2024

Via ropensci-review-tools/babeldown#63 @xtimbeau

lines <- c("---",
'title: "footnote"',
'---',
'',
'let us insert a footnote[^1]',
'',
'[^1]: here it is. We want a line break',
'',
'    nice and clean inside the footnote',
'',
'    another one',
'')

temp_file <- withr::local_tempfile()
brio::write_lines(lines, temp_file)
tinkr::yarn$new(temp_file)$body
#> {xml_document}
#> <document xmlns="http://commonmark.org/xml/1.0">
#> [1] <paragraph>\n  <text xml:space="preserve">let us insert a footnote[^1]</t ...
#> [2] <paragraph>\n  <text xml:space="preserve">[^1]: here it is. We want a lin ...
#> [3] <code_block xml:space="preserve" name="">nice and clean inside the footno ...

Created on 2024-04-05 with reprex v2.1.0

To me it seems to be a limitation of commonmark.

@zkamvar
Copy link
Member

zkamvar commented Apr 5, 2024

It's kind of a limitation with {commonmark}. The thing is: we don't process footnotes per se, we just find a way to ignore them.

The solution to this particular problem at the moment is to use two or three spaces, not four for the footnote, which is causing commonmark to see a code block (but see below as to why this is not future-proof 😞)

Last year {commonmark} gained footnote support, but it produces results that are difficult to work with: (see r-lib/commonmark#23 and r-lib/commonmark#24). That being said, this is upstream in the cmark-gfm repository and GitHub has them enabled for their markdown renderer (but not for comments, apparently!)

That being said, apparently commonmark detects footnote blocks by checking for indentations of four or more spaces following the definition 😩, but of course then we run into the problems of the footnotes labelled as <unknown>, which is invalid XML. I've opened github/cmark-gfm#362 to see if it could be fixed upstream, but we'll see how it goes.

lines <- c("---",
'title: "footnote"',
'---',
'',
'let us insert a footnote[^1]',
'',
'[^1]: here it is. We want a line break',
'    ',
'    nice and clean inside the footnote',
'    ',
'    another one',
'')
temp_file <- withr::local_tempfile()
brio::write_lines(lines, temp_file)
commonmark::markdown_xml(lines, footnotes = TRUE) |> writeLines()
#> <?xml version="1.0" encoding="UTF-8"?>
#> <!DOCTYPE document SYSTEM "CommonMark.dtd">
#> <document xmlns="http://commonmark.org/xml/1.0">
#>   <thematic_break />
#>   <heading level="2">
#>     <text xml:space="preserve">title: &quot;footnote&quot;</text>
#>   </heading>
#>   <paragraph>
#>     <text xml:space="preserve">let us insert a footnote</text>
#>     <<unknown> />
#>   </paragraph>
#>   <<unknown>>
#>     <paragraph>
#>       <text xml:space="preserve">here it is. We want a line break</text>
#>     </paragraph>
#>     <paragraph>
#>       <text xml:space="preserve">nice and clean inside the footnote</text>
#>     </paragraph>
#>     <paragraph>
#>       <text xml:space="preserve">another one</text>
#>     </paragraph>
#>   </<unknown>>
#> </document>

Created on 2024-04-05 with reprex v2.0.2

@zkamvar zkamvar added the bug Something isn't working label Apr 5, 2024
@maelle
Copy link
Member Author

maelle commented Apr 18, 2024

Thank you!!

@zkamvar zkamvar added upstream This issue cannot be addressed directly in {tinkr}} pending fix A fix has been proposed and is awaiting approval labels May 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working pending fix A fix has been proposed and is awaiting approval upstream This issue cannot be addressed directly in {tinkr}}
Projects
None yet
Development

No branches or pull requests

2 participants