我们应该逃避或不逃避生活在YAML文件中的HTML标记中的双引号吗?

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

我对是否应该在YAML文件中的HTML标记内转义双引号感到困惑。

playing_with_cards_html: Playing your best game with %{card_type} between now and <span class="best-card">%{worst_card}</span>.

它看起来是有效的YAML,但如果我们为双引号添加转义字符:

playing_with_cards_html: Playing your best game with %{card_type} between now and <span class=\"best-card\">%{worst_card}</span>.

它还能正确呈现吗?

escaping double yaml double-quotes
1个回答
1
投票

它可能无法正确呈现,除非加载YAML的程序在加载的字符串上执行一些反斜杠转义。

密钥playing_with_cards_html的值是plain scalar。在这些标量中没有定义反斜杠转义:每个字符都按原样拍摄。因此,URL的第二个版本实际上有两个额外的字符(都是\),并且可能无法按需要呈现。

只有当标量本身为double quoted(即以双引号开头和结尾)时,才能在YAML中转义反斜杠。在这种情况下,你必须用反斜杠来逃避标量中间的任何双引号。

© www.soinside.com 2019 - 2024. All rights reserved.