Expand description
Universal document converter: read Pandoc Markdown, CommonMark, GFM,
HTML, DOCX, ODT, EPUB, notebooks or the pandoc JSON AST; write supported
formats plus plain text.
Everything goes through one document model — the same AST pandoc uses — so any supported input can produce any supported output.
use ferrodoc::{Format, convert};
let html = convert(b"# Title\n\nHello *world*.\n", Format::Markdown, Format::Html)?;
assert_eq!(
String::from_utf8(html)?,
"<h1>Title</h1>\n<p>Hello <em>world</em>.</p>\n"
);To transform a document rather than just convert it, work with the AST:
use ferrodoc::{Format, ast::Block, parse, render};
let mut doc = parse(b"# Title\n\ntext\n", Format::Markdown)?;
doc.blocks.retain(|block| !matches!(block, Block::Header(..)));
let html = render(&doc, Format::Html)?;
assert_eq!(String::from_utf8(html)?, "<p>text</p>\n");Modules§
- ast
- The document model: the pandoc-compatible AST.
Structs§
- Page
- What goes into a standalone HTML page besides the document. What goes into the page besides the document.
- Pandoc
- A complete document: metadata plus a sequence of blocks.
Enums§
- Error
- Why a conversion could not be performed.
- Format
- A document format.
- Highlighting
- What goes into a standalone HTML page besides the document.
Whether the writer colours code, as pandoc’s
--syntax-highlightingasks it to. A gate that mutes pandoc’s highlighting must mute this one too, or it compares two different questions. - Html
Wrap - What goes into a standalone HTML page besides the document.
How the writer lays lines out, as pandoc’s
--wrapmeans it. - Wrap
- How the output’s lines are laid out — pandoc’s
--wrap, with the same three values and the same meanings. - Wrapping
- What a writer does with lines, and therefore which
Wrapmodes it can honour.
Constants§
- EXTENSIONS
- Every extension name pandoc 3.8.2.1 knows, so that a name it does not know can be told from one this build has not implemented.
Functions§
- ascii_
only - Every non-ASCII character as a numeric entity, as pandoc’s
--asciidoes for HTML. - convert
- Convert a document from one format to another.
- number_
sections - Number a document’s headings, as pandoc’s
--number-sectionsdoes. - parse
- Read a document.
- parse_
markdown_ github - Read pandoc’s deprecated
markdown_github. - parse_
with_ media - Read a document together with the bytes of every image it embeds.
- prefix_
identifiers - Prefix every identifier, as pandoc’s
--id-prefixdoes. - render
- Write a document. Images are not embedded; see
render_with_media. - render_
html_ unhighlighted - The same fragment with code left uncoloured, which is what
--syntax-highlighting=noneasks for. - render_
html_ with_ id_ prefix - An HTML fragment with
--id-prefixon the identifiers the writer invents. - render_
latex_ standalone - Render a document as a complete LaTeX file rather than a fragment:
preamble,
\begin{document}, and the title block if the document carries one. - render_
latex_ unhighlighted - LaTeX with no highlighting: every code block is
verbatim, whatever language it names. - render_
page - Render a document as a complete HTML page rather than a fragment.
- render_
with_ media - Write a document, embedding every image whose bytes
mediacan supply for its URL. - render_
with_ reference - Render to DOCX or ODT, taking the styles from a reference
document — pandoc’s
--reference-doc. - render_
wrapped - Render, filling text to
columnswhere the writer can fill. - render_
wrapped_ with_ media - Render with a line layout and a media resolver.
- shift_
heading_ level - Shift every heading, as pandoc’s
--shift-heading-level-bydoes. - strip_
comments - Drop every HTML comment, as pandoc’s
--strip-commentsdoes.
Type Aliases§
- Media
- The image bytes a document carries, keyed by the URL its AST refers to them by. Only DOCX input supplies any today; every other reader produces an empty bag.