Skip to content

Add R Markdown surround and frontmatter comments#269

Merged
andycraig merged 4 commits intoREditorSupport:masterfrom
andycraig:rmarkdown-surround
Apr 6, 2020
Merged

Add R Markdown surround and frontmatter comments#269
andycraig merged 4 commits intoREditorSupport:masterfrom
andycraig:rmarkdown-surround

Conversation

@andycraig
Copy link
Copy Markdown
Collaborator

Fixes #249

Fixes #260

This PR includes third-party code. The new lines in package.json are copied from
https://github.com/microsoft/vscode/blob/master/extensions/markdown-basics/package.json
which is MIT-licensed. The license information is included in
ThirdPartyNotices.txt. License information cannot be added to
package.json because JSON does not allow comments. I also added these lines in 1f355a3, and then removed them in 4a108e1. I didn't include the license information that time but I think I should have. I copied the format of ThirdPartyNotices.txt from https://github.com/microsoft/vscode/blob/master/ThirdPartyNotices.txt

@Ikuyadeu I have put your name in ThirdPartyNotices.txt - please check that it is okay.

What problem did you solve?

Adds surround support for R Markdown files.

Adds backtick surround and completion for R Markdown and R documentation files.

Adds correct comments for R Markdown YAML frontmatter, and other languages already supported by VSCode markdown.

How can I check this pull request?

Comments in R Markdown YAML frontmatter: Place cursor in YAML frontmatter. Use command Toggle Line Comment. Previously: Comment is HTML comment <!-- -->. Now: Comment is YAML comment #.

Surround in R Markdown: In R Markdown file, select a word. Press '. Previously: Word is replaced by '. Now: Word is surrounded by '.

Backticks in R Markdown/R document files: Select a word. Press backtick. Previously: Word is replaced by backtick. Now: Word is surrounded by backticks.

The new lines in package.json are copied from
https://github.com/microsoft/vscode/blob/master/extensions/markdown-basics/package.json
which is MIT-licensed. The license information is included in
ThirdPartyNotices.txt. License information cannot be added to
package.json because JSON does not allow comments.
@renkun-ken
Copy link
Copy Markdown
Member

renkun-ken commented Mar 29, 2020

I test this on macOS.

Commenting

Commenting works nicely in

  • YAML frontmatter, markdown content
  • Rmd R code chunk (```{r})
  • Rmd C++ code chunk (```{cpp})
  • Markdown R code chunk (```r)
  • Markdown C++ code chunk (```cpp)

but does not work with python code chunks (treating it like markdown content)

  • Rmd Python code chunk (```{python})
  • Markdown R code chunk (```python)

Although this is not covered by this PR but it still seems worthy pointing out as RStudio supports many language chunks in Rmd.

Surround in R Markdown

The surrounding of quotes works well.

Backticks in R Markdown/R document files

The backticks works well but introduces an obvious drawback: Typing backticks to create a code chunk will never end up with three backticks but two or four.

Extra things to notice

It looks the languageserver diagnostics will fail with Rmd that contains markdown code chunk of any language (```anything). Will raise an issue at lintr or languageserver.

@Ikuyadeu
Copy link
Copy Markdown
Member

@andycraig Thank you for your pull request.
The ThirdPartyNotices.txt contents look good.

@andycraig
Copy link
Copy Markdown
Collaborator Author

@Ikuyadeu Great, thank you!

@renkun-ken Thank you for testing!

but does not work with python code chunks (treating it like markdown content)

Rmd Python code chunk (```{python})

Markdown R code chunk (```python)

I'll open a new issue for Rmd code chunks like ```{python}`.

For me on Windows 10, Python markdown code chunks like ```python do work. That is, if I create a block

```python
var
```

and use the Toggle Line Comment command, the comment is a Python #, not an HTML <!-- -->. When you try this, the comment is an HTML comment?

The backticks works well but introduces an obvious drawback: Typing backticks to create a code chunk will never end up with three backticks but two or four.

Whoops, I missed that! I will add a commit to remove backticks from auto-closing pairs in R Markdown.

Thank you!

@renkun-ken
Copy link
Copy Markdown
Member

@andycraig Sorry, my mistake, ```python works as expected, both highlighing and commenting.

The backtick not auto-closing looks good now.

Everything LGTM. If you have nothing more to add, please feel free to merge.

@andycraig
Copy link
Copy Markdown
Collaborator Author

@renkun-ken Thank you for the checks! I'll go ahead and merge now.

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.

[Feature request] "Surround" support in RMarkdown files Wrong comment type in RMarkdown YAML frontmatter

3 participants