python highlighting in Rmarkdown in RStudio

﹥>﹥吖頭↗ 提交于 2019-12-21 02:01:06

问题


I'm using RStudio 0.98.1103. It is said in release notes that they've 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 don't get proper highlighting (like I have here). I've seen this question: Syntax highlighting for Python chunks does not work - but I guess it was asked before the release of 0.98.1103 and things could've change, I'm just doing something wrong.

Could anyone help me out?


回答1:


output: 
  html_document:
    highlight: pygments

in the head did the trick.




回答2:


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

What they are referring to in the release notes is syntax highlighting in the source code editor. Open an existing Python source file in the editor and you will see it is correctly highlighted.

Language-dependent syntax highlighting is usually selected based on the underlying language of the file you are editing (often simply based on the filename extension). In your example, you are editing a .RMd file, so the editor uses the syntax rules for r-markdown.



来源:https://stackoverflow.com/questions/29520780/python-highlighting-in-rmarkdown-in-rstudio

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!