RTE script tags

I’m trying to save structured data using the RTE code view. The structured data is json inside a <script type="application/ld+json"></script> tag.

Umbraco strips the content I presume b/c it’s wrapped in a script tag.

I’ve tried changing these configs in appsettings…

Umbraco.CMS.RichTextEditor.ValidElements : “…#script[src|async|defer|type|charset|id|class|style|*]”

and

Umbraco.CMS.Global.SanitizeTinyMce : false

I understand why it’s blocked, just wondering if there’s any workaround for this use case.

Hi @benehudson

It’s stripped out by default as adding script in an RTE is a security concern. Are you able to add your structured JSON using another means rather than relying on adding via an RTE (I don’t know your use case?).

The only solution is to amend the ValidElements as you already have done to ensure it doesn’t get stripped out by TinyMCE. I would suggest you would be better off putting your structured JSON in a separate property as the RTE is not really the best place for it.

Justin

Hi Ben,

The issue with your ValidElements config is the at the start that’s not valid syntax and won’t preserve the existing default elements. You need to copy the entire default ValidElements string from the Umbraco v13 RTE config docs and append ,script[*] at the very end. Also make sure to restart the app after any appsettings.json change, as settings are only loaded on startup.

That said, Justin’s suggestion of a Textarea property is still the cleaner long-term solution for JSON-LD.

Or you can create a block with a text area if you want editors to be able to add any scripts at a specific location in the RTE.

2 Likes