Skip to content

Add v-html text content without modification #50

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 21, 2025

Conversation

yerdua
Copy link
Contributor

@yerdua yerdua commented Aug 20, 2025

Prior to this commit, if the value for v-html did not begin with an HTML element tag, it would be wrapped in a <p> tag before being added to its node. This introduced inconsistency in rendering, for example:

  • 'plain text' became '<p>plain text</p>'
  • but '<span>span content</span>' would remain as-is

An additional problem is that if the string began with plain text, but contained an element not allowed in a <p>, that <p> wrapper would be closed early, potentially creating an even more complex structure than expected.
for example:

  • input: 'beginning <div>internal text</div> ending'
  • output: '<p>beginning </p><div>internal text</div> ending'

This wrapping/modification is prevented by wrapping the string in a <body> tag before it is given to the HtmlParser. This <body> tag is only used as a temporary container. Before, it was added in the parser as an implied tag. Adding it explicitly serves the same function of providing a temporary node to extract childNodes from, without the <p> side effect.

Additionally, the tests for v-html are collected into one, using dataProvider function to cover the variations

Bug: T402295

Prior to this commit, if the value for `v-html` did not begin with
an HTML element tag, it would be wrapped in a `<p>` tag before
being added to its node. This introduced inconsistency in rendering,
for example:
  - `'plain text'` became `'<p>plain text</p>'`
  - but `'<span>span content</span>'` would remain as-is

An additional problem is that if the string began with plain text,
but contained an element not allowed in a `<p>`, that `<p>` wrapper
would be closed early, potentially creating an even more complex
structure than expected.
for example:
  - input: `'beginning <div>internal text</div> ending'`
  - output: `'<p>beginning </p><div>internal text</div> ending'`

This wrapping/modification is prevented by wrapping the string in
a `<body>` tag before it is given to the HtmlParser. This `<body>`
tag is only used as a temporary container. Before, it was added in
the parser as an implied tag. Adding it explicitly serves the same
function of providing a temporary node to extract childNodes from,
without the `<p>` side effect.

Additionally, the tests for `v-html` are collected into one, using
dataProvider function to cover the variations

Bug: T402295
@yerdua yerdua force-pushed the stop-wrapping-html-in-p branch from 5e3deee to 23c69a8 Compare August 20, 2025 16:15
Copy link
Contributor

@codders codders left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me! I'll not merge it just yet in case Lucas wants to take a look. But feel free to merge it yourself if nobody else responds.

Copy link
Member

@lucaswerkmeister lucaswerkmeister left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me as well! It’s a bit weird that libxml requires this to not insert a random <p>, but it’s harmless enough. (I tested it on PHP 8.4.11 with libxml 2.14.5, where the <p> is no longer present, and the fix doesn’t seem to hurt anything there.)

@lucaswerkmeister lucaswerkmeister merged commit fd99116 into master Aug 21, 2025
8 checks passed
@lucaswerkmeister lucaswerkmeister deleted the stop-wrapping-html-in-p branch August 21, 2025 10:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants