Skip to content
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

Misaligned tags for overlapping marks #245

Closed
barnslig opened this issue Aug 21, 2023 · 2 comments
Closed

Misaligned tags for overlapping marks #245

barnslig opened this issue Aug 21, 2023 · 2 comments

Comments

@barnslig
Copy link

Describe the bug

Hi,

there seems to be an issue with overlapping marks producing incorrect HTML.

The issue is already fixed in ueberdosis/tiptap-php v1.3.0. However, it seems that it needs to be merged manually into Vizy, because updating tiptap-php does not solve the issue.

Related issues and PRs:

Possibly affected function that needs to be fixed:

vizy/src/services/Nodes.php

Lines 114 to 152 in 69b8c72

public function renderNode(NodeInterface $node, ?NodeInterface $prevNode = null, ?NodeInterface $nextNode = null): string
{
$html = [];
if ($node->marks) {
foreach ($node->marks as $mark) {
if ($this->markShouldOpen($mark, $prevNode)) {
$html[] = $mark->renderOpeningTag();
}
}
}
$html[] = $node->renderOpeningTag();
if ($node->content) {
foreach ($node->content as $index => $nestedNode) {
$prevNestedNode = $node->content[$index - 1] ?? null;
$nextNestedNode = $node->content[$index + 1] ?? null;
$html[] = $this->renderNode($nestedNode, $prevNestedNode, $nextNestedNode);
}
} else if ($text = $node->getText()) {
$html[] = $text;
}
if (!$node->selfClosing()) {
$html[] = $node->renderClosingTag();
if ($node->marks) {
foreach (array_reverse($node->marks) as $mark) {
if ($this->markShouldClose($mark, $nextNode)) {
$html[] = $mark->renderClosingTag();
}
}
}
}
return implode($html);
}

Best regards

Steps to reproduce

Manual issue reproduction:

  1. Create a link within a Vizy field
  2. Create a text selection that overlaps linked and non-linked text
  3. Turn it italic

Example JSON from .getRawNodes():

[{"type":"paragraph","attrs":[],"content":[{"type":"text","text":"Lorem "},{"type":"text","marks":[{"type":"link","attrs":{"href":"https:\/\/google.com","target":"","class":null}}],"text":"ipsum dolor "},{"type":"text","marks":[{"type":"link","attrs":{"href":"https:\/\/google.com","target":"","class":null}},{"type":"italic"}],"text":"sit amet"},{"type":"text","marks":[{"type":"italic"}],"text":", "},{"type":"text","text":"consectetur."}]}]

Rendered invalid HTML from Vizy:

<p>Lorem <a href="https://google.com">ipsum dolor </a><a href="https://google.com"><em>sit amet</a>, </em>consectetur.</p>

Expected HTML, rendered via tiptap-php:

<p>Lorem <a href="https://google.com">ipsum dolor <em>sit amet</em></a><em>, </em>consectetur.</p>

Craft CMS version

Craft Pro 4.4.17

Plugin version

2.1.8

Multi-site?

No response

Additional context

No response

@engram-design
Copy link
Member

Fixed for the next release. To get this early, run composer require verbb/vizy:"dev-craft-4 as 2.1.8"

@engram-design
Copy link
Member

Fixed in 2.1.9

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

No branches or pull requests

2 participants