Skip to main content

Module styled_codec

Module styled_codec 

Source
Expand description

Import and export for StyledText: Markdown, HTML and RTF (docs/texteditor.md). Import and export for StyledText: Markdown, HTML, and RTF (docs/texteditor.md).

All three are lossy, in one direction each way. Reading, anything Day’s model cannot hold is dropped rather than approximated: a table, an image, a stylesheet. Writing, Day emits only what it can read back, so parse(write(doc)) == doc for every document Day itself produced. That round-trip is the contract these are tested against; matching Word or a browser byte for byte is not one.

Hand-rolled, with no new dependency. Each format is a few hundred lines because the subset is kept small (docs/texteditor.md §RTF scope), and because a text codec that panics or loops on hostile input is worse than one that misses a control word.

Structs§

DocStyle
A document’s base style: the font a run says nothing about, and the size everything else is relative to. Import needs it to place headings and code; export needs it to know what not to write.

Functions§

html_to_styled
Parse an HTML fragment into a styled document.
markdown_to_styled
Parse markdown into a styled document: the inline grammar (crate::markdown) plus the block constructs a document editor needs: ATX headings, > quotes, and -/1. lists.
rtf_to_styled
Parse the RTF subset Day writes, plus the control words a real editor puts around it (docs/texteditor.md).
styled_to_html
Write a styled document as an HTML fragment: one <p> per paragraph, <span style="…"> per run, with <b>/<i>/<u>/<s>/<code>/<a> where a tag says it more plainly.
styled_to_markdown
Write a styled document as markdown.
styled_to_rtf
Write a styled document as RTF, in the subset rtf_to_styled reads back (docs/texteditor.md).
Day API ↩ Guides· daybrite.dev