14

I frequently need to paste a code section into a Markdown document and then I want to change some color in the text.

For example:

This is a code sample:
```
#include <stdio.h>

int main(void) {
    printf("Hello World!\n");
    return 0;
}
```

How can I set the text string "Hello World!" to the color red? I wish to use it as a code block since I don't want to reformat it to Markdown style.

slang
  • 626
  • 7
  • 26
lucky1928
  • 8,708
  • 10
  • 43
  • 92
  • Possible duplicate of [How to apply Color in markdown](http://stackoverflow.com/questions/35465557/how-to-apply-color-in-markdown) – mb21 Jan 29 '17 at 17:17
  • You may want to look at "syntax highlighting". There are a lot of options out there and providing tool/library recommendations is off-topic, but that should be a good search term to get you started. – Waylan Jan 30 '17 at 02:01
  • 4
    @mb21 I would not necessarily consider this a duplicate. It is quite common to add color to code blocks through syntax highlighting. Of course, if the OP only wants to color a single string and not apply highlighting to the entire code block, then yes this would be a duplicate. Unfortunately, we don't have enough information to know for sure. – Waylan Jan 30 '17 at 14:30

1 Answers1

20

You can't put color on it.

Try putting C like this:

```c
#include <stdio.h>

int main(void) {
    printf("Hello World!\n");
    return 0;
}
```

It will make your text seems as code.

Igor F.
  • 2,649
  • 2
  • 31
  • 39
Villghust
  • 301
  • 2
  • 4