Skip to main content

Crate ferrodoc

Crate ferrodoc 

Source
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-highlighting asks it to. A gate that mutes pandoc’s highlighting must mute this one too, or it compares two different questions.
HtmlWrap
What goes into a standalone HTML page besides the document. How the writer lays lines out, as pandoc’s --wrap means 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 Wrap modes 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 --ascii does for HTML.
convert
Convert a document from one format to another.
number_sections
Number a document’s headings, as pandoc’s --number-sections does.
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-prefix does.
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=none asks for.
render_html_with_id_prefix
An HTML fragment with --id-prefix on 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 media can 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 columns where 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-by does.
strip_comments
Drop every HTML comment, as pandoc’s --strip-comments does.

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.