格式化函数条带 php 个变量
Format function strips php variables
我试图在字符串中传递参数,但由于某种原因,format
函数删除了可变部分($data
和 $test
)
import os
import textwrap
def reformat(template):
#return template
return textwrap.dedent(template).lstrip()
initial = "$data['completitions'] = [$test];"
scopes = 'meta.embedded.block.php, source.php'
tabTrig = 'doc'
template = reformat(
"""
<snippet>
\t<content><![CDATA[
\t{0}
\t]]></content>
\t<tabTrigger>{2}</tabTrigger>
\t<scope>{1}</scope>
</snippet>
""".format(initial, scopes, tabTrig))
v.run_command("insert_snippet", {"contents": template})
当前输出
<snippet>
<content><![CDATA[
['completitions'] = []; // NOTICE HERE
]]></content>
<tabTrigger>doc</tabTrigger>
<scope>meta.embedded.block.php, source.php</scope>
</snippet>
预期输出
<snippet>
<content><![CDATA[
$data['completitions'] = [$test]; // NOTICE HERE
]]></content>
<tabTrigger>doc</tabTrigger>
<scope>meta.embedded.block.php, source.php</scope>
</snippet>
看起来它可能正在将 $data
和 $test
视为变量并将它们解析为空字符串。您可以尝试使用 $
或 $$
转义每个 $
吗?
我试图在字符串中传递参数,但由于某种原因,format
函数删除了可变部分($data
和 $test
)
import os
import textwrap
def reformat(template):
#return template
return textwrap.dedent(template).lstrip()
initial = "$data['completitions'] = [$test];"
scopes = 'meta.embedded.block.php, source.php'
tabTrig = 'doc'
template = reformat(
"""
<snippet>
\t<content><![CDATA[
\t{0}
\t]]></content>
\t<tabTrigger>{2}</tabTrigger>
\t<scope>{1}</scope>
</snippet>
""".format(initial, scopes, tabTrig))
v.run_command("insert_snippet", {"contents": template})
当前输出
<snippet>
<content><![CDATA[
['completitions'] = []; // NOTICE HERE
]]></content>
<tabTrigger>doc</tabTrigger>
<scope>meta.embedded.block.php, source.php</scope>
</snippet>
预期输出
<snippet>
<content><![CDATA[
$data['completitions'] = [$test]; // NOTICE HERE
]]></content>
<tabTrigger>doc</tabTrigger>
<scope>meta.embedded.block.php, source.php</scope>
</snippet>
看起来它可能正在将 $data
和 $test
视为变量并将它们解析为空字符串。您可以尝试使用 $
或 $$
转义每个 $
吗?