custom syntax highlighting rmd - syntax-highlighting

I would like to be able to customize the syntax highlighting used with RMarkdown so that I can, for example, draw attention to functions coming from a certain package.
I noticed an option mentioned in the knitr NEWS document which says this option can be set via:
opts_knit$set(highr.opts = list(markup = cmd_mine))
for .Rnw and .Rhtml documents. However, when I set this option in my .Rmd file (simplified here to messing with the highlight for numerical constants)
```{r setup, include=TRUE}
# set global chunk options
library(knitr)
opts_chunk$set(cache=TRUE)
library(highr)
cmd_mine = highr:::cmd_html
cmd_mine[rownames(cmd_mine)=="NUM_CONST", 1] <- '<span class="three">'
opts_knit$set(highr.opts = list(markup = cmd_mine))
cmd_mine
sum(1:2)
```
I see no change. This leads me to understand that this option is not implemented for .Rmd, or that I've misunderstood how the option works. If it doesn't exist, it'd be great if it could someday! If it does, I'd appreciate any suggestions. Thanks!
PS: in fact, I tried to set this for an .Rhtml document and also had no success...

The syntax highlighting in knitr only works for LaTeX (.Rnw) and HTML (.Rhtml). It does not apply to R Markdown (.Rmd).
If it does not work for .Rhtml, it could be a bug. But keep in mind that even if it works, you may not see it. It depends on what style you defined for span.three in CSS. Some screenshots and a minimal reproducible example (plus sessionInfo()) will be helpful.

Related

Silly suggestions SASS VS Code

I don't want to turn suggestions off altogether. I just want them to not be this dumb. How do I tell VS Code to stop doing this when editing SASS? It is really weird because I don't find things like variable names being suggested. Current functionality yields only these type of annoyances, and I've got the useful "editor.acceptSuggestionOnCommitCharacter": false already, which greatly improved experiences when editing JS and HTML, JSON and more. But, here, this setting seems ignored.
Perhaps the answer I'm looking for is to the question, "Where are these red($color) suggestions coming from and how do I turn that off?"
BTW, my example with the string value "red" is something I do just to make it really obvious my SASS is being compiled/watched.
There are a bunch of suggestions you can turn off in settings. For example:
Editor > Suggest: Show Colors is true by default, disabling it you won't get those color suggestions anymore.
Under Editor > Suggest: ... there are lots more you might want to disable.

Bold code in rst

How can I get code (monospace) text that is bold in rst (I'm using Sphinx)? Anything in :: seems to be rendered literally, as with ``, so ``**bold**`` doesn't work.
In general, nested inline markup is not possible in reStructuredText. There are more or less ugly workarounds, such as using raw HTML. Like this:
.. raw:: html
<div>Some stuff <pre>some <b>bold</b> text</pre>...</div>
Actually using raw for code is a very bad thing to do as it ignores the beautiful Pygments highlighting and complicates things to extreme. First thing to do is to play with different Pygments highlighting styles. You can find a functional demo here. Then you may set the appropriate highlighting in conf.py. If none of the styles make the desired part of your code bold, you may consider creating your own Pygments theme, which is unfamiliar territory for me, but shouldn't be that hard.
There is third thing to try though, you could look up the class of the word you need to highlight and add a rule to your CSS. Pygments produce this seemingly gibberish classes like nv, ls, etc for every type of the highlighted words. But keep in mind, that every instance of this type will be highlighted. If your chosen word is a class definition - all class definitions will be highlighted.
Only if none of these options apply should you consider using something as atrocious as raw, because every time someone uses raw, Sphinx dies a little. Do you really want Sphinx to die?
Most likely restructured text does not support formatting options you are asking for.
However you are free to add your own :: admonition directives which have custom CSS styling over them.
Example for a custom block and CSS styling. RST:
.. admonition:: foobar
My custom text here
CSS:
.admonition-foobar {
font-weight: bold;
}

text highlight in markdown

Within a Markdown editor I want to support text highlight, not in the sense of code highlighting, but the type of highlighting people do on books.
In code oriented sites people can use backquotes for a grey background, normally inline code within a paragraph. However on books there is the marker pen for normal text within a paragraph. That is the classical black text on yellow background.
Is there any syntax within Markdown (or its variants) to specify that the user want that type of highlight? I want to preserve the backquotes syntax for code related marking, but also want a way to enable highlighted user text
My first thought is just using double backquotes, since triple backquotes are reserved for code blocks. I am just wondering if other implementations have already decided a syntax for it... I would also appreciate if someone could justify if this is a very bad idea.
As the markdown documentation states, it is fine to use HTML if you need a feature that is not part of Markdown.
HTML5 supports
<mark>Marked text</mark>
Else you can use span as suggested by Rad Lexus
<span style="background-color: #FFFF00">Marked text</span>
I'm late to the party but it seems like a couple of markdown platforms (Quilt & iA Writer) are using a double equal to show highlighting.
==highlight==
Typora is also using double equal for highlighting. It would be nice it that becomes a CommonMark standard, as mentioned by DirtyF. It would be nice for those who use it frequently, since it is only 4 repeated chars: ==highlight==
If you want the option to use multiple editors, it may be best to stick with <mark>highlight</mark> for now, as answered by Matthias.
Here is the latest spec from CommonMark, "which attempts to specify Markdown syntax unambiguously". Currently "highlighting" is not included.
Editors using ==highlight== from comments mentioned previously:
Typora
Obsidian
Quilt
IA Writer
Feel free to add to this list.
You can use the Grave accent (backtick) ` to highlight text in markdown
Highlighted text
Also works with VS Code extension markdownlint
Grey-colored Higlighting Solution
A possible solution is to use the <code> element:
This solution works really well on git/github, because git/github doesn't allow css styling.
OBS!:
Using the code-element for highlighting is not semantic.
However, it is a possible solution for adding grey-colored highlighting to text in markdown.
Markdown/HTML
<code> <i>This text will be italic</i> <b>this text will be bold</b> </code>
Output
This text will be italic this text will be bold
Roam markdown uses double-caret: ^^highlight^^. Andrew Shell's answer mentions double-equals.
The accepted and clearly correct answer is <mark> from Matthias above, but I thought I had seen carets in some other flavor of markdown. Maybe not. I want to transform my ^^highlights^^ to <mark>highlights</mark> in pandoc conversion to html, and somehow ended up here...
Probably best bet is just use html e.g
<pre><b>Hello</b> is higlighted</pre>
Hello is higlighted
Remember nearly all html is valid in markdown too.

I'm working on a Pro*C syntax highlighting file for Sublime Text 2

Is there any way to include the color highlighting rules in the tmLanguage file itself?
For those who aren't familiar with it, Pro*C is sort of this mutant hybrid love-child of SQL and C, and both syntaxes are present in the file. However, there are a few Pro*C specific keyword which start or stop a big long block of SQL inside of one.
What I would like to do, is have the Pro*C keywords be different colors than the C/SQL keywords, and for the SQL blocks to have a different background color, so that they stand out. In none of the common themes are there appropriate scopes to use for this, not that I can tell. So I can't just call the Pro*C keywords "keyword.source.some-differently-colored language" (they should really be keyword.source.pro-c anyway) or the blocks "text.whatever.another-color" (using meta.block.pro-c right now).
It would be useful if I could just include the colors for these elements in the same plist that defines the syntax. Is this possible in Sublime? What's the correct way to do this?
As far as I understand it, you would have to modify the color scheme file to support what you want. Bundling the colors as part of the tmLanguage file doesn't make sense anyways. By doing that, you would basically be saying every user has to use your predefined colors, which I could imagine people wouldn't like. For example, let's say I have a white background, and you decide to make the text color white. It would look like there is nothing there.
I think the best route is to include sample "extension" of the color scheme file. Then allow the users to modify it themselves as they see fit. This would also let you use the standard naming conventions, so if they don't apply any new scopes, everything still looks okay. Of course, they can specify a more detailed scope in the scheme file to apply the proper text color/background.
What I think would be nice was if there was some way to simply extend a color scheme from a separate file, rather than needing to modify the original. Though that doesn't exist.

Adding Code Samples to A Slideshow Presentation

I'm making my first technical presentation, and I'd like to add some code samples (ruby in my case). What's the smart way to have nicely formatted with color code samples?
For example, when I code VIM looks like the attached image. I'd like to duplicate something similar in my presentation without manually changing the colors of characters.
MagicPoint can easily include images into slides, so if you've got screenshots of your code (as you do here), you can simply:
%image "index.png"
inside your slide's content.
If you're looking to avoid taking manual screenshots, you can probably convince Google Code Prettify or coderay to emit output in some format that can be used with MagicPoint's %filter command.
When I had to do that, I used PDF-Latex with the class "beamer" for the presentation and the package "listings" for code samples. It supports syntax highlighting including colors for Ruby.
After some initial learning, it worked like a charm.

Resources