Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 43 additions & 1 deletion pkgs/id/src/web/markdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3943,6 +3943,15 @@ fn validate_placement(doc: &Value) -> Result<(), ConversionError> {

/// Convert `ProseMirror` JSON document to markdown text.
///
/// Unknown marks are skipped by design (#1045): marks outside the
/// codec's vocabulary (`em`, `strong`, `strikethrough`, `link`, plus
/// the `code` mark handled specially by `create_marked_text`) are
/// dropped while the marked text itself is kept verbatim. This
/// differs from unknown *nodes*, which return
/// `ConversionError::UnknownType`, because an unknown inline style
/// can be shed without corrupting the document text. Known marks
/// render byte-identically whether or not unknown marks are present.
///
/// # Arguments
///
/// * `doc` - The `ProseMirror` JSON document.
Expand Down Expand Up @@ -5191,7 +5200,11 @@ fn create_marked_text<'a>(arena: &'a Arena<'a>, text: &str, marks: &[Value]) ->
title: title.to_owned(),
}))
}
_ => continue, // Skip code (handled below) and unknown marks
// #1045: `code` is skipped here because it is handled
// below as the innermost node; any other unrecognized mark
// is skipped by design — the text survives, the unknown
// styling is shed (see `prosemirror_to_markdown`).
_ => continue,
};
wrappers.push(wrapper_value);
}
Expand Down Expand Up @@ -5642,6 +5655,35 @@ mod tests {
assert_eq!(prosemirror_to_markdown(&ok).unwrap(), "hello\n");
}

#[test]
fn test_unknown_marks_are_skipped_by_design() {
// #1045: unknown marks are shed while their text survives —
// unlike unknown nodes, which error. Pins the documented
// skip policy on `prosemirror_to_markdown`.
let text = |marks: Value| {
json!({"type": "doc", "content": [{"type": "paragraph", "content": [
{"type": "text", "text": "hi", "marks": marks}
]}]})
};
// Bare unknown mark: text survives, mark vanishes.
let doc = text(json!([{"type": "underline"}]));
assert_eq!(prosemirror_to_markdown(&doc).unwrap(), "hi\n");
// Mixed known + unknown: the known mark still renders.
let doc = text(json!([{"type": "strong"}, {"type": "underline"}]));
assert_eq!(prosemirror_to_markdown(&doc).unwrap(), "**hi**\n");
// Unknown mark alongside code + link: code-mark special
// handling is unchanged.
let doc = text(json!([
{"type": "code"},
{"type": "link", "attrs": {"href": "http://e.com"}},
{"type": "underline"},
]));
assert_eq!(
prosemirror_to_markdown(&doc).unwrap(),
"[`hi`](http://e.com)\n"
);
}

#[test]
fn test_code_block() {
let doc = markdown_to_prosemirror("```rust\nfn main() {}\n```");
Expand Down
Loading