pub fn to_json(blocks: &[Block]) -> StringExpand description
Every block as JSON: kind, page, box, text, spans and reading-order index.
Preview: output quality is still improving and the API may change in a minor release.
An OBJECT with a blocks array in it, not a bare array. A document is a
thing with blocks in it and other things later – the page sizes, the
document’s own metadata – and a format that opened as an array could never
say one without breaking every reader of it.
THE FURNITURE IS IN IT, which is the difference from crate::to_markdown.
A running head standing between two paragraphs is what makes it a defect
for anything that chunks the text, so the markdown does not write it; a
caller reading the blocks is not reading a flow, and the line the document
repeats is something it may well want. It carries "header" or "footer"
and stands after the body, where the reading order puts it (#571).
Deterministic: the same blocks produce the same bytes. Indented with two spaces per level, because the golden test over this is a diff somebody has to read, and any consumer that wants it smaller minifies it.
use pdf_engine::{to_json, Block, BlockKind};
let blocks = vec![Block::new(
BlockKind::Heading { level: 1 },
0,
[72.0, 700.0, 200.0, 712.0],
"Scope".to_string(),
0,
)];
assert!(to_json(&blocks).contains("\"kind\": \"heading\""));