diff --git a/pkgs/id/src/web/markdown.rs b/pkgs/id/src/web/markdown.rs
index c8e3c7d7da..11810b660b 100644
--- a/pkgs/id/src/web/markdown.rs
+++ b/pkgs/id/src/web/markdown.rs
@@ -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 = ">
\n> html\n>
\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
diff --git a/pkgs/id/src/web/markdown/markdown_serialization.rs b/pkgs/id/src/web/markdown/markdown_serialization.rs
index 647b32abc7..875680ab66 100644
--- a/pkgs/id/src/web/markdown/markdown_serialization.rs
+++ b/pkgs/id/src/web/markdown/markdown_serialization.rs
@@ -76,6 +76,16 @@ pub fn prosemirror_to_markdown(doc: &Value) -> Result {
/// 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];
@@ -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;
}
@@ -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;
}
@@ -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;