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_styledreads back (docs/texteditor.md).