doccy 0.1.3

Doccy is a simple brace based markup language.
Documentation

Doccy

Doccy is a simple brace based markup language, an alternative to writing HTML for people who enjoy the power and flexibility but do not enjoy writing it.

Syntax

Paragraphs

Any text contained within specific contexts will be treated as one or more paragraphs if separated by two or more line breaks and it contains only inline elements.

Document body

This is a paragraph.

{h1: This is a header.}

And this is another.

Renders as:

<p>This is a paragraph.</p>
<h1>This is a header.</h1>
<p>And this is another.</p>

Special elements

The following elements also automatically wrap paragraphs: article, aside, blockquote, div, fieldset, footer, form, header, hgroup, main and section.

{blockquote: This is a paragraph.

And this is another.}

Renders as:

<blockquote>
    <p>This is a paragraph.</p>
    <p>And this is another.</p>
</blockquote>

Elements

Anything between two curley-braces is considered an element if:

  • Immediately following the opening brace, a valid element name is found,
  • followed by whitespace or attributes,
  • and finaly a colon (:).

For example, the following are all valid:

{h1:Top-level heading}
{p : A paragraph}

There is one exception to this rule, line breaks (<br>) can be written as:

{br}

Attributes

Anything between the opening curley-brace and colon is considered an attribute if:

  • It begins with one of @, #, %, .,
  • followed by a valid identifier ([a-zA-Z][a-zA-Z0-9]*)
  • and optionally a value.

Named Attributes

A named attribute with a value looks like:

{h1 @class main header: Header}

Renders as:

<h1 class="main header">Header</h1>

Without a value:

{input @required}

Renders as:

<input required>

Values containing special characters must be escaped:

{h1 @test Bad characters\: \@\#\%\.\{\}: ...}

Renders as:

<h1 test="Bad characters: @#%.{}">...</h1>

Data Attributes

A shorthand for data- attributes:

{pre %lang html: ...}
{pre %html: ...}

Renders as:

<pre data-lang="html">...</pre>
<pre data-html>...</pre>

As with named attributes, special characters must be escaped.

Class Attributes

A shorthand for class="..." attributes:

{h1.main.header: Header}

Renders as:

<h1 class="main header">Header</h1>

Id Attributes

A shorthand for id="..." attributes:

{h1#main: Header}

Renders as:

<h1 id="main">Header</h1>

Usage

Rust

extern crate doccy;

use doccy::doccy_to_html;

fn main() {
    match doccy_to_html("your document here") {
        Ok(html) => println!("{:?}", html), // <p>your document here</p>
        Err(error) => {}
    };
}