Repository navigation
fix(id-web): preserve empty-text links in markdown codec (#996) - #1033
Conversation
The Link arm represented a link only as a mark on its child text nodes; an empty-text link has no children, so the mark and href vanished on open and save emitted nothing. - convert_node Link arm: when the link has no inline children, synthesize an empty text node carrying the link mark. - text_node_with_marks: drop empty text only when it carries no marks — an empty marked node is the representation of an empty-text link. - Tests: PM shape for [](https://e.com) plus byte-identical round-trips alone, mid-paragraph, and with a title, each a stable second-save fixpoint. Queue task 1190.
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 56 seconds. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a06b506de9
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| // an empty text node carrying the mark; the save side | ||
| // wraps it back into a Link node (create_marked_text), | ||
| // so `[](url)` round-trips. | ||
| return json!(vec![text_node_with_marks("", &marks)]); |
There was a problem hiding this comment.
Preserve empty links without emitting forbidden empty text nodes
When a Markdown file contains an empty link anywhere, this emits a text node that ProseMirror rejects: its TextNode constructor throws RangeError("Empty text nodes are not allowed"). In the actual editor load path, pkgs/id/web/src/editor.ts:352–356 calls Node.fromJSON and handles that exception by replacing the entire document with an empty document. Thus before [](https://e.com) after now opens completely blank, rather than merely losing the empty link. Use an editor-compatible representation and validate it through the frontend deserializer; codec-only round-trip tests miss this regression.
Useful? React with 👍 / 👎.
Fixes #996 · Queue task 1190
Problem
markdown_to_prosemirrordropped an empty-text link entirely: theLinkarm represents a link only as a mark on its child text nodes, and with no children the mark — and the href — vanished, so[](https://e.com)opened as an empty paragraph and saved as ``.Change (codec only,
pkgs/id/src/web/markdown.rs)convert_nodeLink arm: when the link has no inline children, synthesize an empty text node carrying the link mark viatext_node_with_marks("", &marks).text_node_with_marks: an empty text node is dropped only when it carries no marks; an empty node with marks is information-bearing (it is the only representation of an empty-text link).create_marked_text, which wrapsText("")in the Link node and comrak renders[](url)(verified in triage task 1153).Tests
New
test_empty_link_roundtrips: PM shape of[](https://e.com)(single text node,text: "", link mark with href), plus byte-identical round-trips — alone, mid-paragraph (before [](https://e.com) after), and with a title ([](https://e.com "T")) — each a stable second-save fixpoint. Targeted suite:cargo test --features web --lib web::markdown.Known limitation (out of scope per the task packet)
The frontend editor may still drop empty text nodes while editing (ProseMirror tends to normalize them away), so an empty link created in markdown can survive the codec round-trip yet still be fragile inside the live editor. No editor/frontend schema changes are made here; the codec round-trip is the deliverable.
Need help on this PR? Tag
@codesmith-botwith what you need.