Skip to main content

Static Markdown

A static web server with markdown rendering feature.

It serves regular HTTP content (HTML, JS, CSS, images, etc), but when you're browsing a .md, .mdown or .markdown file, it's converted into HTML and rendered as a (hopefully) readable page.

PyPI - Python Version Travis CI status

IMPORTANT WARNING

This server is not recommended for production. It's a toy to serve static files and Markdown content, but there's no guarantee about security, performance, availability, etc.

Installation

via PyPI

Install this tool using pip to download it from PyPI. You may prefer to use a virtualenv, but you may also want to install "user-wide".

pip install static-markdown
pip install --user static-markdown

Using the source

We're advising you to use virtualenv to install this package. Clone this repository, and, inside your virtualenv, run the following:

pip install -e ./

Usage

Once it's installed, you can just change your current shell session to the designated directory and run the following:

cd /path/to/directory
serve-md

Alternatively, you can also run this command line from anywhere, but set the target path as a command argument:

serve-md /path/to/directory

Using these default option, you can now browse your "static website" by pointing your browser to: http://127.0.0.1:8080/.

Stop the server with Ctrl-C.

Options

usage: serve-md [-h] [-p PORT] [--markdown-template MARKDOWN_TEMPLATE]
                [--stylesheet STYLESHEET] [--version]
                [root]

positional arguments:
  root                  Path to serve statically

optional arguments:
  -h, --help            show this help message and exit
  -p PORT, --port PORT  Port number (0-65535)
  --markdown-template MARKDOWN_TEMPLATE
                        Path to an alternate HTML template for Markdown files
  --stylesheet STYLESHEET
                        Path to a custom stylesheet
  --version             Return version and exit

Browsing

Let's consider the following path tree:

.
├── empty
├── images
│   └── knight.png
├── index.html
├── mdown
│   └── index.md
├── mdown-readme
│   └── README.md
└── subdir
    └── index.html

Here is a table describing the different pages rendered with the given URL in your browser

URL Content Content type Status Code
/ index.html text/html 200 OK
/empty directory listing text/html 200 OK
/images/knight.png knight.png (as binary) image/png 200 OK
/mdown/ index.md (as HTML) text/html 200 OK
/mdown/index.md index.md (as HTML) text/html 200 OK
/mdown-readme README.md (as HTML) text/html 200 OK
/subdir redirect to /subdir/ - 301 MOVED PERMANENTLY
/subdir/ subdir/index.html text/html 200 OK

Indexes

When browsing a directory, serve-md will look after the following files, in that specific order: "index.html", "index.htm", "index.md", "README.md", "readme.md". The first one of them to be found will be served as the index page of the directory.

If none of them is found, serve-md will return a directory listing. If you're using the "Markdown template" feature, it'll be used when rendering this page.

HTTP Verbs

GET & HEAD verbs are implemented.

POST, PUT, DELETE will result into a 405 Method Not Allowed error.

Markdown templates

By default, Markdown files will be rendered as HTML using a minimal CSS. Using the --markdown-template option, you can use your own HTML template with a custom CSS to render generate the text/html. You can find various examples in the example-options directory in the source repository.

We've used various minimalist CSS frameworks for rendering and layout:

Custom styles

If the only thing you need is to customize styles, but not the structure of your HTML page, you can use the --stylesheet option to point at a CSS file.

Example:

serve-md /path/to/directory --stylesheet ~/my-style.css

Hack

  1. Clone this repository.
  2. Write tests.
  3. Implement stuff.
  4. Open a Pull Request.

Important: Each time you're modifying any line of the server's code, if you want to test your patch live, you HAVE to stop and restart the application.

Run automated tests

In a shell session, run tests with:

make test

Metadata

Release files for static-markdown 0.4.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for static-markdown 0.4.0
File Size Uploaded
static-markdown-0.4.0.tar.gz 11.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for static-markdown 0.4.0
File Interpreter ABI Platform
static_markdown-0.4.0-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 20.9 kB

Release files / static-markdown-0.4.0.tar.gz

Download URL static-markdown-0.4.0.tar.gz
Size 11.2 kB
Tags Source
SHA-256 checksum
How to use checksums
3f80a3aa0ddb03292337ee8329dfb0efc178c924eb36c7440be8e91e509872b2
BLAKE2b-256 checksum
How to use checksums
211b70104dbc840ba695c6dfc41a399870d2728fab3af96460f53dc4df79fca2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.0

Release files / static_markdown-0.4.0-py2.py3-none-any.whl

Download URL static_markdown-0.4.0-py2.py3-none-any.whl
Size 9.7 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
26c9bfdd28bdfb5d9ea247e87915f2a7f659b59fbc9f14eb4c0dba13669ab38e
BLAKE2b-256 checksum
How to use checksums
2d6c928b0849df75a746f65577928d22c0c8d5b073f0b62344af3e97ec8eec2b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.0

Release history Release notifications | RSS feed

This release

0.4.0 This release

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page