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

DS-576 | @ericbakenhus | Remove WYSIWYG empty links #408

Draft
wants to merge 1 commit into
base: dev
Choose a base branch
from
Draft
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
1 change: 1 addition & 0 deletions src/utilities/richTextField.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ function createMarkup(storyblokHTML) {
allowedTags: false, // This allows extra HTML tags to be rendered, e.g., H2, img
allowedAttributes: false, // This allows custom class names
allowVulnerableTags: true, // https://github.com/apostrophecms/sanitize-html/blob/main/CHANGELOG.md#1250
exclusiveFilter: (frame) => frame.tag === 'a' && !frame.text.trim(), // Remove empty links
Copy link
Contributor Author

@ericbakenhus ericbakenhus Mar 18, 2024

Choose a reason for hiding this comment

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

Removes empty links. The sanitize-html docs use removing empty links as their exclusiveFilter example: https://www.npmjs.com/package/sanitize-html#filters 😆

Copy link
Member

Choose a reason for hiding this comment

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

ah, that's niiice.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@sherakama Unlike the related Alumni site fix, this will also remove links that have child elements (e.g. <br>) as long as there's no eventual text ancestors. That could cause some unexpected layout shifting.

I think I'm going to close this PR, manually handle the handful of WYSIWYG issues to get rid of the a11y issue, then handle this in the site rebuild instead...

Copy link
Member

Choose a reason for hiding this comment

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

That sounds like a reasonable pivot to me.

You can put this into draft to keep it around for a bit if you'd like.

});

// Rewrite the URL to the redirect link to mask the API endpoint.
Expand Down
Loading