Jer*_*emy 5 visual-studio-code vscode-snippets
我正在尝试在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>$1</title>",
"</head>",
"<body>",
"$2",
"</body>",
"</html>"
],
"description": "Base template for html file"
}
Run Code Online (Sandbox Code Playgroud)
你看到什么了 :
<!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>
Run Code Online (Sandbox Code Playgroud)
我想要的是什么:
<!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>
Run Code Online (Sandbox Code Playgroud)
缩进需要在字符串内部,而不是在外部(它没有意义),所以:
" <meta charset='UTF-8'>",
Run Code Online (Sandbox Code Playgroud)
代替:
"<meta charset='UTF-8'>",
Run Code Online (Sandbox Code Playgroud)
这按预期工作:
"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>$1</title>",
"</head>",
"<body>",
" $2",
"</body>",
"</html>"
],
"description": "Base template for html file"
}
Run Code Online (Sandbox Code Playgroud)
我认为更合适的方法是\t甚至使用空间来保持文档缩进。
"\t<meta charset='UTF-8'>",
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2356 次 |
| 最近记录: |