1

I need to change a text color of a code cell (namely code cell, not just a text block) that is defined using "`" symbols in Markdown. All my attempts have failed and the color stays the same, which is by default black

I have tried to use <font color="...">...<\font> attribute and also <span style="color:...;">...<\span> attribute. All of them didn't work and the text is still the same as on the attached image. How can I solve this problem and finally change the color to whatever I want? Code cell which text I want to change

  • check out this post https://stackoverflow.com/questions/19746350/how-to-change-color-in-markdown-cells-ipython-jupyter-notebook – Your_Card_was_Declined Apr 24 '23 at 00:12
  • @Your_Card_was_Declined the answer in the post you provided works perfectly for text blocks, but I need to change the color of the text in the code cell (see the first sentence of my question); the solution in the post does not work in my case, unfortunately – olesatthewheel Apr 24 '23 at 09:45

3 Answers3

1

If you want to add syntax highlighting to a programming language, it can be written like this:

# For example, you want to use Python

```python
print("the syntax is highlighted")
```

The result would be like this:

print("the syntax is highlighted")

EDIT:

As far as I know, Markdown doesn't support color. So what you'll need is wrap the code cell as HTML.

Instead of this:

`some beautiful text here`

You would want to write this:

<code>some beautiful text here</code>

And then add the span tag to change the color:

<code>some <span style='color:blue'>beautiful</span> text here</code>

At this point, the word 'beautiful' will change to blue.

It works on my VSCode Markdown viewer. But different app will render Markdown differently.

Faiz Byputra
  • 11
  • 1
  • 2
  • I'm sorry, but you might misunderstood my question. I need to change the color of text in a code cell, but your solution doesn't provide anything related to color changing – olesatthewheel May 07 '23 at 08:30
  • Sorry for the mistake. I'd already made an edit on the answer. Hope that's what you mean and hope it could help you – Faiz Byputra May 07 '23 at 16:39
0

I tried the span without closing tags and it worked. Are you running on jupyter notebook locally?

<span style="color: red;">testing 

<span style="color: blue;">testing 
    

result

Mystery
  • 61
  • 4
  • I'm sorry, but I'm talking about code cell and not a text block. If you turn "testing" in code cell (I wrote that in the first sentence of my question) and apply , there won't be any changes – olesatthewheel Apr 23 '23 at 21:45
  • @olesatthewheel sorry, I hadn't understood that. I think it's not possible to change the color of a code cell on vanilla jupyter, maybe you could try to search for a plugin for specific code highlighting. – Mystery Apr 23 '23 at 21:57
0

for change text color of a code cell:

<span style="color: green">Hello</span>

  • I'm sorry, but the code you provided works only for text blocks. If I write `Hello` and "Hello" becomes a code cell, the color of the text in the cell will be still be black – olesatthewheel Apr 24 '23 at 09:11