markupsth
A very simple Rust library for writing almost all kinds of formatted text files, escpially Markup files, such as HTML and XML. Its original purpose was to develop a Text-to-HTML converter, but got slowly extended step-by-step. HTML and XML support is default and implemented, but you can also define your own Markup Language by configuring your individual syntax. There are also some pre-defined formatters to either no formatting at all the Markup output or have some out-of-the-box formatting styles for a beautiful and readable HTML code.
For an individual syntax style (own Markup Language), have a look at the syntax
module. For
an own formatting style (implement your own Formatter
to be used with this crate), have a
look at the format
module.
Request for changes
In case of interest, I am also willing to extend this crate any time by new Markup Languages, formatting styles, or any other kind of meaningful modifications. Feel free to contact me via Email provided in the cargo manifest file.
Examples
By using an implemented Markup Language such as HTML or XML, and a pre-defined Formatter
, you
can quickly write some converter or HTML-generator. Such a quick-start guide can be seen in the
following example.
Readable HTML
To generate the following HTML code:
New Website
This is HTML
you need to implement:
use ;
// Setup a document (String), MarkupSth and a default formatter.
let mut document = String new;
let mut mus = new.unwrap;
// Default Formatter is an AutoIndent, so get it, configure it!
let fmtr = mus.formatter.optional_fixed_ruleset.unwrap;
fmtr.add_tags_to_rule
.unwrap;
fmtr.add_tags_to_rule.unwrap;
fmtr.add_tags_to_rule
.unwrap;
// Generate the content of example shown above.
mus.open.unwrap;
mus.open.unwrap;
mus.open_close_w.unwrap;
mus.self_closing.unwrap;
properties!.unwrap;
mus.close.unwrap;
mus.open.unwrap;
mus.open.unwrap;
mus.open.unwrap;
mus.new_line.unwrap;
mus.open.unwrap;
mus.self_closing.unwrap;
properties!.unwrap;
mus.close.unwrap;
mus.open_close_w.unwrap;
mus.close_all.unwrap;
mus.finalize.unwrap;
# assert_eq!;
Readable XML
To generate the following output:
Wikipedia List of Cities
Hamburg
Hamburg is the residence of ...
Munich
Munich is the residence of ...
you have to implement:
use ;
let do_entry = ;
// Setup a document (String), MarkupSth and a default formatter.
let mut document = String new;
let mut mus = new.unwrap;
// Default Formatter is an AutoIndent, so get it, configure it!
let fmtr = mus.formatter.optional_fixed_ruleset.unwrap;
fmtr.add_tags_to_rule.unwrap;
fmtr.add_tags_to_rule.unwrap;
// Generate the content of example shown above.
mus.open.unwrap;
mus.open.unwrap;
mus.text.unwrap;
mus.close.unwrap;
do_entry;
do_entry;
mus.close_all.unwrap;
mus.finalize.unwrap;
More Informations
Have a look into the crate's code documentation by using cargo.