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

Feature request: support sourcepos = TRUE #110

Closed
dmurdoch opened this issue Dec 8, 2023 · 1 comment · Fixed by #111
Closed

Feature request: support sourcepos = TRUE #110

dmurdoch opened this issue Dec 8, 2023 · 1 comment · Fixed by #111

Comments

@dmurdoch
Copy link
Contributor

dmurdoch commented Dec 8, 2023

I'd like to update the RmdConcord package to support markdown::html_format (and maybe markdown::latex_format, but I'm not there yet). This requires the sourcepos = TRUE argument to be passed to commonmark::markdown_html. I can see how to do that, but the trouble is that the markdown::mark function causes problems with the result.

Specifically, with this file as input:

---
title: "Untitled"
output: 
  markdown::html_format:
    keep_md: true
---

some text

I can see commonmark::markdown_html being called twice. Once is for the main text, and a second time is for the title. When I turn on the sourcepos = TRUE option, the main text is fine.

However, the output from commonmark::markdown_html for the title is "<p data-sourcepos=\"1:1-1:8\">Untitled</p>\n". The render() function within mark() cleans this up to "<p data-sourcepos=\"1:1-1:8\">Untitled\n", and that's not valid HTML because now the tags don't balance and we have an orphan <p data-sourcepos=\"1:1-1:8\"> stuck within the title in the final output:

<title><p data-sourcepos=\"1:1-1:8\">Untitled</title>

There's a similar issue in in the body where the title is displayed.

Would you accept a PR that fixed this? I think it would be okay to completely remove the source reference when cleaning. It might be possible to fix it up to point to the YAML block, but that's probably messy.

@yihui
Copy link
Member

yihui commented Dec 8, 2023

Oh yes please. Thank you!

@yihui yihui linked a pull request Dec 8, 2023 that will close this issue
@yihui yihui closed this as completed in #111 Dec 8, 2023
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 a pull request may close this issue.

2 participants