是否有任何 VSCode 设置使用 synthax '/>' 而不是 '>' 来关闭 PHP 文件的自关闭标签?

问题描述 投票:0回答:0

我使用 VSCode,当我用 PHP 编写代码时,自动完成时自动结束的标签会自动以“>”结尾,我希望它们以“/>”结尾,这样我的代码就是有效的 XML。

总而言之,我想要一个 img 自关闭标签,vscode 为我提供了

<img src="" alt=''/>
而不是
<img src="" alt=''>

有没有人有解决这个问题的想法?

我设法通过在我的 settings.json 中添加它来在 HTML 文件中做到这一点:

"emmet.syntaxProfiles": {
        "html": "xml"
    },

但它不适用于 PHP 文件,所以我尝试将这段代码插入到我的 settings.json 中:

"auto-close-tag.customTagShortcuts": [
    {
        "tag": "img",
        "label": "img",
        "description": "img tag",
        "snippet": "<img src="$1" alt="$2" />"
    },
    {
        "tag": "hr",
        "label": "hr",
        "description": "hr tag",
        "snippet": "<hr />"
    },
    // Add here the self-closing tag with the syntax "/>"
    {
        "tag": "test",
        "label": "test",
        "description": "test tag",
        "snippet": "<test />"
    }
]

但它仍然没有用所以我也测试了这个:

"auto-close-tag.rules": [
    {
        "filetypes": [ "php"],
        "before": "/>",
        "after": ""
    }
]

但没有结果,因为它告诉我“未知配置设置”。

php html xml visual-studio-code tags
© www.soinside.com 2019 - 2024. All rights reserved.