javascript - 在 YAML 中使用 HTML 会生成 js-yaml 中的 [Object Object]

标签 javascript yaml remarkjs

我在 YML 中使用 HTML 生成 [Object Object]

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

渲染为

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

但我希望我的输出是

context: { fieldLabel: '<strong>\n    Some Bold Text\n</strong> and now normal continued.\n' },

我的 JS 代码:

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

控制台输出:

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

它以 [object Object] 的形式出现,而不是 <strong>\n Some Bold Text\n</strong>

最佳答案

来自js-yaml docs :

safeLoad (string [ , options ])

Recommended loading way. Parses string as single YAML document. Returns a JavaScript object or throws YAMLException on error. By default, does not support regexps, functions and undefined. This method is safe for untrusted data.

由于您在 yaml 中包含非安全代码(即 HTML),因此 js-yaml 似乎给您带来了错误。如果您的 yaml 保证安全,您可以使用 load() 进行非安全加载,或者您可以修改代码结构以更改 yaml 中存储的内容和不存储的内容.

关于javascript - 在 YAML 中使用 HTML 会生成 js-yaml 中的 [Object Object],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53797217/

相关文章:

bash - 使用 bash 递归合并 yaml 配置文件

css - 增量幻灯片不适用于两列布局

javascript - 尝试运行空白 ionic 启动应用程序时,我收到 Cordova 错误 "Failed to load resource"

c# - 在 javascript 函数中添加脚本 src

javascript - 单击具有不同类名称的另一行时隐藏/显示具有特定类名称的表行? Angular 2

docker - 设置 Apache Airflow 时无法执行脚本 docker-compose

javascript - 从单独的网络访问 Node.js 服务器

yaml - "on"和 "off"在 YAML 1.2 中应该被解释为 true 还是 false?

css - xaringan:减少输入和输出之间的垂直空间?

r - 在 Xaringan 中保留 <- 或 != 等字符序列,防止替换