JSON:API processed output is wrapped by body tag

Created on 27 February 2024, 9 months ago

Problem/Motivation

I'm working on a decoupled project and we use JSON:API. The processed output is wrapped in a body tag as follows:

body: {
  value: "<p>This is a paragraph</p><embedded-content data-plugin-config="{&quot;url&quot;:&quot;https:\/\/www.drupal.org\/project\/ckeditor5_embedded_content&quot;,&quot;text&quot;:&quot;Find out more&quot;}" data-plugin-id="call_to_action">&nbsp;</embedded-content><p>This is another paragraph after the embedded content.</p>",
  format: "full_html",
  processed: "<p>This is a paragraph</p><body><p>
  <a href="https://www.drupal.org/project/ckeditor5_embedded_content" style="background:blue;color:white;border-radius: 1rem;font-size: 2rem;padding:1rem">
    Find out more
  </a>
</p>
</body><p>This is another paragraph after the embedded content.</p>",
summary: ""
},

I'm guessing that usually, the extra body tag gets removed automatically because there can only be 1 body tag per page but since the JSON output is just a string, then the body tag remains.

Steps to reproduce

  • Using a standard drupal installation
  • Enable JSON:API, Embedded Content and Embedded Content Examples
  • Add the Embedded Content plugin to a text editor
  • Create an article and add one of the embedded content example inside of the Body field
  • Go to /jsonapi/node/article
  • See that body.processed of the article you just created wraps the output with <body>

Proposed resolution

From what I understand in issue #3364980 src/Plugin/Filter/EmbeddedContent.php was updated and the line $new_node = $document->importNode($xpath->query('//body')->item(0), TRUE); is querying the body tag. Ideally the content inside the body should be returned instead.

Remaining tasks

User interface changes

API changes

Data model changes

🐛 Bug report
Status

Active

Version

1.0

Component

Code

Created by

🇫🇮Finland Laurie Lim Helsinki

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

Comments & Activities

Production build 0.71.5 2024