Skip to content

Render nested markup inside headings in HTMLFormatter#280

Merged
d-ronnqvist merged 2 commits into
swiftlang:mainfrom
somiljain2006:link-bug-fix
Jul 1, 2026
Merged

Render nested markup inside headings in HTMLFormatter#280
d-ronnqvist merged 2 commits into
swiftlang:mainfrom
somiljain2006:link-bug-fix

Conversation

@somiljain2006

Copy link
Copy Markdown
Contributor

Bug/issue #, if applicable: Fixes #262

Summary

HTMLFormatter.visitHeading(:) rendered headings using heading.plainText, which stripped all nested inline markup. As a result, links, emphasis, strong text, inline code, and other inline elements inside headings were lost in the generated HTML. Updated HTMLFormatter.visitHeading(:) to render a heading's child markup by descending into its children instead of using heading.plainText.

Dependencies

N/A

Testing

Added regression tests covering:

  • Reference-style links inside headings (the reported issue).
  • Inline links and inline code inside headings.
  • Emphasis and strong text inside headings.

Steps:
Run HTMLFormatterTests

Checklist

Make sure you check off the following items. If they cannot be completed, provide a reason.

  • Added tests
  • Ran the ./bin/test script and it succeeded

Comment thread Tests/MarkdownTests/Visitors/HTMLFormatterTests.swift Outdated

@d-ronnqvist d-ronnqvist left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

These changes look good except for the real example URL used in the test.

@d-ronnqvist

Copy link
Copy Markdown
Contributor

@swift-ci please test

@d-ronnqvist
d-ronnqvist merged commit 2020df0 into swiftlang:main Jul 1, 2026
2 checks passed
@somiljain2006
somiljain2006 deleted the link-bug-fix branch July 1, 2026 13:09
jackbolen added a commit to jackbolen/swift-markdown that referenced this pull request Jul 19, 2026
Upstream swiftlang#274 (visitText/visitInlineCode/visitCodeBlock escape &<> through
String.htmlEscaped()) and swiftlang#280 (visitHeading descends into nested markup)
land byte-for-byte so the next upstream merge is clean. Fork delta on top:
attribute positions — link href, image src/title, footnote ids/hrefs, and
data-attributes — route through a quote-escaping attribute wrapper, since
upstream's 3-character text helper cannot serve a double-quoted attribute;
data-attributes drops its invalid backslash-escaped quote for &quot;. Math
text moves onto htmlEscaped() (a quote needs no escape in text position).
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.

HTMLFormatter ignores links in title

2 participants