feat(writeback): image form ![marqdo-out](…) with view parity

Auto-persist image paths/URLs as Markdown images (validated extension);
keep HTML comment for text. View and static export share styled source
markers and output-card <img> rendering.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
cflmyandCursor committed 2026-10-15 15:45:52 +08:00
1 parent 9cf98a98b5
commit f47a1e143a
8 files changed
+454 -52

No files matched your search

+30
View File
@@ -292,9 +292,25 @@ fn breaks_comment_paragraph(trimmed: &str) -> bool {
if trimmed.starts_with('+') {
return true;
}
if is_image_writeback_line(trimmed) {
return true;
}
false
}
/// `![marqdo-out …](image-url)` — image writeback surface (see stdlib-writeback).
pub fn is_image_writeback_line(trimmed: &str) -> bool {
let t = trimmed.trim();
let Some(rest) = t.strip_prefix("![") else {
return false;
};
let Some(alt_end) = rest.find("](") else {
return false;
};
let alt = rest[..alt_end].trim();
alt.split_whitespace().any(|tok| tok == "marqdo-out")
}
fn looks_like_ordered_list_item(trimmed: &str) -> bool {
let mut chars = trimmed.chars();
let mut saw_digit = false;
@@ -382,6 +398,9 @@ pub fn classify_source(source: &str) -> Vec<ClassifiedLine> {
in_writeback = false;
}
LineKind::Writeback
} else if is_image_writeback_line(trimmed) {
in_comment_paragraph = false;
LineKind::Writeback
} else {
match base {
LineKind::Blank => {
@@ -547,6 +566,17 @@ mod tests {
assert_eq!(lines[3].kind, LineKind::Writeback);
}
#[test]
fn image_writeback_line_classified() {
assert!(is_image_writeback_line("![marqdo-out](a.svg)"));
assert!(is_image_writeback_line("![marqdo-out ok](plots/x.png)"));
assert!(!is_image_writeback_line("![plot](a.svg)"));
let src = "# main\n\n**x = 1**\n![marqdo-out](out.svg)\n\n> print text=x\n";
let lines = classify_source(src);
let img = lines.iter().find(|l| l.text.contains("marqdo-out]")).unwrap();
assert_eq!(img.kind, LineKind::Writeback, "{:?}", lines);
}
#[test]
fn paragraph_comment_keeps_backtick_continuation() {
let src = "采用了\n`.mq.md`的双层后缀\n\n> print text=ok\n";