backstage / mkdocs-techdocs-core

The core MkDocs plugin used by Backstage's TechDocs as a wrapper around multiple MkDocs plugins and Python Markdown extensions
Apache License 2.0
83 stars 61 forks source link

fix: fix broken template_metadata.json for multiline strings #58

Closed pjungermann closed 2 years ago

pjungermann commented 2 years ago

Before, the jinja template was constructing the output JSON manually injecting values from the config object as simple values.

This worked well as long as the values did not contain any special characters like newlines. Hence, it causes invalid JSON to be rendered in case of multiline strings as values, e.g. passed as argument for site_description which was the use case at the bug report at backstage/backstage issue #10277. Other special characters like double-quotes could have caused a similar effect.

This change introduces a test to reproduce the case and provides a new jinja template which makes use of the tojson filter introduced in jinja 2 to generate valid JSON.

As previously, the values have been expected to be of type string, the string filter is used for values on top to guarantee this. (E.g., a numeric value passed as value would still result in a string value at the rendered JSON.)

Closes: #57 Relates-to: backstage/backstage issue #10277 Signed-off-by: Patrick Jungermann Patrick.Jungermann@gmail.com