Style Inline R Notebook Code with same formatting as R Notebook code chunk

Hello Everyone!

I'm trying to style the inline code in my HTML R Markdown notebook to look like the code chunks in RStudio. In RStudio, the code chunks have different colors for functions, packages, etc., but when I render my R Markdown file to HTML, the inline code doesn't have the same styling. Does anyone know how to apply similar syntax highlighting to the inline code in the HTML output? Any resources or guidance on how to achieve this would be appreciated!

For example:
On the left is the RStudio formatting I used (notice different colors for functions and packages) and on the right is the R markdown html output file.

What is more interesting, just picking a random example from the Advanced R book gives some text of text with colored results:

While there are some nice pre-defined class outputs defined in the R Markdown cookbook, it looks like they are limited to changing the background color.

I was messing around and had some success getting inline hooks and the highr package working, but I was wondering if there is something a bit more straight forward available?

1 Like

To achieve similar syntax highlighting for inline code in HTML R Markdown as seen in RStudio, you can use custom CSS to style the inline code. This allows you to replicate the colors and formatting. Additionally, explore rmarkdown's syntax highlighting options and consider combining highr with your custom CSS for more precise control. May Allah grant you success in your project!

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.