Skip to content

fix(core/link-to-dfn): recognize code dfns with empty text nodes#5239

Open
marcoscaceres wants to merge 2 commits into
mainfrom
fix/3346-backtick-dfn
Open

fix(core/link-to-dfn): recognize code dfns with empty text nodes#5239
marcoscaceres wants to merge 2 commits into
mainfrom
fix/3346-backtick-dfn

Conversation

@marcoscaceres
Copy link
Copy Markdown
Contributor

Closes #3346

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Updates core/link-to-dfn’s “is this dfn code?” detection so <dfn> elements whose only meaningful child is <code> (but that also contain whitespace-only text nodes) are treated as code, enabling the requested <dfn>\thing`` authoring pattern.

Changes:

  • Filter out whitespace-only text nodes from a <dfn>’s childNodes before determining whether it contains exactly one <code> child.
  • Adjust the “single child” check to use the filtered node list.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/core/link-to-dfn.js Outdated
Comment thread src/core/link-to-dfn.js
@marcoscaceres
Copy link
Copy Markdown
Contributor Author

@copilot Can you confirm all your feedback has been addressed? Can you fix anything that was not addressed?

Copy link
Copy Markdown
Contributor

Copilot AI commented May 4, 2026

@copilot Can you confirm all your feedback has been addressed? Can you fix anything that was not addressed?

All reviewer feedback has been addressed in e8bead4:

  1. nodeType guard (src/core/link-to-dfn.js:266): Added if (child.nodeType !== Node.ELEMENT_NODE) return false; before accessing localName, safely rejecting Text/Comment nodes without a forced JSDoc cast to HTMLElement. The Element cast on the next line is only reached after the guard confirms it's an element node.

  2. Regression test (tests/spec/core/link-to-dfn-spec.js:391–406): Added a test using <dfn>\n <code>myTerm</code>\n</dfn> (with leading/trailing whitespace text nodes around <code>), asserting the corresponding <a> link is wrapped in <code>.

…t nodes

Enables <dfn>`term`</dfn> to auto-wrap [=term=] links in <code>.
Inlines.js processes backticks before dfn.js, leaving empty text nodes
around the <code>. The isCode() check now filters these out.

Closes #3346
Address Copilot review feedback:
- Check child.nodeType === ELEMENT_NODE before accessing localName,
  preventing incorrect cast on non-element nodes (Text, Comment).
- Add regression test for <dfn> with whitespace text nodes around <code>.
@marcoscaceres marcoscaceres force-pushed the fix/3346-backtick-dfn branch from e8bead4 to c85674c Compare May 5, 2026 10:00
@marcoscaceres
Copy link
Copy Markdown
Contributor Author

@copilot Can you confirm all your feedback has been addressed? Can you fix anything that was not addressed?

Copy link
Copy Markdown
Contributor

Copilot AI commented May 8, 2026

@copilot Can you confirm all your feedback has been addressed? Can you fix anything that was not addressed?

All feedback has been addressed in e8bead4:

  1. nodeType guard (src/core/link-to-dfn.js:266): if (child.nodeType !== Node.ELEMENT_NODE) return false; safely rejects Text/Comment nodes before accessing localName, with the Element cast only applied after the guard confirms it's an element.

  2. Regression test (tests/spec/core/link-to-dfn-spec.js:391–406): Covers <dfn>\n <code>myTerm</code>\n</dfn> with leading/trailing whitespace text nodes, asserting the resolved <a> link is wrapped in <code>.

Nothing remains unaddressed.

@marcoscaceres marcoscaceres marked this pull request as ready for review May 9, 2026 02:40
@marcoscaceres marcoscaceres requested review from sidvishnoi and removed request for sidvishnoi May 9, 2026 02:41
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.

Allow auto-coding of <dfn>thing<dfn>

3 participants