1use crate::document::{DoclingDocument, Node, Table};
4
5#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
7pub enum ImageMode {
8 #[default]
10 Placeholder,
11 Embedded,
13 Referenced,
16}
17
18struct Ctx {
20 strict: bool,
21 compact_tables: bool,
23 images: ImageMode,
24 artifacts_dir: String,
25 artifacts: Vec<(String, Vec<u8>)>,
27 pic_index: usize,
28}
29
30pub fn to_markdown(doc: &DoclingDocument, strict: bool) -> String {
36 to_markdown_images(doc, strict, ImageMode::Placeholder, "artifacts").0
37}
38
39pub fn to_markdown_images(
43 doc: &DoclingDocument,
44 strict: bool,
45 images: ImageMode,
46 artifacts_dir: &str,
47) -> (String, Vec<(String, Vec<u8>)>) {
48 let mut ctx = Ctx {
49 strict,
50 compact_tables: doc.compact_tables,
51 images,
52 artifacts_dir: artifacts_dir.to_string(),
53 artifacts: Vec::new(),
54 pic_index: 0,
55 };
56 let mut blocks: Vec<String> = Vec::new();
57 render(&doc.nodes, &mut blocks, &mut ctx);
58 let mut body = blocks.join("\n\n");
59 if strict && !doc.links.is_empty() {
63 body = apply_links(&body, &doc.links);
64 }
65 let md = if body.is_empty() {
66 String::new()
67 } else {
68 format!("{body}\n")
69 };
70 (md, ctx.artifacts)
71}
72
73fn apply_links(body: &str, links: &[(String, String)]) -> String {
81 let mut out = body.to_string();
82 let mut cursor = 0usize;
83 for (anchor, href) in links {
84 let anchor = anchor
85 .replace('&', "&")
86 .replace('<', "<")
87 .replace('>', ">");
88 if anchor.is_empty() {
89 continue;
90 }
91 if let Some(rel) = out[cursor..].find(&anchor) {
92 let at = cursor + rel;
93 let replacement = format!("[{anchor}]({href})");
95 out.replace_range(at..at + anchor.len(), &replacement);
96 cursor = at + replacement.len();
97 }
98 }
99 out
100}
101
102fn apply_links_chunk(chunk: &str, queue: &mut Vec<(String, String)>) -> String {
113 let mut out = chunk.to_string();
114 let mut cursor = 0usize;
115 let mut carried: Vec<(String, String)> = Vec::new();
116 for (anchor_raw, href) in std::mem::take(queue) {
117 let anchor = anchor_raw
118 .replace('&', "&")
119 .replace('<', "<")
120 .replace('>', ">");
121 if anchor.is_empty() {
122 continue;
123 }
124 if let Some(rel) = out[cursor..].find(&anchor) {
125 let at = cursor + rel;
126 let replacement = format!("[{anchor}]({href})");
127 out.replace_range(at..at + anchor.len(), &replacement);
128 cursor = at + replacement.len();
129 } else {
130 carried.push((anchor_raw, href));
132 }
133 }
134 *queue = carried;
135 out
136}
137
138pub struct MarkdownStreamer {
156 strict: bool,
157 images: ImageMode,
158 compact_tables: bool,
159 emitted_any: bool,
162 links: Vec<(String, String)>,
164 artifacts_dir: String,
168 artifacts: Vec<(String, Vec<u8>)>,
169 pic_index: usize,
170}
171
172impl MarkdownStreamer {
173 pub fn new(strict: bool, images: ImageMode, compact_tables: bool) -> Self {
176 debug_assert!(
177 images != ImageMode::Referenced,
178 "referenced image mode needs an artifacts dir; use with_artifacts"
179 );
180 Self::with_artifacts(strict, images, compact_tables, "artifacts")
181 }
182
183 pub fn with_artifacts(
190 strict: bool,
191 images: ImageMode,
192 compact_tables: bool,
193 artifacts_dir: &str,
194 ) -> Self {
195 Self {
196 strict,
197 images,
198 compact_tables,
199 emitted_any: false,
200 links: Vec::new(),
201 artifacts_dir: artifacts_dir.to_string(),
202 artifacts: Vec::new(),
203 pic_index: 0,
204 }
205 }
206
207 pub fn take_artifacts(&mut self) -> Vec<(String, Vec<u8>)> {
212 std::mem::take(&mut self.artifacts)
213 }
214
215 pub fn push(&mut self, nodes: &[Node], links: &[(String, String)]) -> String {
220 self.links.extend(links.iter().cloned());
221 let mut ctx = Ctx {
222 strict: self.strict,
223 compact_tables: self.compact_tables,
224 images: self.images,
225 artifacts_dir: std::mem::take(&mut self.artifacts_dir),
226 artifacts: std::mem::take(&mut self.artifacts),
227 pic_index: self.pic_index,
228 };
229 let mut blocks: Vec<String> = Vec::new();
230 render(nodes, &mut blocks, &mut ctx);
231 self.artifacts_dir = std::mem::take(&mut ctx.artifacts_dir);
232 self.artifacts = std::mem::take(&mut ctx.artifacts);
233 self.pic_index = ctx.pic_index;
234 if blocks.is_empty() {
235 return String::new();
236 }
237 let mut body = blocks.join("\n\n");
238 if self.strict && !self.links.is_empty() {
239 body = apply_links_chunk(&body, &mut self.links);
240 }
241 let chunk = if self.emitted_any {
242 format!("\n\n{body}")
243 } else {
244 body
245 };
246 self.emitted_any = true;
247 chunk
248 }
249
250 pub fn finish(self) -> String {
253 if self.emitted_any {
254 "\n".to_string()
255 } else {
256 String::new()
257 }
258 }
259}
260
261fn strict_text(text: &str, strict: bool) -> String {
269 if !strict {
270 return text.to_string();
271 }
272 text.replace("\\_", "_")
273 .replace(" ,", ",")
274 .replace(" .", ".")
275 .replace(" ;", ";")
276 .replace(" )", ")")
277 .replace("( ", "(")
278 .replace(" ]", "]")
279 .replace("[ ", "[")
280}
281
282fn render(nodes: &[Node], blocks: &mut Vec<String>, ctx: &mut Ctx) {
283 let mut i = 0;
284 while i < nodes.len() {
285 match &nodes[i] {
286 Node::ListItem { .. } => {
287 let start = i;
288 i += 1;
289 loop {
290 match nodes.get(i) {
291 Some(Node::ListItem { .. }) => i += 1,
292 Some(Node::Paragraph { text })
296 if text.is_empty()
297 && matches!(nodes.get(i + 1), Some(Node::ListItem { .. })) =>
298 {
299 i += 1
300 }
301 _ => break,
302 }
303 }
304 render_list_run(&nodes[start..i], blocks, ctx.strict);
305 }
306 other => {
307 render_one(other, blocks, ctx);
308 i += 1;
309 }
310 }
311 }
312}
313
314fn render_list_run(items: &[Node], blocks: &mut Vec<String>, strict: bool) {
320 let mut lines: Vec<String> = Vec::new();
321 let mut prev: Vec<Option<(bool, u64)>> = Vec::new();
324
325 for item in items {
326 let Node::ListItem {
327 ordered,
328 number,
329 first_in_list,
330 text,
331 level,
332 marker: _,
333 location: _,
334 dclx: _,
335 href: _,
336 layer,
337 } = item
338 else {
339 continue;
340 };
341 if layer.is_some() {
344 continue;
345 }
346 let level = *level as usize;
347
348 prev.truncate(level + 1);
350 while prev.len() <= level {
351 prev.push(None);
352 }
353
354 if level == 0 {
360 if let Some((prev_ordered, prev_number)) = prev[level] {
361 let new_list = *first_in_list
362 || prev_ordered != *ordered
363 || (*ordered && *number != prev_number + 1);
364 if new_list {
365 lines.push(String::new());
366 }
367 }
368 }
369
370 let indent = " ".repeat(level);
371 let marker = if *ordered {
372 format!("{number}.")
373 } else {
374 "-".to_string()
375 };
376 lines.push(format!("{indent}{marker} {}", strict_text(text, strict)));
377 prev[level] = Some((*ordered, *number));
378 }
379
380 if !lines.is_empty() {
383 blocks.push(lines.join("\n"));
384 }
385}
386
387fn render_one(node: &Node, blocks: &mut Vec<String>, ctx: &mut Ctx) {
388 match node {
389 Node::Heading { level, text } => {
390 let hashes = "#".repeat((*level).clamp(1, 6) as usize);
391 blocks.push(format!("{hashes} {}", strict_text(text, ctx.strict)));
392 }
393 Node::Paragraph { text } if text.is_empty() => {}
396 Node::Paragraph { text } => blocks.push(strict_text(text, ctx.strict)),
397 Node::CheckboxItem { checked, text } => {
398 let mark = if *checked { "- [x] " } else { "- [ ] " };
399 blocks.push(strict_text(&format!("{mark}{text}"), ctx.strict));
400 }
401 Node::Code { language, text, .. } => {
402 let lang = match language {
404 Some(l) if ctx.strict => l.as_str(),
405 _ => "",
406 };
407 blocks.push(format!("```{lang}\n{text}\n```"));
408 }
409 Node::Formula { latex, .. } => blocks.push(format!("$${latex}$$")),
412 Node::Table(table) => {
413 let rendered = render_table(table, ctx.compact_tables);
414 if !rendered.is_empty() {
415 blocks.push(rendered);
416 }
417 }
418 Node::Picture { caption, image, .. } => {
420 if let Some(cap) = caption {
421 if !cap.is_empty() {
422 blocks.push(cap.clone());
423 }
424 }
425 blocks.push(picture_marker(image.as_ref(), ctx));
426 }
427 Node::Chart {
431 kind,
432 table,
433 caption,
434 ..
435 } => {
436 if let Some(cap) = caption {
437 if !cap.is_empty() {
438 blocks.push(cap.clone());
439 }
440 }
441 blocks.push(picture_marker(None, ctx));
442 blocks.push(humanize_label(kind));
443 let rendered = render_table(table, false);
444 if !rendered.is_empty() {
445 blocks.push(rendered);
446 }
447 }
448 Node::DoclangOnly(_) => {}
450 Node::Group { children, .. } => render(children, blocks, ctx),
451 Node::FieldRegion { items } => {
452 blocks.push(MISSING_TEXT.to_string());
457 for item in items {
458 blocks.push(MISSING_TEXT.to_string());
459 for part in [&item.marker, &item.key, &item.value].into_iter().flatten() {
460 blocks.push(strict_text(part, ctx.strict));
461 }
462 }
463 }
464 Node::InlineGroup { md_text, .. } => blocks.push(strict_text(md_text, ctx.strict)),
467 Node::TextDump(text) => {
469 if !text.is_empty() {
470 blocks.push(text.clone());
471 }
472 }
473 Node::Furniture { .. } => {}
476 Node::PageFurniture { .. } => {}
477 Node::Located { inner, .. } => render_one(inner, blocks, ctx),
479 Node::PageBreak => {}
481 Node::PageInfo { .. } => {}
483 Node::ListItem { .. } => unreachable!("list items are rendered in runs"),
485 }
486}
487
488const MISSING_TEXT: &str = "<!-- missing-text -->";
491
492fn humanize_label(label: &str) -> String {
497 let text = label.replace('_', " ");
498 let mut chars = text.chars();
499 match chars.next() {
500 Some(f) => f.to_uppercase().collect::<String>() + chars.as_str(),
501 None => text,
502 }
503}
504
505fn picture_marker(image: Option<&crate::PictureImage>, ctx: &mut Ctx) -> String {
506 match (ctx.images, image) {
507 (ImageMode::Embedded, Some(img)) => format!("", img.data_uri()),
508 (ImageMode::Referenced, Some(img)) => {
509 let path = format!(
510 "{}/image_{:06}.{}",
511 ctx.artifacts_dir,
512 ctx.pic_index,
513 ext_for(&img.mimetype)
514 );
515 ctx.pic_index += 1;
516 ctx.artifacts.push((path.clone(), img.data.clone()));
517 format!("")
518 }
519 _ => "<!-- image -->".to_string(),
521 }
522}
523
524fn ext_for(mimetype: &str) -> &str {
525 match mimetype {
526 "image/jpeg" => "jpg",
527 "image/gif" => "gif",
528 "image/webp" => "webp",
529 "image/bmp" => "bmp",
530 "image/tiff" => "tif",
531 _ => "png",
532 }
533}
534
535fn is_number_cell(t: &str) -> bool {
552 t.parse::<f64>().is_ok() || is_thousands_number(t)
553}
554
555fn is_thousands_number(t: &str) -> bool {
561 let b = t.as_bytes();
562 let mut i = 0;
563 let start = i;
564 if i < b.len() && (b[i] == b'+' || b[i] == b'-') {
565 i += 1;
566 }
567 let d0 = i;
569 while i < b.len() && b[i].is_ascii_digit() && i - d0 < 3 {
570 i += 1;
571 }
572 let has_int = i > d0;
573 if has_int {
574 while i + 3 < b.len() + 1
576 && b.get(i) == Some(&b',')
577 && b.get(i + 1).is_some_and(u8::is_ascii_digit)
578 && b.get(i + 2).is_some_and(u8::is_ascii_digit)
579 && b.get(i + 3).is_some_and(u8::is_ascii_digit)
580 {
581 i += 4;
582 }
583 } else {
584 i = start;
586 }
587 if i < b.len() && b[i] == b'.' {
589 i += 1;
590 let f0 = i;
591 while i < b.len() && b[i].is_ascii_digit() {
592 i += 1;
593 }
594 if !has_int && i == f0 {
595 return false; }
597 } else if !has_int {
598 return false; }
600 i == b.len()
601}
602
603pub(crate) fn render_table(table: &Table, compact: bool) -> String {
604 if table.rows.is_empty() {
605 return String::new();
606 }
607 let num_cols = table.rows.iter().map(Vec::len).max().unwrap_or(0);
608 if num_cols == 0 {
609 return String::new();
610 }
611
612 let grid: Vec<Vec<String>> = table
615 .rows
616 .iter()
617 .enumerate()
618 .map(|(r, row)| {
619 (0..num_cols)
620 .map(|c| {
621 let cell = escape_cell(row.get(c).map(String::as_str).unwrap_or(""));
622 if r == 0 {
623 cell
624 } else {
625 cell.trim().to_string()
626 }
627 })
628 .collect()
629 })
630 .collect();
631
632 if compact {
633 let render_row = |r: usize| -> String { format!("| {} |", grid[r].join(" | ")) };
635 let mut lines = Vec::with_capacity(grid.len() + 1);
636 lines.push(render_row(0));
637 let sep: Vec<&str> = (0..num_cols).map(|_| "-").collect();
638 lines.push(format!("| {} |", sep.join(" | ")));
639 for r in 1..grid.len() {
640 lines.push(render_row(r));
641 }
642 return lines.join("\n");
643 }
644
645 let dw = |s: &str| s.chars().count();
647 let data_rows = 1..grid.len();
648
649 let right: Vec<bool> = (0..num_cols)
654 .map(|c| {
655 let mut any = false;
656 for r in data_rows.clone() {
657 let t = grid[r][c].trim();
658 if t.is_empty() {
659 continue;
660 }
661 if !is_number_cell(t) {
662 return false;
663 }
664 any = true;
665 }
666 any
667 })
668 .collect();
669
670 let width: Vec<usize> = (0..num_cols)
672 .map(|c| {
673 let mut w = dw(&grid[0][c]) + 2;
674 for r in data_rows.clone() {
675 w = w.max(dw(&grid[r][c]));
676 }
677 w
678 })
679 .collect();
680
681 let fmt_cell = |s: &str, c: usize| -> String {
682 let pad = " ".repeat(width[c].saturating_sub(dw(s)));
683 let body = if right[c] {
684 format!("{pad}{s}")
685 } else {
686 format!("{s}{pad}")
687 };
688 format!(" {body} ")
689 };
690 let render_row = |r: usize| -> String {
691 let cells: Vec<String> = (0..num_cols).map(|c| fmt_cell(&grid[r][c], c)).collect();
692 format!("|{}|", cells.join("|"))
693 };
694
695 let mut lines = Vec::with_capacity(grid.len() + 1);
696 lines.push(render_row(0));
697 let sep: Vec<String> = (0..num_cols).map(|c| "-".repeat(width[c] + 2)).collect();
698 lines.push(format!("|{}|", sep.join("|")));
699 for r in data_rows {
700 lines.push(render_row(r));
701 }
702 lines.join("\n")
703}
704
705fn escape_cell(s: &str) -> String {
708 s.replace('\n', " ").replace('|', "|")
709}
710
711#[cfg(test)]
712mod tests {
713 use super::*;
714 use crate::PictureImage;
715
716 #[test]
717 fn renders_headings_paragraphs_and_lists() {
718 let mut doc = DoclingDocument::new("demo");
719 doc.add_heading(1, "Title");
720 doc.add_paragraph("Hello world.");
721 doc.push(Node::ListItem {
722 ordered: false,
723 number: 1,
724 first_in_list: true,
725 text: "first".into(),
726 level: 0,
727 marker: None,
728 location: None,
729 dclx: None,
730 href: None,
731 layer: None,
732 });
733 doc.push(Node::ListItem {
734 ordered: false,
735 number: 2,
736 first_in_list: false,
737 text: "second".into(),
738 level: 0,
739 marker: None,
740 location: None,
741 dclx: None,
742 href: None,
743 layer: None,
744 });
745 let md = doc.export_to_markdown();
746 assert_eq!(md, "# Title\n\nHello world.\n\n- first\n- second\n");
747 }
748
749 #[test]
750 fn strict_renders_recovered_links_legacy_does_not() {
751 let mut doc = DoclingDocument::new("cv");
752 doc.add_paragraph("Find me on LinkedIn or GitHub.");
753 doc.links = vec![
754 ("LinkedIn".into(), "https://www.linkedin.com/in/x/".into()),
755 ("GitHub".into(), "https://github.com/x/".into()),
756 ];
757 assert_eq!(doc.export_to_markdown(), "Find me on LinkedIn or GitHub.\n");
759 assert_eq!(
761 doc.export_to_markdown_with(true),
762 "Find me on [LinkedIn](https://www.linkedin.com/in/x/) or [GitHub](https://github.com/x/).\n"
763 );
764 }
765
766 #[test]
767 fn strict_links_match_escaped_anchor_and_consume_in_order() {
768 let mut doc = DoclingDocument::new("d");
769 doc.add_paragraph("AI & ML here, and issues here, then issues there.");
773 doc.links = vec![
774 ("AI & ML".into(), "https://a/".into()),
775 ("issues".into(), "https://first/".into()),
776 ("issues".into(), "https://second/".into()),
777 ];
778 assert_eq!(
779 doc.export_to_markdown_with(true),
780 "[AI & ML](https://a/) here, and [issues](https://first/) here, then [issues](https://second/) there.\n"
781 );
782 }
783
784 #[test]
785 fn renders_compact_table() {
786 let mut doc = DoclingDocument::new("t");
787 doc.compact_tables = true;
790 doc.push(Node::Table(Table {
791 rows: vec![vec!["a".into(), "b".into()], vec!["1".into(), "2".into()]],
792 location: None,
793 structure: None,
794 cell_blocks: None,
795 }));
796 let md = doc.export_to_markdown();
797 assert_eq!(md, "| a | b |\n| - | - |\n| 1 | 2 |\n");
798 }
799
800 #[test]
801 fn renders_padded_github_table_by_default() {
802 let mut doc = DoclingDocument::new("t");
803 doc.push(Node::Table(Table {
804 rows: vec![vec!["a".into(), "b".into()], vec!["1".into(), "2".into()]],
805 location: None,
806 structure: None,
807 cell_blocks: None,
808 }));
809 let md = doc.export_to_markdown();
810 assert_eq!(md, "| a | b |\n|-----|-----|\n| 1 | 2 |\n");
812 }
813
814 #[test]
815 fn strict_unescapes_inline_underscores_legacy_keeps_them() {
816 let mut doc = DoclingDocument::new("t");
817 doc.add_heading(1, "a\\_b");
818 doc.add_paragraph("x\\_y");
819 doc.push(Node::ListItem {
820 ordered: false,
821 number: 1,
822 first_in_list: true,
823 text: "i\\_j".into(),
824 level: 0,
825 marker: None,
826 location: None,
827 dclx: None,
828 href: None,
829 layer: None,
830 });
831 assert_eq!(doc.export_to_markdown(), "# a\\_b\n\nx\\_y\n\n- i\\_j\n");
833 assert_eq!(doc.export_to_markdown_with(true), "# a_b\n\nx_y\n\n- i_j\n");
835 }
836
837 fn assert_stream_matches(
840 doc: &DoclingDocument,
841 strict: bool,
842 images: ImageMode,
843 splits: &[usize],
844 ) {
845 let (want, want_artifacts) = to_markdown_images(doc, strict, images, "artifacts");
846 let mut streamer =
847 MarkdownStreamer::with_artifacts(strict, images, doc.compact_tables, "artifacts");
848 let mut got = String::new();
849 let mut got_artifacts = Vec::new();
850 let mut start = 0;
851 for &end in splits {
852 let links = if start == 0 {
855 doc.links.as_slice()
856 } else {
857 &[]
858 };
859 got.push_str(&streamer.push(&doc.nodes[start..end], links));
860 got_artifacts.extend(streamer.take_artifacts());
863 start = end;
864 }
865 got.push_str(&streamer.push(
866 &doc.nodes[start..],
867 if start == 0 {
868 doc.links.as_slice()
869 } else {
870 &[]
871 },
872 ));
873 got_artifacts.extend(streamer.take_artifacts());
874 got.push_str(&streamer.finish());
875 assert_eq!(
876 got, want,
877 "streamed output diverged (splits={splits:?}, strict={strict})"
878 );
879 assert_eq!(
880 got_artifacts, want_artifacts,
881 "streamed artifacts diverged (splits={splits:?}, strict={strict})"
882 );
883 }
884
885 #[test]
886 fn streaming_is_byte_identical_to_buffered() {
887 let mut doc = DoclingDocument::new("d");
888 doc.add_heading(1, "Title");
889 doc.add_paragraph("First paragraph.");
890 doc.push(Node::ListItem {
891 ordered: false,
892 number: 1,
893 first_in_list: true,
894 text: "a".into(),
895 level: 0,
896 marker: None,
897 location: None,
898 dclx: None,
899 href: None,
900 layer: None,
901 });
902 doc.push(Node::ListItem {
903 ordered: false,
904 number: 2,
905 first_in_list: false,
906 text: "b".into(),
907 level: 0,
908 marker: None,
909 location: None,
910 dclx: None,
911 href: None,
912 layer: None,
913 });
914 doc.push(Node::Code {
915 language: Some("rust".into()),
916 text: "let x = 1;".into(),
917 orig: None,
918 });
919 doc.push(Node::Table(Table {
920 rows: vec![vec!["a".into(), "b".into()], vec!["1".into(), "2".into()]],
921 location: None,
922 structure: None,
923 cell_blocks: None,
924 }));
925 doc.push(Node::Picture {
926 caption: Some("Fig 1".into()),
927 image: Some(PictureImage {
928 mimetype: "image/png".into(),
929 width: 2,
930 height: 2,
931 data: b"png-one".to_vec(),
932 }),
933 classification: None,
934 });
935 doc.add_paragraph("Last paragraph.");
936 doc.push(Node::Picture {
939 caption: None,
940 image: Some(PictureImage {
941 mimetype: "image/png".into(),
942 width: 2,
943 height: 2,
944 data: b"png-two".to_vec(),
945 }),
946 classification: None,
947 });
948
949 for &strict in &[false, true] {
952 for &images in &[
953 ImageMode::Placeholder,
954 ImageMode::Embedded,
955 ImageMode::Referenced,
956 ] {
957 for splits in [&[][..], &[1][..], &[2][..], &[4][..], &[1, 4, 6, 7][..]] {
958 assert_stream_matches(&doc, strict, images, splits);
959 }
960 }
961 }
962 }
963
964 #[test]
965 fn streaming_applies_recovered_links_in_strict_mode() {
966 let mut doc = DoclingDocument::new("d");
967 doc.add_paragraph("See LinkedIn for details.");
968 doc.add_paragraph("And GitHub too.");
969 doc.links = vec![
970 ("LinkedIn".into(), "https://lnkd/".into()),
971 ("GitHub".into(), "https://gh/".into()),
972 ];
973 assert_stream_matches(&doc, true, ImageMode::Placeholder, &[1]);
976 }
977
978 #[test]
979 fn strict_tightens_punctuation_spacing_legacy_keeps_it() {
980 let mut doc = DoclingDocument::new("t");
981 doc.add_paragraph("see [ 37 , 36 ] and ( x ) .");
982 assert_eq!(doc.export_to_markdown(), "see [ 37 , 36 ] and ( x ) .\n");
984 assert_eq!(doc.export_to_markdown_with(true), "see [37, 36] and (x).\n");
986 }
987}