Can RStudioAPI distinguish between markdown text and code chunks?

I'm being a bit lazy here but I haven't managed to find an answer in the documentation I've found so far, so I'm straight out asking for help :grinning:

I want to make a styler-type add-in that puts each sentence on a new line within the text sections of an RMarkdown file, probably by doing a find and replace on ". " ... you get the picture. But it wouldn't be a good idea to apply that find and replace to R code!

The styler documentation suggests that it can work with .Rmd files, but equally it says it only styles R source code, not the markdown text.

Is there a way of setting the scope of an add-in like the one I want to make, so it only operates outside of R code chunks?

I don't think so, you probably have to detect it yourself. We do this in styler. On the other hand, I know it's not quite what you asked for but you could also have a look at https://github.com/lorenzwalthert/stylermd that prettifies markdown.

1 Like

Not as a native rstudioapi feature. You might look at how knitr does it:

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