actix-mark
An actix-web service for serving Markdown files as HTML. Drop it into your app the same way you would actix-files::Files: point it at a directory, give it an HTML template, and it will render every .md file on the fly. Non-Markdown files (CSS, images, …) are passed through unchanged.
Features
- Template-based rendering — provide any HTML file with a
<markdown>tag; the rendered content is injected there - Clean URLs —
/docs/guideresolves toguide.md; the.mdextension also works directly - Nested directories — subdirectories are handled recursively;
/docs/resolves toindex.md - Static asset pass-through — CSS, images, and other files in the same directory are served as-is
- Markdown extensions — tables, strikethrough, footnotes, and task lists enabled via pulldown-cmark
- Path traversal protection — requests cannot escape the served directory
Installation
[]
= "4"
= "0.9"
Usage
Minimal example
use ;
use MarkdownFiles;
async
Loading the template from a file at startup
new
.template_file?
template_file reads the file eagerly, so a missing or unreadable template is reported at startup rather than on the first request.
Template format
The template is any valid HTML file containing a <markdown> tag (self-closing variants <markdown/> and <markdown /> are also accepted). The tag is replaced with the rendered HTML.
My docs
The stylesheet can live in the same content directory and will be served as a static file.
URL mapping
| Request URL | File served |
|---|---|
/docs/ |
<dir>/index.md |
/docs/guide |
<dir>/guide.md |
/docs/guide.md |
<dir>/guide.md |
/docs/api/intro |
<dir>/api/intro.md |
/docs/style.css |
<dir>/style.css (static) |
| anything else | 404 |
Running the example
The repository includes a working example with sample Markdown pages and a stylesheet:
Then open http://localhost:8080/docs/.
License
Licensed under the Apache License, Version 2.0.