Skip to main content

Add an extra dimension to your markdown documents

Project description

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 and styling within markdown documents. So, how does it work?

Overview

SMD is currently a python module that parses SMD into formatted html and css. Currently, the module uses mistune to parse the markdown parts of .smd documents. The general idea is that a static site could use these easy-to-write SMD files in place of html templates or the like. If you’re wondering what makes SMD so special, jump down to the SMD vs MD section.

Installation

Well, I finally got it working with pip, so

pip install structured-markdown

will now work! (I’m using Python >= 3.7, btw.)

If you want to build from source, simply:

git clone https://github.com/Structured-Markdown/structured_markdown.git
cd structured_markdown
pip install .

(At least, that’s what works for me.)

You may also need to install mistune, a markdown parser.

pip install mistune

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

Usage

To use SMD in your project, import it like so:

import structured_markdown as smd

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

with open("example.smd", "r") as fin:
    inp = fin.read()

html, css = smd.parse(inp)

if you wish to get back only html or css, do the following:

html = smd.parse(inp, html=True)
css = smd.parse(inp, css=True)

I’m planning to add templating capabilities to SMD, but it’s not done yet 😔.

SMD vs MD

All squares are rectangles, but not all rectangles are squares. The same can be said of SMD - All Markdown documents are valid SMD documents, but not necessarily the other way around. With that out of the way, what’s the difference?

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

layer welcome:
  # Welcome to Structured-Markdown!
  this is markdown embedded within a layer.

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

<div class='root'>
  <div class='welcome'>
    <h1>Welcome to Structured-Markdown!</h1>
    <p>this is markdown embedded within a layer.</p>
  </div>
</div>

Essentially, a layer is a div, the layer name being the div‘s class. Everything is put into a root div before the parsed SMD is returned.

Nesting is pretty simple:

layer welcome:
  # Welcome to Structured-Markdown!
  this is markdown embedded within a layer.
  layer nested:
    hey, this is nested
  more markdown after the nesting

Which becomes:

<div class='root'>
  <div class='welcome'>
    <h1>Welcome to Structured-Markdown!</h1>
    <p>this is markdown embedded within a layer.</p>
    <div class='welcome'>
      <p>hey, this is nested</p>
    </div>
    <p>more markdown after the nesting</p>
  </div>
</div>

Where it really shines is when text is wrapped in complex formatting, like this navbar example:

layer navbar:
    layer logotype:
        # Templating Engine
    layer navlinks:
        1. [blog](/blog)
        2. [about](/about)
        3. [projects](/projects)

Note that the expanded html is longer and more verbose.

<div class='root'>
  <div class='navbar'>
    <div class='logotype'>
      <h1>Templating Engine</h1>
    </div>
    <div class='navlinks'>
      <ol>
      <li><a href="/blog">blog</a></li>
      <li><a href="/about">about</a></li>
      <li><a href="/projects">projects</a></li>
      </ol>
    </div>
  </div>
</div>

So, what about styling? I was feeling a bit lazy, and had to refactor a lot of code to introduce styling, so for now it’s practically a one to one mapping to css. Here’s what styling looks like:

style layer:
    border = 1px solid
    font-family = sans-serif

use the style keyword to indent a style block - then, for each line in the style block, put the element on the left, followed by an equals sign, followed by the attribute.

style layer.navbar:
    background-color = #fff

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.)

layer.navbar a:hover:
    color = #888

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.

That’s about it for now. Not all features are implemented as this is still a WIP.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

structured_markdown-0.2.0.tar.gz (6.5 kB view details)

Uploaded Source

Built Distribution

structured_markdown-0.2.0-py3-none-any.whl (7.3 kB view details)

Uploaded Python 3

File details

Details for the file structured_markdown-0.2.0.tar.gz.

File metadata

  • Download URL: structured_markdown-0.2.0.tar.gz
  • Upload date:
  • Size: 6.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.2

File hashes

Hashes for structured_markdown-0.2.0.tar.gz
Algorithm Hash digest
SHA256 6312c1d69c7c5f92f06965705342e23fbb95fa97ea65c76a2266f9123d7d7644
MD5 0eaad4f621f59273fb0704415628e4c9
BLAKE2b-256 27fa7084bf8590d5ee3df29254c393906d2355f47754c54b3be172fc5f17da7a

See more details on using hashes here.

File details

Details for the file structured_markdown-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: structured_markdown-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 7.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.2

File hashes

Hashes for structured_markdown-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 bbf9bb6229bc778a9e3a39c57096d980ab5e4ef47baa418fe99854c8976ee5b8
MD5 ffe8d0dcfc5cea8db32dd65fd2e7da14
BLAKE2b-256 7c8378f568726fce6cfcc860eb9ddb6878a7047f99b46c00ebc1ddc1a6902f5e

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page