Visual Studio 代码中缩进的片段
Snippets with indentation in Visual Studio Code
我正在尝试在 Visual Studio 代码中创建一个片段。这有效,但缺少缩进:
我的片段:
"HTML structure": {
"prefix": "html",
"body": [
"<!DOCTYPE html>",
"<html lang='fr'>",
"<head>",
"<meta charset='UTF-8'>",
"<meta name='viewport' content='width=device-width, initial-scale=1.0'>",
"<meta http-equiv='X-UA-Compatible' content='ie=edge'>",
"<title></title>",
"</head>",
"<body>",
"",
"</body>",
"</html>"
],
"description": "Base template for html file"
}
你所看到的:
<!DOCTYPE html>
<html lang='fr'>
<head>
<meta charset='UTF-8'>
<meta name='viewport' content='width=device-width, initial-scale=1.0'>
<meta http-equiv='X-UA-Compatible' content='ie=edge'>
<title>test</title>
</head>
<body>
test
</body>
</html>
我想要什么:
<!DOCTYPE html>
<html lang='fr'>
<head>
<meta charset='UTF-8'>
<meta name='viewport' content='width=device-width, initial-scale=1.0'>
<meta http-equiv='X-UA-Compatible' content='ie=edge'>
<title></title>
</head>
<body>
</body>
</html>
缩进需要在字符串的内部,而不是在外部(没有意义的地方),所以:
" <meta charset='UTF-8'>",
而不是:
"<meta charset='UTF-8'>",
这按预期工作:
"HTML structure": {
"prefix": "html",
"body": [
"<!DOCTYPE html>",
"<html lang='fr'>",
"<head>",
" <meta charset='UTF-8'>",
" <meta name='viewport' content='width=device-width, initial-scale=1.0'>",
" <meta http-equiv='X-UA-Compatible' content='ie=edge'>",
" <title></title>",
"</head>",
"<body>",
" ",
"</body>",
"</html>"
],
"description": "Base template for html file"
}
我认为更合适的方法是使用\t
而不是space来保持文档缩进均匀。
"\t<meta charset='UTF-8'>",
我正在尝试在 Visual Studio 代码中创建一个片段。这有效,但缺少缩进:
我的片段:
"HTML structure": {
"prefix": "html",
"body": [
"<!DOCTYPE html>",
"<html lang='fr'>",
"<head>",
"<meta charset='UTF-8'>",
"<meta name='viewport' content='width=device-width, initial-scale=1.0'>",
"<meta http-equiv='X-UA-Compatible' content='ie=edge'>",
"<title></title>",
"</head>",
"<body>",
"",
"</body>",
"</html>"
],
"description": "Base template for html file"
}
你所看到的:
<!DOCTYPE html>
<html lang='fr'>
<head>
<meta charset='UTF-8'>
<meta name='viewport' content='width=device-width, initial-scale=1.0'>
<meta http-equiv='X-UA-Compatible' content='ie=edge'>
<title>test</title>
</head>
<body>
test
</body>
</html>
我想要什么:
<!DOCTYPE html>
<html lang='fr'>
<head>
<meta charset='UTF-8'>
<meta name='viewport' content='width=device-width, initial-scale=1.0'>
<meta http-equiv='X-UA-Compatible' content='ie=edge'>
<title></title>
</head>
<body>
</body>
</html>
缩进需要在字符串的内部,而不是在外部(没有意义的地方),所以:
" <meta charset='UTF-8'>",
而不是:
"<meta charset='UTF-8'>",
这按预期工作:
"HTML structure": {
"prefix": "html",
"body": [
"<!DOCTYPE html>",
"<html lang='fr'>",
"<head>",
" <meta charset='UTF-8'>",
" <meta name='viewport' content='width=device-width, initial-scale=1.0'>",
" <meta http-equiv='X-UA-Compatible' content='ie=edge'>",
" <title></title>",
"</head>",
"<body>",
" ",
"</body>",
"</html>"
],
"description": "Base template for html file"
}
我认为更合适的方法是使用\t
而不是space来保持文档缩进均匀。
"\t<meta charset='UTF-8'>",