我有一个自述文件。md文件用于我的项目underscore-cli,我想记录——color标志。

目前,做到这一点的唯一方法是截图(可以存储在项目存储库中):

但截图不是文本,防止读者复制/粘贴截图中的命令。创建/编辑/维护它们也很麻烦,而且浏览器加载速度较慢。现代网络使用文本样式,而不是一堆渲染的文本图像。

虽然一些Markdown解析器支持内联HTML样式,但GitHub不支持;这行不通:

<span style="color: green"> Some green text </span>

这行不通:

<font color="green"> Some green text </font>

当前回答

问题是“如何在github readme中为文本上色” 哪一个是困难的/不可能的

跑题:在github的问题上,我们可以用

<span color="red">red</span>

例子:

#!/bin/bash

# Convert ANSI-colored terminal output to GitHub Markdown

# To colorize text on GitHub, we use <span color="red">red</span>, etc.
# Depends on:
#   aha: convert terminal colors to html
#   xclip: copy the result to clipboard
# License: CC0-1.0
# Note: some tools may need other arguments than `--color=always`
# Sample use: colors-to-github.sh diff a.txt b.txt

cmd="$1"
shift # now the arguments are in $@
(
    echo '<pre>'
    $cmd --color=always "$@" 2>&1 | aha --no-header
    echo '</pre>'
) \
| sed -E 's/<span style="[^"]*color:([^;"]+);"/<span color="\1"/g' \
| sed -E 's/ style="[^"]*"//g' \
| xclip -i -sel clipboard

其他回答

向README添加颜色的一种方法是利用提供占位符图像的服务。

例如,Markdown可以使用:

- ![#f03c15](https://placehold.co/15x15/f03c15/f03c15.png) `#f03c15`
- ![#c5f015](https://placehold.co/15x15/c5f015/c5f015.png) `#c5f015`
- ![#1589F0](https://placehold.co/15x15/1589F0/1589F0.png) `#1589F0`

创建一个你喜欢的颜色列表:

# f03c15 # c5f015 # 1589F0

在GitHub README中为文本着色。md,可以使用SVG <text>

<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 55 20" fill="none">
    <text x="0" y="15" fill="#4285f4">G</text>
    <text x="12" y="15" fill="#ea4335">o</text>
    <text x="21" y="15" fill="#fbbc05">o</text>
    <text x="30" y="15" fill="#4285f4">g</text>
    <text x="40" y="15" fill="#389738">l</text>
    <text x="45" y="15" fill="#ea4335">e</text>
</svg>

在使用自定义颜色制作自定义文本之后,保存SVG文件并按照以下步骤操作。

在GitHub上打开你的存储库。 单击README.md的“编辑”按钮 将SVG文件拖放到打开的在线编辑器中。GitHub将生成一个降价图像。大致如下。 (谷歌)! (https://user-images.githubusercontent.com/000/000-aaa.svg) 如果您想改变SVG的原始大小,可以使用生成的URL作为<img/>标记的src,并给出所需的大小。 <img height="100px" src="https://user-images.githubusercontent.com/000/000-aaa.svg" alt=""/> .

可能不是问题的确切答案,但当我处于OP的情况下,我正在寻找下面的解决方案:

简单地用:

[![](https://img.shields.io/badge/github-blue?style=for-the-badge)](https://github.com/hamzamohdzubair/redant)
[![](https://img.shields.io/badge/book-blueviolet?style=for-the-badge)](https://hamzamohdzubair.github.io/redant/)
[![](https://img.shields.io/badge/API-yellow?style=for-the-badge)](https://docs.rs/crate/redant/latest)
[![](https://img.shields.io/badge/Crates.io-orange?style=for-the-badge)](https://crates.io/crates/redant)
[![](https://img.shields.io/badge/Lib.rs-lightgrey?style=for-the-badge)](https://lib.rs/crates/redant)

GitHub默默地增加了对> __Note__和> __Warning__语法的支持:

如果你想要着色超过1个词,那么我发现这是最方便的方法来着色文本在Github乳胶。

$\color{lightblue}{\textrm{Red Nimetaga 3 kõige suuremat pilveteenuste pakkujat}}$

示例Github可用在这里