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

Footnotes support? #22

Closed
yihui opened this issue Mar 16, 2023 · 11 comments
Closed

Footnotes support? #22

yihui opened this issue Mar 16, 2023 · 11 comments

Comments

@yihui
Copy link
Contributor

yihui commented Mar 16, 2023

It seems that footnotes are supported in GFM:

but somehow this feature is not enabled in the R package?

commonmark::markdown_html('a[^1] \n\n[^1]: test footnote')
#> [1] "<p>a[^1]</p>\n<p>[^1]: test footnote</p>\n"

And worse still, a footnote can be treated as a link definition:

commonmark::markdown_html('a[^1] \n\n[^1]: https://example.com')
#> [1] "<p>a<a href=\"https://example.com\">^1</a></p>\n"

@jeroen Do you know how to enable footnotes support? Thanks!

@jeroen jeroen closed this as completed in 91dd6eb Mar 17, 2023
@jeroen
Copy link
Member

jeroen commented Mar 17, 2023

Good catch. Seemingly this is an option in the parser, not sure why.
I have now exposed the option (or should we just enable it by default globally)?

commonmark::markdown_html('a[^1] \n\n[^1]: test footnote', footnotes = TRUE)
# [1] "<p>a<sup class=\"footnote-ref\"><a href=\"#fn-1\" id=\"fnref-1\" data-footnote-ref>1</a></sup></p>\n<section class=\"footnotes\" data-footnotes>\n<ol>\n<li id=\"fn-1\">\n<p>test footnote <a href=\"#fnref-1\" class=\"footnote-backref\" data-footnote-backref aria-label=\"Back to content\">↩</a></p>\n</li>\n</ol>\n</section>\n"

@yihui
Copy link
Contributor Author

yihui commented Mar 17, 2023

Thanks! I think it will be nice to enable it by default. However, the LaTeX output is not implemented yet:

case CMARK_NODE_FOOTNOTE_DEFINITION:
case CMARK_NODE_FOOTNOTE_REFERENCE:
// TODO

I don't know why it was not implemented, i.e., isn't it just \footnote{CONTENT}?

@jeroen
Copy link
Member

jeroen commented Mar 17, 2023

I have no idea, you'd have to ask the folks at cmark-gfm. I guess it's not part of the official spec?

@yihui
Copy link
Contributor Author

yihui commented Mar 17, 2023

Okay. I'll ask there. Before LaTeX output is implemented, I think it may be better to disable this option by default for markdown_latex() while enabling it for markdown_html().

BTW, it will be great if you can make a new CRAN release but there is no hurry (I spent some time on a clumsy implementation of footnotes in R before I dug into GFM's C code and discovered that GFM actually had this feature). Thanks again!

@yihui
Copy link
Contributor Author

yihui commented Mar 17, 2023

One more thing: do you have a plan to upgrade to 0.29.0.gfm.9? There have been some improvements like github/cmark-gfm@c32ef78.

@jeroen
Copy link
Member

jeroen commented Mar 17, 2023

OK I've upgraded to 0.29.0.gfm.9 now.

I can do a CRAN release any moment, if we agree to switch the default or not :)

@yihui
Copy link
Contributor Author

yihui commented Mar 17, 2023

Sounds great! I don't have a strong opinion on whether to enable footnotes by default. It's simple enough for me to enable it by myself, and I'm okay with any decision your make. I only slightly prefer enabling it for markdown_html() at this time.

@jeroen
Copy link
Member

jeroen commented Mar 17, 2023

OK in that case I will leave it disabled by now, such that there is no change of default behavior, and submit to CRAN now.

Perhaps we can enable it by default in future versions, but that would require more checking of reverse dependencies to make sure we don't break things.

@yihui
Copy link
Contributor Author

yihui commented Mar 17, 2023

that would require more checking of reverse dependencies to make sure we don't break things.

Absolutely.

Let's see if anyone could help with github/cmark-gfm#314.

@jeroen
Copy link
Member

jeroen commented Mar 17, 2023 via email

@yihui
Copy link
Contributor Author

yihui commented Mar 17, 2023

Perfect!

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

No branches or pull requests

2 participants