Repository navigation
Conversation
When a figure is rebuilt by createFigureWithCaption, the caption went through extractUniqueCaptionContent, which collected the text nodes and joined them with spaces. Every element was dropped, so a caption like "You can find the source code <a href="…">here</a>." lost its link. This happens on Substack posts, where captions are spans around links. The joined text was then re-parsed as HTML, so escaped markup in a caption (<img src=x>) came back as a real element. Replace it with appendUniqueCaptionContent, which copies the caption into the new figcaption as DOM nodes: repeated text is still skipped, links (href checked with isDangerousUrl) and inline formatting (em, i, strong, b, code, sub, sup) are kept as clean shells, other wrappers are unwrapped with a space at block boundaries, and text stays text. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When a figure is standardized (
createFigureWithCaptioninsrc/elements/images.ts), the caption goes throughextractUniqueCaptionContent, which collects the caption's text nodes and joins them with spaces. Every element is dropped, so links in captions disappear:becomes
…You can find the source code here.This is how Substack renders captions, so every Substack post with linked captions loses them (a real post I clipped lost 12). It also reaches Obsidian Web Clipper users.A second, smaller issue in the same path: the joined text is passed back through
parseHTML, so escaped markup in a caption (<img src=x>) is turned back into a real element. With the current code the new fixture's Figure 4 comes out as.Fix
extractUniqueCaptionContentis replaced byappendUniqueCaptionContent, which copies the caption into the new<figcaption>as DOM nodes instead of building an HTML string:hrefis checked withisDangerousUrl. Inline formatting (em,i,strong,b,code,sub,sup) is kept as clean elements with no attributes;<div>A</div><div>B</div>doesn't becomeAB;parseHTML/innerHTMLround trip.Tests
elements--figcaption-inline-formattingcovers a Substack-style caption, emphasis + inline code + a relative link, a caption split across block elements, escaped markup, and ajavascript:link that keeps its text but loses itshref. It fails onmainand passes with the fix.issues--227-noscript-lazy-imagesexpected output updated: its captions contain<a href="https://example.com/source1">Source One</a>and<a href="https://example.com/source2">Source Two</a>, which were flattened before and are now kept as links.npm testandnpm run test:jsdom: 773/773.lint:unusedandlint:innerhtmlpass, andnpm run sizeis within budget.🤖 Generated with Claude Code