Skip to main content

script_json

Function script_json 

Source
pub fn script_json(mime: &str, json: &str) -> Element
Expand description

A <script type="…"> holding a JSON document, made safe to embed. See json_ld.

Use it for other data blocks a page reads with JSON.parse, such as application/json. mime is attribute-escaped. Do not use it for type="module" or for classic scripts: that content is code, not data, and no escaping makes arbitrary code safe.

§Examples

use molt::prelude::*;
use molt::seo::script_json;
assert_eq!(
    script_json("application/json", r#"{"id":7}"#).render(),
    r#"<script type="application/json">{"id":7}</script>"#
);