How to add color to Github's README.md file

后端 未结 10 798
一生所求
一生所求 2020-11-27 09:00

I have a README.md file for my project underscore-cli, a pretty sweet tool for hacking JSON and JS on the command-line.

I want to document the -

相关标签:
10条回答
  • 2020-11-27 09:26

    It's worth mentioning that you can add some colour in a README using a placeholder image service. For example if you wanted to provide a list of colours for reference:

    - ![#f03c15](https://via.placeholder.com/15/f03c15/000000?text=+) `#f03c15`
    - ![#c5f015](https://via.placeholder.com/15/c5f015/000000?text=+) `#c5f015`
    - ![#1589F0](https://via.placeholder.com/15/1589F0/000000?text=+) `#1589F0`
    

    Produces:

    • #f03c15 #f03c15
    • #c5f015 #c5f015
    • #1589F0 #1589F0
    0 讨论(0)
  • 2020-11-27 09:29

    Here is the code you can write color texts

    <h3 style="color:#ff0000">Danger</h3>
    
    0 讨论(0)
  • 2020-11-27 09:30

    I'm inclined to agree with Qwertman that it's not currently possible to specify color for text in GitHub markdown, at least not through HTML.

    GitHub does allow some HTML elements and attributes, but only certain ones (see their documentation about their HTML sanitization). They do allow p and div tags, as well as color attribute. However, when I tried using them in a markdown document on GitHub, it didn't work. I tried the following (among other variations), and they didn't work:

    • <p style='color:red'>This is some red text.</p>
    • <font color="red">This is some text!</font>
    • These are <b style='color:red'>red words</b>.

    As Qwertman suggested, if you really must use color you could do it in a README.html and refer them to it.

    0 讨论(0)
  • 2020-11-27 09:31

    You cannot color plain text in a GitHub README.md file. You can however add color to code samples with the tags below.

    To do this just add tags such as these samples to your README.md file:

    ```json
       // code for coloring
    ```
    ```html
       // code for coloring
    ```
    ```js
       // code for coloring
    ```
    ```css
       // code for coloring
    ```
    // etc.
    

    No "pre" or "code" tags needed.

    This is covered in the GitHub Markdown documentation (about half way down the page, there's an example using Ruby). GitHub uses Linguist to identify and highlight syntax - you can find a full list of supported languages (as well as their markdown keywords) over in the Linguist's YAML file.

    0 讨论(0)
  • 2020-11-27 09:32

    You can use the diff language tag to generate some colored text:

    ```diff
    - text in red
    + text in green
    ! text in orange
    # text in gray
    @@ text in purple (and bold)@@
    ```
    

    However, it adds it as a new line starting with either - + ! # or starts and ends with @@

    enter image description here

    This issue was raised in github markup #369, but they haven't made any change in decision since then (2014).

    0 讨论(0)
  • 2020-11-27 09:35

    As of writing, Github Markdown renders color codes like `#ffffff` (note the backticks!) with a color preview. Just use a color code and surround it with backticks.

    For example:

    becomes

    0 讨论(0)
提交回复
热议问题