Skip to main content

A static web server with markdown rendering feature

Project description

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.

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

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

static-markdown-0.3.0.tar.gz (8.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

static_markdown-0.3.0-py2.py3-none-any.whl (9.6 kB view details)

Uploaded Python 2Python 3

File details

Details for the file static-markdown-0.3.0.tar.gz.

File metadata

  • Download URL: static-markdown-0.3.0.tar.gz
  • Upload date:
  • Size: 8.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/2.7.12

File hashes

Hashes for static-markdown-0.3.0.tar.gz
Algorithm Hash digest
SHA256 89df1795aac4672963bb92776aefa542ace84a0d86f413092343228ed5240931
MD5 cca9752afc7a4152ce8af33d59ac30e8
BLAKE2b-256 6162429bf2df69eecfdf05bd16f1bd7b156146cec0988166e11572ca38e9fd51

See more details on using hashes here.

File details

Details for the file static_markdown-0.3.0-py2.py3-none-any.whl.

File metadata

  • Download URL: static_markdown-0.3.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 9.6 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/2.7.12

File hashes

Hashes for static_markdown-0.3.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 ccc3792a3b5f0f717899e2f69a45ffc69443c940f850d68d9e928915fd876cf6
MD5 91c305cf4f3fa6f9310a74fd83d3aa39
BLAKE2b-256 8613b315e81152796a26aaa439773b0cae57622347003031ee4fef1d6b6f3e7d

See more details on using hashes here.

Supported by

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