Skip to content
Merged
Show file tree
Hide file tree
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
31 changes: 31 additions & 0 deletions pkgs/id/src/web/markdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2873,6 +2873,37 @@ mod tests {
assert_eq!(first, second, "nested-quote text must be a save fixpoint");
}

#[test]
fn test_fence_first_blockquote_marker_stays_escaped() {
// #7563: a blockquote whose first block is a fenced code block
// HAS content, so a standalone escaped marker line in a later
// paragraph is authored literal text, not an alert opener: it
// must stay escaped, hard break intact. The restore scan's
// fence branches never marked quote_has_content, so the quote
// still counted as empty and the marker was unescaped.
let original = "> ```\n> code\n> ```\n>\n> \\[\\!NOTE\\]\\\n> Body.\n";
let (first, second) = two_saves(original);
assert!(
first.contains(r"\[\!NOTE\]"),
"marker after a fence-first block must stay escaped: {first:?}"
);
assert_eq!(first, second, "fence-first quote must be a save fixpoint");
}

#[test]
fn test_html_first_blockquote_marker_stays_escaped() {
// #7563: the HTML-block sibling of the fence-first case,
// pinned directly on the restore scan: in the saved spelling
// an HTML block as the quote's first block is content, so the
// later escaped marker line (hard break intact) is authored
// text and passes through byte-identical. (No two_saves form:
// the renderer splits an HTML-first quote ahead of the marker
// paragraph into a separate blockquote, where the marker
// legitimately IS the first content.)
let saved = "> <div>\n> html\n> </div>\n>\n> \\[\\!NOTE\\]\\\n> Body.\n";
assert_eq!(restore_github_alert_markers(saved), saved);
}

#[test]
fn test_strong_link_roundtrip_fixpoint() {
// Both spellings of a bold link canonicalize to the link-outermost
Expand Down
14 changes: 14 additions & 0 deletions pkgs/id/src/web/markdown/markdown_serialization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,16 @@ pub fn prosemirror_to_markdown(doc: &Value) -> Result<String, ConversionError> {
/// literal content, so a line like `> \[\!NOTE\]` inside one is authored
/// text, not a renderer-escaped marker, and rewriting it would silently
/// change the code (Codex P2 on the first cut).
/// Mark every quote level up to `depth` as having content. A fence or
/// HTML block inside a quote IS content of the quote (and of its
/// ancestors), so a marker line after one is not the quote's first
/// content (#7563).
fn mark_quote_content(quote_has_content: &mut [bool; 64], depth: usize) {
for seen in quote_has_content.iter_mut().take(depth + 1).skip(1) {
*seen = true;
}
}

pub(crate) fn restore_github_alert_markers(markdown: &str) -> String {
let mut output = String::with_capacity(markdown.len());
let mut quote_has_content = [false; 64];
Expand Down Expand Up @@ -111,6 +121,7 @@ pub(crate) fn restore_github_alert_markers(markdown: &str) -> String {
match strip_quote_depth(content_start, opened_at) {
Some(body) => {
fence.feed(fence_feed_line(body));
mark_quote_content(&mut quote_has_content, opened_at);
if !fence.in_fence() {
fence_depth = None;
}
Expand All @@ -128,6 +139,7 @@ pub(crate) fn restore_github_alert_markers(markdown: &str) -> String {
match strip_quote_depth(content_start, opened_at) {
Some(body) => {
html.feed(body, at_block_start);
mark_quote_content(&mut quote_has_content, opened_at);
if !html.in_html() {
html_depth = None;
}
Expand All @@ -146,12 +158,14 @@ pub(crate) fn restore_github_alert_markers(markdown: &str) -> String {
// literal from here on.
if fence.feed(fence_feed_line(rest)) {
fence_depth = Some(depth);
mark_quote_content(&mut quote_has_content, depth);
output.push_str(line);
at_block_start = false;
continue;
}
if html.feed(rest, at_block_start) {
html_depth = Some(depth);
mark_quote_content(&mut quote_has_content, depth);
output.push_str(line);
at_block_start = false;
continue;
Expand Down
Loading