2

I'm using HTML in YML yields [Object Object]

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

It's rendering as

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

but I want my output to be

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

My JS Code :

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

Console output :

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

It is coming as [object Object] instead of <strong>\n Some Bold Text\n</strong>

zb226
  • 9,586
  • 6
  • 49
  • 79
Prashanth
  • 1,309
  • 2
  • 9
  • 17

1 Answers1

2

From the 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.

As you're including non-safe code (i.e. HTML) in your yaml, it looks like js-yaml is giving you an error instead. You can do a non-safe load with load() instead, if your yaml is guaranteed to be safe, or you could modify the structure of your code to change what's stored in yaml and what isn't.

Joundill
  • 6,828
  • 12
  • 36
  • 50