Skip to content

fix(id-web): preserve empty-text links in markdown codec (#996) - #1033

Merged
dezren39 merged 1 commit into
mainfrom
queue/1190-996-empty-link
Oct 27, 2026
Merged

dezren39 merged 1 commit into
mainfrom
queue/1190-996-empty-link

Conversation

@dezren39

@dezren39 dezren39 commented Oct 26, 2026 •

Copy link
Copy Markdown
Member

Fixes #996 · Queue task 1190

Problem

markdown_to_prosemirror dropped an empty-text link entirely: the Link arm 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_node Link arm: when the link has no inline children, synthesize an empty text node carrying the link mark via text_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).
  • Save side needed no change: the PM text arm hands marked text to create_marked_text, which wraps Text("") 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.


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need.

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.
@dezren39
dezren39 requested a review from a team as a code owner October 26, 2026 23:41
@coderabbitai

coderabbitai Bot commented Oct 26, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You'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.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 671fa29c-50e4-4722-9071-62913af0d202
Commits

Reviewing files that changed from the base of the PR and between 050a8da and a06b506.

Files selected for processing: 1
  • pkgs/id/src/web/markdown.rs
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-26T23:44:29.768520Z a06b506 PR opened
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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)]);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge 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 👍 / 👎.

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.

id(web): empty-text links are silently deleted on save — href lost

1 participant