Conversation
…t-deserializing-to-to-a-link-in
maximilianfalco
left a comment
There was a problem hiding this comment.
looks good but probs need to remove the duplicate JSX expression parsing
…t-deserializing-to-to-a-link-in
|
Logic to transform the anchor tag looks good, tests are pretty extensive, though it covers many edge cases I was concerned about. Since the new transformer only applies to tags & is behind the editor flag, this shouldn't cause rendering regressions. Just 1 concern about the evaluateExpressions code! |
Co-authored-by: Dimas Putra Anugerah <63914983+eaglethrost@users.noreply.github.com>
kevinports
left a comment
There was a problem hiding this comment.
Looks good. Had a few minor comments.
| }); | ||
|
|
||
| it('should handle Anchor with JavaScript URL (should preserve as-is)', () => { | ||
| // Security note: Anchor component should handle sanitization at render time |
There was a problem hiding this comment.
Does the Anchor component actually sanitize this?
There was a problem hiding this comment.
@Jadenzzz you marked this conversation as resolved, but this was an actual question for you. Does the Anchor component actually sanitize this already? Or is this work we need to follow up with?
There was a problem hiding this comment.
sorry this comment is kinda misleading. The goal of this test is to make sure JavaScript URLs are preserved as-is
|
@Jadenzzz is this good to merge? Then you can get on with https://github.com/readmeio/readme/pull/17426 |
đź§° Changes
Issue
Built-in
<Anchor>components were not properly deserializing to links in the MDXish editor. When an Anchor component with a target attribute was saved and reloaded, it wasn't being recognized as a proper inline component nodeWhen the markdown parser encounters an inline component like:
Click <Anchor href="/docs" target="_blank">here</Anchor> to learn more.It fragments it into multiple sibling nodes inside the paragraph:
paragraph
├── text: "Click "
├── html: "<Anchor href="/docs" target="_blank">"
├── text: "here"
├── html:
"</Anchor>"└── text: " to learn more."
Unlike block components (Recipe, Callout) which are parsed as single elements, inline components need to be reassembled from these fragments.
Solution
Created mdxish-inline-components.ts transformer - A new MDAST transformer that:
🧬 QA & Testing