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

fix: Prevent spans containing svgs from being removed #445

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/utils/DOMUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ export default class DOMUtils {
// remove spans
document.querySelectorAll('span').forEach((span) => {
// do not touch spans with images and span with a css class or an id
if (!span.querySelector('img') && span.classList.length === 0 && !span.id && !span.getAttribute('style')) {
if (!span.querySelector('img,svg') && span.classList.length === 0 && !span.id && !span.getAttribute('style')) {
if (span.textContent === '') {
span.remove();
} else {
Expand Down
1 change: 1 addition & 0 deletions test/utils/DOMUtils.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ describe('DOMUtils#removeSpans tests', () => {
test('<p>Spacing<span> should</span> remain the same</p>', '<p>Spacing should remain the same</p>');
test('<p>Spacing<span> should</span> remain the <span>same even</span> with<span> multiple spans</span></p>', '<p>Spacing should remain the same even with multiple spans</p>');
test('<span><div><img src="animage.jpg"></div></span>', '<span><div><img src="animage.jpg"></div></span>');
test('<span><div><svg class="test"><rect width="200" height="100" x="10" y="10" rx="20" ry="20" fill="blue"></rect></svg></div></span>', '<span><div><svg class="test"><rect width="200" height="100" x="10" y="10" rx="20" ry="20" fill="blue"></rect></svg></div></span>');
test('<span>Some image here: <div><img src="animage.jpg"></div></span>', '<span>Some image here: <div><img src="animage.jpg"></div></span>');
test('<div>Spans potentially used to do layouting: <span class="tab1">tab1</span><span class="tab2">tab2</span></div>', '<div>Spans potentially used to do layouting: <span class="tab1">tab1</span><span class="tab2">tab2</span></div>');
test('<div>Spans potentially used to do layouting: <span id="tab1">tab1</span><span id="tab2">tab2</span></div>', '<div>Spans potentially used to do layouting: <span id="tab1">tab1</span><span id="tab2">tab2</span></div>');
Expand Down