r-lib / commonmark

High Performance CommonMark and Github Markdown Rendering in R
https://docs.ropensci.org/commonmark/
Other
88 stars 11 forks source link

`commonmark::markdown_text(footnotes = TRUE)` does not strip footnotes #24

Open salim-b opened 1 year ago

salim-b commented 1 year ago

The recently introduced footnote support via param footnotes does not work as one would expect for commonmark::markdown_text(). For all other Markdown features (like emphasizing, links etc.), they are stripped by commonmark::markdown_text() since regular text has no notion of markup.

But the footnotes remain:

md <- "Text *emphasized* and **bold**, with [inline link](https://to.some.where/), [reference link][ref] and footnote[^fn].\n\n[ref]: https://fsf.org\n\n[^fn]: A note.\n"
cat(md)
#> Text *emphasized* and **bold**, with [inline link](https://to.some.where/), [reference link][ref] and footnote[^fn].
#> 
#> [ref]: https://fsf.org
#> 
#> [^fn]: A note.

# without footnote parsing
md |> commonmark::markdown_text(footnotes = F) |> cat()
#> Text emphasized and bold, with inline link, reference link and footnote[^fn].
#> 
#> [^fn]: A note.

# with footnote parsing
md |> commonmark::markdown_text(footnotes = T) |> cat()
#> Text emphasized and bold, with inline link, reference link and footnote[^1].
#> 
#> [^1]: A note.

Created on 2023-03-29 with reprex v2.0.2

Is this really the intended behaviour?

jeroen commented 1 year ago

I am not sure actually. Footnotes are not described in the gfm spec. I can imagine they are considered content, not markup, and hence get retained in plain text.

Either way, you have to ask this upstream in https://github.com/github/cmark-gfm . We don't control this form the R bindings.