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

Respect preview output format #785

Merged
merged 2 commits into from
Sep 11, 2021

Conversation

ElianHugh
Copy link
Collaborator

Closes #779

At the moment, previewing R Markdown documents forces the rmarkdown::html_document() format. However, this overwrites all output formats, even if they can result in a .html file.

This PR uses the object pandoc$to from rmarkdown:::create_output_format to check if the document's output format == html. This way, we only override the output format if pandoc$to does not equal html.

Screenshot

image

How can I check this pull request?

The following renders incorrectly on master, which is fixed in this PR:

---
title: "R Notebook"
output:
  bookdown::html_document2: default
---

```{r table1}
knitr::kable(mtcars[1:5, 1:5], caption = "The mtcars data.")
```

`mtcar` data is shown in Table \@ref(tab:table1).

@renkun-ken
Copy link
Member

renkun-ken commented Sep 10, 2021

The rendering works now.

But it seems the link to table 1 does not work: it will open in an external browser and go to a non-working URL.

@ElianHugh
Copy link
Collaborator Author

ElianHugh commented Sep 11, 2021

Thanks for picking that up - it looks like this is something to do with how webviews convert links, as the anchors work in external browsers.

Edit:
Specifically, anchor tags like #tab:table1 are converted to a webview resource scheme

@renkun-ken
Copy link
Member

The anchor tags work nicely now.

Copy link
Member

@renkun-ken renkun-ken left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@renkun-ken renkun-ken merged commit 2333f69 into REditorSupport:master Sep 11, 2021
ElianHugh added a commit to ElianHugh/vscode-R that referenced this pull request May 12, 2022
* Respect output format

* Fix anchor tags
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 this pull request may close these issues.

Cross-reference does not work in preview when specify output as bookdown::html_document2
2 participants