Search code examples
pythonjupyter-notebookmarkdown

How to change a text color of a code cell in Markdown?


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


Solution

  • 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.