Skip to content

fix: Link target attribute parsing to match serialization#92

Open
dkesberg wants to merge 2 commits into
ueberdosis:mainfrom
dkesberg:link-target-attribute-parsing
Open

fix: Link target attribute parsing to match serialization#92
dkesberg wants to merge 2 commits into
ueberdosis:mainfrom
dkesberg:link-target-attribute-parsing

Conversation

@dkesberg

Copy link
Copy Markdown

Description / Problem

When parsing HTML links without a target attribute, the parser returns null from getAttrs, leaving target unset in the mark's attrs.
During rendering, renderHTML would then apply the default target="_blank" from HTMLAttributes.
In the current tests for serialization the test link mark can disable target (tests/DOMSerializer/Marks/LinkTest.php:250) tests that a mark with target: null does not output the _blank default in rendered HTML.
To be consistent the parser should also initialize the document object with target: null.

Solution

getAttrs now explicitly returns target: null when no target attribute is present on the parsed element.
This mirrors the existing serializer behavior: a mark with target: null does not output target="_blank"

Changes

  • src/Marks/Link.php: return ['target' => null] from getAttrs when no target is present
  • tests/DOMParser/Marks/LinkTest.php: update existing tests to reflect target: null in parsed output

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant