Crate minimad[][src]

Expand description

This crate provides a very simple markdown parser.

It’s the basis of the termimad lib, which displays static and dynamic markdown snippets on a terminal without mixing the skin with the code and wrapping the text and tables as needed.

It can be used on its own:

use minimad::*;

assert_eq!(
    parse_line("## a header with some **bold**!"),
    Line::new_header(
        2,
        vec![
            Compound::raw_str("a header with some "),
            Compound::raw_str("bold").bold(),
            Compound::raw_str("!"),
        ]
    )
);

assert_eq!(
    parse_inline("*Italic then **bold and italic `and some *code*`** and italic*"),
    Composite::from(vec![
        Compound::raw_str("Italic then ").italic(),
        Compound::raw_str("bold and italic ").bold().italic(),
        Compound::raw_str("and some *code*").bold().italic().code(),
        Compound::raw_str(" and italic").italic(),
    ])
);

The mad_inline macro is useful for semi-dynamic markdown building: it prevents characters like '*' from messing the style:

use minimad::*;

let md1 = mad_inline!(
    "**$0 formula:** *$1*", // the markdown template, interpreted only once
    "Disk",  // fills $0
    "2*π*r", // fills $1. Note that the stars don't mess the markdown
);
let md2 = Composite::from(vec![
    Compound::raw_str("Disk formula:").bold(),
    Compound::raw_str(" "),
    Compound::raw_str("2*π*r").italic(),
]);

Note that Termimad contains macros and tools to deal with templates. If your goal is to print in the console you should use Termimad’s functions.

Re-exports

pub use clean::*;
pub use once_cell;

Modules

Macros

build an inline from a string literal intepreted as markdown and optional arguments which may fill places designed as $0..$9

Structs

a composite is a monoline sequence of compounds. It’s defined by

a Compound is a part of a line with a consistent styling. It can be part of word, several words, some inline code, or even the whole line.

a template built from a markdown string, with optional placeholder

The structure parsing a line or part of a line. A LineParser initialized from a markdown string exposes 2 main methods:

A template expander owning the value you set so that you don’t have to keep them around until you produce the text to display. Additionnaly, the same expander can be used for several templates.

an expander for a sub template. You get it using the sub method of the text expander

A facility to build templates for tables

a text, that is just a collection of lines

a markdown template allowing you to replace some placeholders with given values, or to expand some sub-templates with repetitions (useful with lists, table rows, etc.)

an expander you get from a template. You specify replacements on the expander then you ask it the text using expand

Enums

Left, Center, Right or Unspecified

The global style of a composite

a parsed line

Constants

Functions

count the number of ‘#’ at start. Return 0 if they’re not followed by a ’ ’ or if they’re too many

parse a monoline markdown snippet which isn’t from a text. Don’t produce some types of line: TableRow, Code, ListItem as they only make sense in a multi-line text.

parse a line, which is meant to be part of a markdown text. This function shouldn’t usually be used: if you don’t want a text you probably need parse_inline

parse a markdown text