简体   繁体   English

如何使嵌套的 markdown 项目符号列表在 vscode 中具有不同的项目符号 styles

[英]How to make nested markdown bullet lists have different bullet styles in vscode

I want to have vscode render lists in markdown with bullet points instead of the asterisk (*) character, so that the top level would use •, the next one would use ◦, etc.我想让 markdown 中的 vscode 渲染列表带有项目符号点而不是星号 (*) 字符,这样顶层将使用 •,下一个将使用 ◦,等等。

My first approach was to create a ligature font with FontForge that replaced * with ◦, space plus * with ◦, two spaces plus * with ▪, and so on, but using ligatures has the obvious issue that it's not context-sensitive, so all asterisks would be replaced, not just the ones leading a line.我的第一种方法是用 FontForge 创建一个连字字体,将 * 替换为 ◦,空格加 * 替换为 ◦,两个空格加 * 替换为 ▪,等等,但是使用连字有一个明显的问题,即它不是上下文敏感的,所以所有星号将被替换,而不仅仅是领先一行的星号。

Looking at the vscode text decoration API , it seems limited to just changing the font style and color, and not the font family.查看vscode 文本装饰 API ,似乎仅限于更改字体样式和颜色,而不是字体系列。 Is there some way to visually replace the characters in vscode?有什么方法可以直观地替换 vscode 中的字符吗? They should still be saved as asterisks in the source code to be valid markdown.它们仍应在源代码中保存为星号才能有效 markdown。

As of VS Code 1.27, your best bet is to write an extension that adds decorators on the * characters to do this. 从VS Code 1.27开始,最好的办法是编写一个扩展名,在*字符上添加装饰符以实现此目的。 Take a look at the decorator example extension to get started 查看装饰器示例扩展以开始

I do not think the current vscode API allows you to overwrite the * text itself, but you can try emulate this by making the * character transparent and adding your custom bullet point after it: 我不认为当前的vscode API允许您覆盖*文本本身,但是您可以通过使*字符透明并在其后添加自定义项目符号点来尝试模仿此文本:

const level1DecorationType = vscode.window.createTextEditorDecorationType({
    color: 'transparent',
    after: {
        contentText: "◦"
    }
});

Then your extension just has to apply this style to the bullet points in the document. 然后,您的扩展程序只需要将此样式应用于文档中的项目符号点即可。

Unofficially, you can also use this decorator hack to replace the * character entirely: 非官方地,您还可以使用此装饰器技巧完全替换*字符:

const level1DecorationType = vscode.window.createTextEditorDecorationType({
    color: 'transparent',
    textDecoration: `none; display: inline-block; width: 0;`,
    after: {
        contentText: "◦"
    }
});

However that is not guaranteed to work properly or continue working in the future. 但是,这不能保证正常工作或将来继续工作。

Consider opening a feature request to get better decorators support for this 考虑打开功能请求以获得更好的装饰器对此的支持

Why not do this为什么不这样做

<ul>
    <li>Simple Function to create a column named "status". 
    <ul>
        <li style="list-style-type: upper-roman;">0 = Same</li>
        <li>1 = Swap</li>
        <li>0 = Changed</li>
    </ul>
    </li>
</ul>

You could use Images as well;您也可以使用图像;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM