Python markup in Rmarkdown in RStudio

I am using RStudio 0.98.1103. The release notes say they added "Syntax highlighting modes for XML, YAML, SQL, Python, and shell scripts." But when I write something like this:

```{r engine='python', highlight=TRUE} print("Hello World") ``` 

- I do not get the correct selection (for example, I have it here). I saw this question: syntax highlighting for pieces of Python does not work - but I think it was asked before 0.98.1103 was released, and everything could change, I'm just doing something wrong.

Can anyone help me out?

+6
source share
2 answers
 output: html_document: highlight: pygments 

in my head did the trick.

+5
source

The engine option tells knitr which language to use to actually run the code snippet.

In the release notes, they mean syntax highlighting in the source editor. Open the existing Python source file in the editor and you will see that it is correctly selected.

The allocation of language-dependent syntax is usually selected based on the main language of the file being edited (often simply based on the file name extension). In your example, you are editing the .RMd file, so the editor uses the syntax rules for r-markdown.

0
source

Source: https://habr.com/ru/post/984857/


All Articles