Version 0.2.0

(This isn't really documentation, just the README. Real documentation will be added in the future.)

Structured-Markdown

I love markdown, but I've always wanted to use it to write more than just "flat" documents. Structured Markdown is an extension to markdown syntax that allows for nesting, styling, and templating within markdown documents. So, how does it work?

Table of Contents

Here are the different sections in this README. If you're looking for the documentation, it's herearrow-up-right.

Overview

Structured Markdown, or SMD, is a syntactic extension to Markdown. SMD documents support structuring, styling, and templating. structured_markdown is a Python module that parses SMD documents into formatted html and css. Currently, the module uses mistunearrow-up-right to parse the markdown parts of SMD documents. this project aims to make SMD more commonplace in static site development. If you're wondering what makes SMD different from normal MD, jump down to the SMD vs MDarrow-up-right section.

Installation

To install the most recent stable version of structured_markdown, you can use pip. This project was written using Python >= 3.7, but most earlier versions of Python 3 should work.

$ pip install structured-markdown

If you like the bleeding edge, you can build from source.

You might also need to install mistune, a markdown parser, and m2r.

Remember to use pip3 when working with Python 3. (I always forget to use pip3, so I thought you might like a little reminder 👍.)

Usage

To use structured_markdown in your projects, import it like so. (We recommend using smd as an import alias as structured_markdown is a bit long.)

The main purpose of structured_markdown is to parse SMD documents. This is pretty simple:

The smd.parse function takes a SMD string and returns formatted html and css There are many other functions availiable in the structured_markdown package.

structured_markdown also supports basic templating. We hope to extend structured_markdown's templating features soon.

If you want to quickly template in some fields, you can add additional keywords to structured_markdown function calls. For example, let's say you have the following SMD document called template.smd.

In this document, we have 3 templating fields: title, adjective, and font_name. (Note that templating fields are wrapped in {{}}. There needs to be a space around each templating field: {{ this_is_valid }}, {{this_is_not}}.) To fill in these fields, we need to pass values to them. Here's an example.

You can even use pass markdown (and other SMD documents).

That's a basic introduction to using SMD. I hope you find it enjoyable 😁.

SMD vs MD

This is a deeper dive into what SMD is and how it works.

A Structured Markdown can be thought of an extension of Markdown. Just like how all squares are rectangles, but not all rectangles are squares, all Markdown documents are valid SMD documents, but not necessarily the other way around. So, what are the extensions that SMD offers?

A SMD document is made of layers. Each layer has a name and can contain markdown content and/or other layers.

This is a block of markdown within a layer whose name is welcome. Here is the equivalent html.

Essentially, a layer is a div, the layer name being the div's class. Nesting is pretty simple:

Which becomes:

Here is some simple SMD that expands to a lot more html:

Here's the equivalent html.

So, what about styling? (Side Note: when I was implementing styling support, I had to refactor a large amount of code. because of this I didn't have time to implement a more advanced form of styling, so for now it's essentially a one to one mapping to css.) Here's what styling looks like:

Style blocks are created using the style keyword to indent a style block. After the style block is a css selector. For each line in the style block, put the css element on the left, followed by an equals sign, followed by the attribute.

All normal css selectors should work, note that you should use the word layer instead of div. (You can still use div if you'd like, layer makes it look more readable and unified in my opinion.) Here's another example fo a selector.

When parsed, SMD style blocks are fully transpiled into css. Hopefully, in the future I'll've implemented a better styling system, but this is what's here to stay for now.

[The section on templating is not completed yet...]

That's all for now. Thanks for following along this far.

Last updated

Was this helpful?