Escape html instead of stripping html tags

Created on 9 November 2023, about 1 year ago
Updated 21 November 2023, about 1 year ago

Problem/Motivation

Schema Metatag converts all text to plain text for json-ld, although escaped html would also be valid.

Steps to reproduce

An acceptedAnswer with text input <a href="https://validator.schema.org">The validator of schema.org</a> says yes. returns the following output, missing the html tags.

{
    "@context": "https://schema.org",
    "@graph": [
        {
            "@type": "FAQPage",
            "mainEntity": [
                {
                    "@type": "Question",
                    "name": "Can I use escaped HTML in json-ld?",
                    "acceptedAnswer": {
                        "@type": "Answer",
                        "text": "The validator of schema.org says yes.", // Missing html
                        "url": "https://validator.schema.org/"
                    }
                }
            ]
        }
    ]
}

The following example was generated using only "SchemaMetatagManager::encodeJsonld", skipping "PlainTextOutput::renderFromHtml" in "SchemaNameBase::processItem".

It is valid according to https://validator.schema.org/, https://search.google.com/test/rich-results and https://jsonlint.com/.

{
    "@context": "https://schema.org",
    "@graph": [
        {
            "@type": "FAQPage",
            "mainEntity": [
                {
                    "@type": "Question",
                    "name": "Can I use escaped HTML in json-ld?",
                    "acceptedAnswer": {
                        "@type": "Answer",
                        "text": "\u003Ca href=\u0027https://validator.schema.org\u0027\u003EThe validator of schema.org\u003C/a\u003E says yes.",
                        "url": "https://validator.schema.org/"
                    }
                }
            ]
        }
    ]
}

Proposed resolution

- Skip PlainTextOutput::renderFromHtml for text (and maybe other types) in SchemaNameBase::processItem

Remaining tasks

- Determine additional types that can contain HTML
- Adjust tests

User interface changes

- None

API changes

- SchemaNameBase::output may contain escaped html

Data model changes

-

✨ Feature request
Status

Needs work

Version

3.0

Component

Code

Created by

πŸ‡¨πŸ‡­Switzerland pvbergen

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024