【问题标题】:Using HTML in YML yields [Objcet Object] in js-yaml在 YAML 中使用 HTML 在 js-yaml 中产生 [Object Object]
【发布时间】:2019-05-16 18:10:15
【问题描述】:

在 YML 中使用 HTML 会产生 [Objcet Object]

YML

context: fieldLabel: | <strong> Some Bold Text </strong> and now normal continued. 它呈现为

context: fieldLabel: ",[object Object], and now normal continued.↵" 但我希望我的输出应该是

context: { fieldLabel: '&lt;strong&gt;\n Some Bold Text\n&lt;/strong&gt; and now normal continued.\n' },

我的 JS 代码:

我的 JS 代码:

const tests = YAML.safeLoad(this.props.children,{json:true}); console.log("tests",...tests)

控制台输出:

context: fieldLabel: ",[object Object], and now normal continued.↵"

它以 [object Object] 的形式出现,而不是 &lt;strong&gt;\n Some Bold Text\n&lt;/strong&gt;

【问题讨论】:

    标签: javascript yaml remarkjs


    【解决方案1】:

    来自js-yaml docs

    safeLoad (string [ , options ])

    推荐的加载方式。将字符串解析为单个 YAML 文档。返回一个 JavaScript 对象或在出错时抛出 YAMLException。默认情况下,不支持正则表达式、函数和未定义。这种方法对于不受信任的数据是安全的。

    当您在 yaml 中包含非安全代码(即 HTML)时,看起来 js-yaml 正在给您一个错误。如果保证您的 yaml 是安全的,您可以使用 load() 进行非安全加载,或者您可以修改代码结构以更改 yaml 中存储的内容和不存储的内容。

    【讨论】:

      猜你喜欢
      • 2018-01-17
      • 2020-08-18
      • 2023-02-23
      • 2017-12-15
      • 1970-01-01
      • 1970-01-01
      • 2018-02-26
      • 2020-07-18
      • 1970-01-01
      相关资源
      最近更新 更多