Create anchors using span tag rather than anchor tag

Created on 11 September 2024, 2 months ago
Updated 16 September 2024, 2 months ago

Problem/Motivation

When an anchor is created in the wysiwyg, an anchor tag (i.e. <a>) without an href is wrapped around the highlighted text. Though this technically works, given that an <a> tag without an href is semantically the same as a <span>, I propose using a <span> directly instead. The <a> tag missing its href flags as an Alert in some a11y checkers, and if you review MDN documentation for <a> tags, the opening paragraph highlights the importance of href on anchors:

"The <a> HTML element (or anchor element), with its href attribute, creates a hyperlink to web pages, files, email addresses, locations in the same page, or anything else a URL can address."

Given than an anchor (not an <a> tag but the anchors that are created with the module) doesn't link anywhere, but is instead a destination point for a link, I believe a span is a better choice here.

I've attached examples of the <a> tag without an href, as well as the <a> tag flagging in the ARC Toolkit a11y checker.

Steps to reproduce

- Ensure the module/plugin is enabled on a Drupal install
- Enable the plugin on a text editor
- Use the module to create an anchor
- Inspect the anchor
- Confirm that an <a> tag is added around the text, and that the <a> tag is missing an href
- Extra step: install the ARC Toolkit and scan the page you created with the anchor to confirm that this flags as an Alert

Proposed resolution

- Rather than adding an <a> tag around the highlighted text in order to create an anchor, add a <span> instead
- An id attribute can be added to a span just like an <a> tag, and will be semantically clearer

I left this as a Task, rather than a Bug because this is technically fine as is, but would benefit from the change.

πŸ“Œ Task
Status

Active

Version

3.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States morganlyndel

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024