Module somedoc::write[][src]

Expand description

Provides the functions, and format types, to serialize a Document in supported markup formats.

The enum OutputFormat provides a set of implemented formatters that may then be used in write_document and write_document_to_string.

Example

The following uses the write_document_to_string convenience function.

use somedoc::write::{OutputFormat, write_document_to_string};

let doc = make_some_document();

let doc_str = write_document_to_string(&doc, OutputFormat::Latex).unwrap();
println!("{}", doc_str);

Writer Implementation

Each of the supported output formats implements at least the Writer and possibly the ConfigurableWriter trait. These provide common functions for construction of the writer struct and the write_document method. The following example constructs two separate writers and emits the same document into both.

use somedoc::write::{ConfigurableWriter, Writer};
use somedoc::write::markdown::{MarkdownFlavor, MarkdownWriter};
use somedoc::write::latex::LatexWriter;

let doc = make_some_document();

let mut out = std::io::stdout();

let writer = MarkdownWriter::new_with(&mut out, MarkdownFlavor::CommonMark);
assert!(writer.write_document(&doc).is_ok());

let writer = LatexWriter::new(&mut out);
assert!(writer.write_document(&doc).is_ok());

Modules

html

Write a document as HTML. This includes a small number of additional CSS and JavaScript assets to support math formatting and code syntax highlighting.

json

Write a document as HTML. This includes a small number of additional CSS and JavaScript assets to support math formatting and code syntax highlighting.

latex

Write a document as LaTeX. This includes a small number of additional CTAN packages to support math formatting, images, and code syntax highlighting.

markdown

Write a document in one of a number of light-weight markdown formats. format.

Enums

OutputFormat

This indicates the output format to use when writing a document.

Traits

ConfigurableWriter

This trait can be implemented by a serializer to provide a common instantiation method when configuration may be passed to the new instance.

Writer

This trait can be implemented by a serializer to provide a common instantiation method.

Functions

write_document

Write the provided document doc, in the format described by format, into the write implementation w. This is simply a convenience function

write_document_to_string

A convenience function that will return a String containing the output of the write_document function for the given Document instance.