docloom
A Rust library for programmatically building and rendering documents to markdown and styled terminal output.
Installation
[]
= "0.0.1"
Usage
use *;
use ;
let blocks = ;
let markdown = doc;
let terminal = doc;
println!;
println!;
Apply renderer-specific styling with .with_style(...) before calling .to_string().
Document Structure
Documents are built from Block and Inline elements.
Block Elements
Paragraph(Vec<Inline>)- Text paragraphHeading { level, content }- Headers (h1-h6)CodeBlock { language, content }- Fenced code blocksList { ordered, items }- Ordered/unordered listsTaskList { items }- Checkbox listsTable { headers, rows, alignments }- Tables with alignmentImage { alt, url }- Standalone image blocksBlockquote(Vec<Block>)- Quoted blocksHorizontalRule- Horizontal dividerBlockList(Vec<Block>)- Container for multiple blocks
Inline Elements
Text(String)- Plain textBold(Vec<Inline>)- Bold formattingItalic(Vec<Inline>)- Italic formattingStrikethrough(Vec<Inline>)-StrikethroughformattingCode(String)-Inline codeLink { text, url }- HyperlinksImage { alt, url }- Inline imagesLineBreak- Line break
Builder Functions
Block Builders
use *;
use Alignment;
// Headers
h1
h2 // ... through h6
// Content
p
code_block
quote
hr // horizontal rule
// Lists
ul // unordered
ol // ordered
task_list
// Tables
table
table_aligned
Inline Builders
use *;
text
bold
italic
strikethrough
code
link
Extension Traits
Use method syntax with BlockExt and InlineExt:
use *;
"Title".h1
"Paragraph".p
"text".bold
"text".italic
"link text".link
Renderers
Markdown Renderer
Outputs standard markdown with configurable styles:
use ;
let style = Style ;
// Reuse the `blocks` definition from the usage example above.
let output = to_string_with_style;
Terminal Renderer
Outputs styled terminal output with ANSI codes:
use ;
// Reuse the `blocks` definition from the usage example above.
let ansi = to_string;
let style = plain
.unicode_boxes
.colors
.heading_colors;
let plain = to_string_with_style;
let ascii = to_string_with_style;
Terminal features:
- Colored headers, code, links
- Unicode or ASCII box drawing
- Table alignment support
- Indented lists and blockquotes
Tuple Convenience
Build content from tuples for concise syntax:
// Multiple inline elements from tuple
p
// Table rows from nested tuples
table
Custom Rendering
Implement the Render trait for custom output formats:
License
MIT