markdotserver 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- markdotserver-0.1.0/LICENSE +21 -0
- markdotserver-0.1.0/PKG-INFO +243 -0
- markdotserver-0.1.0/README.md +216 -0
- markdotserver-0.1.0/pyproject.toml +123 -0
- markdotserver-0.1.0/setup.cfg +4 -0
- markdotserver-0.1.0/src/markdotserver/__init__.py +7 -0
- markdotserver-0.1.0/src/markdotserver/__main__.py +252 -0
- markdotserver-0.1.0/src/markdotserver/app.py +191 -0
- markdotserver-0.1.0/src/markdotserver/config.py +118 -0
- markdotserver-0.1.0/src/markdotserver/filesystem.py +547 -0
- markdotserver-0.1.0/src/markdotserver/graphviz_renderer.py +333 -0
- markdotserver-0.1.0/src/markdotserver/markdown_renderer.py +516 -0
- markdotserver-0.1.0/src/markdotserver/py.typed +1 -0
- markdotserver-0.1.0/src/markdotserver/routes.py +741 -0
- markdotserver-0.1.0/src/markdotserver/static/css/app.css +888 -0
- markdotserver-0.1.0/src/markdotserver/static/js/app.js +741 -0
- markdotserver-0.1.0/src/markdotserver/static/js/theme.js +24 -0
- markdotserver-0.1.0/src/markdotserver/templates/base.html +19 -0
- markdotserver-0.1.0/src/markdotserver/templates/index.html +41 -0
- markdotserver-0.1.0/src/markdotserver/templates/partials/directory_tree.html +44 -0
- markdotserver-0.1.0/src/markdotserver/templates/partials/document.html +71 -0
- markdotserver-0.1.0/src/markdotserver/templates/partials/error.html +7 -0
- markdotserver-0.1.0/src/markdotserver/templates/partials/headings.html +24 -0
- markdotserver-0.1.0/src/markdotserver/templates/partials/toolbar.html +46 -0
- markdotserver-0.1.0/src/markdotserver.egg-info/PKG-INFO +243 -0
- markdotserver-0.1.0/src/markdotserver.egg-info/SOURCES.txt +28 -0
- markdotserver-0.1.0/src/markdotserver.egg-info/dependency_links.txt +1 -0
- markdotserver-0.1.0/src/markdotserver.egg-info/entry_points.txt +2 -0
- markdotserver-0.1.0/src/markdotserver.egg-info/requires.txt +7 -0
- markdotserver-0.1.0/src/markdotserver.egg-info/top_level.txt +1 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Alexey Agafonov
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: markdotserver
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Lightweight, read-only HTTP viewer for Markdown and Graphviz documentation
|
|
5
|
+
Author-email: Alexey Agafonov <128855676+lucir13@users.noreply.github.com>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/lucir13/markdotserver
|
|
8
|
+
Project-URL: Repository, https://github.com/lucir13/markdotserver
|
|
9
|
+
Project-URL: Issues, https://github.com/lucir13/markdotserver/issues
|
|
10
|
+
Keywords: markdown,graphviz,documentation,viewer,dot,svg
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
12
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
13
|
+
Classifier: Topic :: Documentation
|
|
14
|
+
Classifier: Topic :: Internet :: WWW/HTTP :: HTTP Servers
|
|
15
|
+
Classifier: Intended Audience :: Developers
|
|
16
|
+
Requires-Python: >=3.12
|
|
17
|
+
Description-Content-Type: text/markdown
|
|
18
|
+
License-File: LICENSE
|
|
19
|
+
Requires-Dist: fastapi>=0.115
|
|
20
|
+
Requires-Dist: uvicorn>=0.30
|
|
21
|
+
Requires-Dist: starlette>=0.40
|
|
22
|
+
Requires-Dist: jinja2>=3.1
|
|
23
|
+
Requires-Dist: markdown-it-py>=3.0
|
|
24
|
+
Requires-Dist: mdit-py-plugins>=0.4
|
|
25
|
+
Requires-Dist: pygments>=2.21
|
|
26
|
+
Dynamic: license-file
|
|
27
|
+
|
|
28
|
+
# markdotserver
|
|
29
|
+
|
|
30
|
+
A lightweight, read-only HTTP server for browsing an existing documentation tree of
|
|
31
|
+
Markdown documents, Graphviz diagrams, images and plain text files.
|
|
32
|
+
|
|
33
|
+
Point it at a directory and open a browser. There is no configuration file, build
|
|
34
|
+
step, database or generated site, and the server never modifies the documentation
|
|
35
|
+
directory.
|
|
36
|
+
|
|
37
|
+
[](https://github.com/lucir13/markdotserver/actions/workflows/ci.yml)
|
|
38
|
+
[](LICENSE)
|
|
39
|
+
|
|
40
|
+
## Features
|
|
41
|
+
|
|
42
|
+
- Server-side rendered two-pane interface with a resizable, collapsible sidebar.
|
|
43
|
+
- Files and Headings tabs, nested directory tree and heading navigation.
|
|
44
|
+
- Markdown rendering with heading anchors, Pygments highlighting, task lists,
|
|
45
|
+
tables, relative-link rewriting and safe URL handling.
|
|
46
|
+
- Graphviz `.dot` and `.gv` documents rendered to SVG through the OS `dot`
|
|
47
|
+
executable, with zoom, fit, reset and download controls.
|
|
48
|
+
- Embedded Graphviz fences rendered to inline SVG data URIs.
|
|
49
|
+
- Image, SVG and plain-text viewing.
|
|
50
|
+
- Directory URLs render an index of their visible entries.
|
|
51
|
+
- Bookmarkable document URLs, direct navigation, browser history and heading deep
|
|
52
|
+
links.
|
|
53
|
+
- Fragment-swap navigation served entirely from local assets, with a normal
|
|
54
|
+
full-page fallback.
|
|
55
|
+
- Light and dark themes plus persistent sidebar, tab and tree state.
|
|
56
|
+
- Strict Content-Security-Policy and security headers on every response, with no
|
|
57
|
+
inline scripts or styles in the page shell.
|
|
58
|
+
- Path confinement, hidden-path filtering, symlink-escape checks, a depth-bounded
|
|
59
|
+
tree and read-only operation.
|
|
60
|
+
- Bounded caching for the directory tree and rendered diagrams, and a dedicated
|
|
61
|
+
worker pool so slow documents cannot stall the rest of the server.
|
|
62
|
+
|
|
63
|
+
## Requirements
|
|
64
|
+
|
|
65
|
+
- Python 3.12 or newer
|
|
66
|
+
- Graphviz with the `dot` executable on `PATH`
|
|
67
|
+
- A modern browser
|
|
68
|
+
|
|
69
|
+
Install Graphviz first, for example:
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
# Debian / Ubuntu
|
|
73
|
+
sudo apt install graphviz
|
|
74
|
+
|
|
75
|
+
# Fedora / RHEL
|
|
76
|
+
sudo dnf install graphviz
|
|
77
|
+
|
|
78
|
+
# macOS
|
|
79
|
+
brew install graphviz
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
Verify it with `dot -V`.
|
|
83
|
+
|
|
84
|
+
## Quick start
|
|
85
|
+
|
|
86
|
+
From the repository root:
|
|
87
|
+
|
|
88
|
+
```bash
|
|
89
|
+
python3.12 -m venv .venv
|
|
90
|
+
source .venv/bin/activate
|
|
91
|
+
python -m pip install --upgrade pip
|
|
92
|
+
python -m pip install -e .
|
|
93
|
+
python -m markdotserver --root examples --port 8765
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
Open <http://127.0.0.1:8765/>. The server redirects to `examples/README.md`.
|
|
97
|
+
|
|
98
|
+
To serve your own documentation:
|
|
99
|
+
|
|
100
|
+
```bash
|
|
101
|
+
python -m markdotserver --root /path/to/docs
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
Useful options:
|
|
105
|
+
|
|
106
|
+
```text
|
|
107
|
+
--root DIRECTORY documentation root (default: current directory)
|
|
108
|
+
--host HOST bind interface (default: 127.0.0.1)
|
|
109
|
+
--port PORT bind port (default: 8000)
|
|
110
|
+
--graphviz-engine EXECUTABLE Graphviz executable (default: dot)
|
|
111
|
+
--graphviz-timeout SECONDS Graphviz render timeout (default: 10.0)
|
|
112
|
+
--max-graphviz-source-bytes BYTES maximum DOT source size (default: 2000000)
|
|
113
|
+
--max-graphviz-output-bytes BYTES maximum rendered SVG size (default: 32000000)
|
|
114
|
+
--max-text-file-bytes BYTES maximum text document size (default: 5000000)
|
|
115
|
+
--max-tree-depth DEPTH maximum directory tree depth (default: 32)
|
|
116
|
+
--tree-cache-ttl SECONDS directory tree cache lifetime (default: 2.0)
|
|
117
|
+
--max-embedded-diagrams COUNT embedded diagrams per document (default: 32)
|
|
118
|
+
--render-deadline SECONDS per-document render deadline (default: 30.0)
|
|
119
|
+
--render-workers COUNT shared rendering pool size (default: 4)
|
|
120
|
+
--svg-cache-entries COUNT rendered SVGs kept in memory (default: 32)
|
|
121
|
+
--version print the version
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
The root must already exist and be readable. If it contains `README.md`,
|
|
125
|
+
`readme.md`, `index.md` or `INDEX.md`, `/` redirects to that document; otherwise a
|
|
126
|
+
welcome page is shown.
|
|
127
|
+
|
|
128
|
+
## Supported formats
|
|
129
|
+
|
|
130
|
+
| Extension | Display |
|
|
131
|
+
|---|---|
|
|
132
|
+
| `.md`, `.markdown` | Rendered Markdown with headings and links |
|
|
133
|
+
| `.dot`, `.gv` | SVG rendered by Graphviz |
|
|
134
|
+
| `.svg`, `.png`, `.jpg`, `.jpeg`, `.gif`, `.webp` | Image asset |
|
|
135
|
+
| `.txt` | Escaped plain text |
|
|
136
|
+
| directory | Index of the visible entries |
|
|
137
|
+
|
|
138
|
+
All other file types are omitted from the tree and rejected by direct requests.
|
|
139
|
+
|
|
140
|
+
### Embedded Graphviz
|
|
141
|
+
|
|
142
|
+
Fence DOT source in Markdown with `dot` or `graphviz`:
|
|
143
|
+
|
|
144
|
+
````markdown
|
|
145
|
+
```dot
|
|
146
|
+
digraph G {
|
|
147
|
+
a -> b;
|
|
148
|
+
}
|
|
149
|
+
```
|
|
150
|
+
````
|
|
151
|
+
|
|
152
|
+
The diagram is rendered when the page is requested and embedded as an SVG data URI.
|
|
153
|
+
No temporary files are written.
|
|
154
|
+
|
|
155
|
+
### Relative links
|
|
156
|
+
|
|
157
|
+
Links and images in Markdown are resolved relative to the source document. Supported
|
|
158
|
+
documents are served through the viewer, images through the asset route and Graphviz
|
|
159
|
+
images through the SVG route. Unsafe URL schemes are removed, and raw HTML is
|
|
160
|
+
disabled.
|
|
161
|
+
|
|
162
|
+
## Remote access
|
|
163
|
+
|
|
164
|
+
Keep the default loopback bind and forward the port over SSH:
|
|
165
|
+
|
|
166
|
+
```bash
|
|
167
|
+
# On the server
|
|
168
|
+
python -m markdotserver --root /srv/docs --port 8765
|
|
169
|
+
|
|
170
|
+
# On the client
|
|
171
|
+
ssh -L 8765:127.0.0.1:8765 user@server.example.com
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
Then open <http://127.0.0.1:8765/> locally.
|
|
175
|
+
|
|
176
|
+
## Security summary
|
|
177
|
+
|
|
178
|
+
- Route paths are validated and resolved against the documentation root; traversal,
|
|
179
|
+
absolute paths, hidden names and symlink escapes are rejected. Reads and asset
|
|
180
|
+
responses open the final component with `O_NOFOLLOW` so it cannot be swapped for
|
|
181
|
+
a symlink in between.
|
|
182
|
+
- Markdown raw HTML is disabled and unsafe URL schemes are stripped.
|
|
183
|
+
- SVGs are served as image assets with `nosniff` and a sandboxing CSP.
|
|
184
|
+
- Graphviz runs without a shell, with fixed arguments, stdin/stdout only, source
|
|
185
|
+
and output size limits and a hard timeout, and its output is validated as SVG
|
|
186
|
+
without scripts, event handlers or `javascript:` links before it is served.
|
|
187
|
+
- Every response carries `nosniff`, `Referrer-Policy`, `X-Frame-Options` and a
|
|
188
|
+
Content-Security-Policy; pages use a strict policy with no `'unsafe-inline'`.
|
|
189
|
+
- Rendering is bounded: tree depth, embedded diagrams per document, a per-document
|
|
190
|
+
render deadline and a fixed-size worker pool.
|
|
191
|
+
- The server has no write endpoints and never modifies the documentation directory.
|
|
192
|
+
- There is no authentication or HTTPS. Do not expose the viewer to untrusted
|
|
193
|
+
networks.
|
|
194
|
+
|
|
195
|
+
**Graphviz is not a sandbox.** DOT files must be trusted; malicious graphs can still
|
|
196
|
+
consume resources or exploit Graphviz bugs. See [Security](docs/security.md).
|
|
197
|
+
|
|
198
|
+
## Testing
|
|
199
|
+
|
|
200
|
+
```bash
|
|
201
|
+
python -m pip install --group test
|
|
202
|
+
pytest -q
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
Lint and type checks, enforced by CI:
|
|
206
|
+
|
|
207
|
+
```bash
|
|
208
|
+
python -m pip install --group dev
|
|
209
|
+
ruff check src tests
|
|
210
|
+
black --check src tests
|
|
211
|
+
mypy
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
The suite uses temporary directories and fake renderers, with optional integration
|
|
215
|
+
tests against the real `dot` executable. Browser-only interactions are verified
|
|
216
|
+
manually against `examples/`.
|
|
217
|
+
|
|
218
|
+
## Documentation
|
|
219
|
+
|
|
220
|
+
- [Documentation index](docs/index.md)
|
|
221
|
+
- [Installation](docs/installation.md)
|
|
222
|
+
- [Usage](docs/usage.md)
|
|
223
|
+
- [Supported formats](docs/formats.md)
|
|
224
|
+
- [Architecture](docs/architecture.md)
|
|
225
|
+
- [Security](docs/security.md)
|
|
226
|
+
- [Testing](docs/testing.md)
|
|
227
|
+
- [Limitations](docs/limitations.md)
|
|
228
|
+
- [Detailed design](docs/design.md)
|
|
229
|
+
- [Security policy](SECURITY.md)
|
|
230
|
+
- [Third-party notices](THIRD_PARTY_NOTICES.md)
|
|
231
|
+
|
|
232
|
+
## Project status
|
|
233
|
+
|
|
234
|
+
The project is feature-complete: package scaffolding, configuration and path
|
|
235
|
+
confinement, Graphviz and Markdown rendering, the HTTP interface, the two-pane
|
|
236
|
+
interface, the example tree, complete documentation, hardening and acceptance
|
|
237
|
+
verification are all in place. See the [detailed design](docs/design.md) for the
|
|
238
|
+
architecture and implementation decisions.
|
|
239
|
+
|
|
240
|
+
## Licence
|
|
241
|
+
|
|
242
|
+
MIT. See [LICENSE](LICENSE). Reuse and redistribution are permitted provided the
|
|
243
|
+
copyright notice and permission notice in that file are retained with the software.
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
# markdotserver
|
|
2
|
+
|
|
3
|
+
A lightweight, read-only HTTP server for browsing an existing documentation tree of
|
|
4
|
+
Markdown documents, Graphviz diagrams, images and plain text files.
|
|
5
|
+
|
|
6
|
+
Point it at a directory and open a browser. There is no configuration file, build
|
|
7
|
+
step, database or generated site, and the server never modifies the documentation
|
|
8
|
+
directory.
|
|
9
|
+
|
|
10
|
+
[](https://github.com/lucir13/markdotserver/actions/workflows/ci.yml)
|
|
11
|
+
[](LICENSE)
|
|
12
|
+
|
|
13
|
+
## Features
|
|
14
|
+
|
|
15
|
+
- Server-side rendered two-pane interface with a resizable, collapsible sidebar.
|
|
16
|
+
- Files and Headings tabs, nested directory tree and heading navigation.
|
|
17
|
+
- Markdown rendering with heading anchors, Pygments highlighting, task lists,
|
|
18
|
+
tables, relative-link rewriting and safe URL handling.
|
|
19
|
+
- Graphviz `.dot` and `.gv` documents rendered to SVG through the OS `dot`
|
|
20
|
+
executable, with zoom, fit, reset and download controls.
|
|
21
|
+
- Embedded Graphviz fences rendered to inline SVG data URIs.
|
|
22
|
+
- Image, SVG and plain-text viewing.
|
|
23
|
+
- Directory URLs render an index of their visible entries.
|
|
24
|
+
- Bookmarkable document URLs, direct navigation, browser history and heading deep
|
|
25
|
+
links.
|
|
26
|
+
- Fragment-swap navigation served entirely from local assets, with a normal
|
|
27
|
+
full-page fallback.
|
|
28
|
+
- Light and dark themes plus persistent sidebar, tab and tree state.
|
|
29
|
+
- Strict Content-Security-Policy and security headers on every response, with no
|
|
30
|
+
inline scripts or styles in the page shell.
|
|
31
|
+
- Path confinement, hidden-path filtering, symlink-escape checks, a depth-bounded
|
|
32
|
+
tree and read-only operation.
|
|
33
|
+
- Bounded caching for the directory tree and rendered diagrams, and a dedicated
|
|
34
|
+
worker pool so slow documents cannot stall the rest of the server.
|
|
35
|
+
|
|
36
|
+
## Requirements
|
|
37
|
+
|
|
38
|
+
- Python 3.12 or newer
|
|
39
|
+
- Graphviz with the `dot` executable on `PATH`
|
|
40
|
+
- A modern browser
|
|
41
|
+
|
|
42
|
+
Install Graphviz first, for example:
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
# Debian / Ubuntu
|
|
46
|
+
sudo apt install graphviz
|
|
47
|
+
|
|
48
|
+
# Fedora / RHEL
|
|
49
|
+
sudo dnf install graphviz
|
|
50
|
+
|
|
51
|
+
# macOS
|
|
52
|
+
brew install graphviz
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
Verify it with `dot -V`.
|
|
56
|
+
|
|
57
|
+
## Quick start
|
|
58
|
+
|
|
59
|
+
From the repository root:
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
python3.12 -m venv .venv
|
|
63
|
+
source .venv/bin/activate
|
|
64
|
+
python -m pip install --upgrade pip
|
|
65
|
+
python -m pip install -e .
|
|
66
|
+
python -m markdotserver --root examples --port 8765
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
Open <http://127.0.0.1:8765/>. The server redirects to `examples/README.md`.
|
|
70
|
+
|
|
71
|
+
To serve your own documentation:
|
|
72
|
+
|
|
73
|
+
```bash
|
|
74
|
+
python -m markdotserver --root /path/to/docs
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
Useful options:
|
|
78
|
+
|
|
79
|
+
```text
|
|
80
|
+
--root DIRECTORY documentation root (default: current directory)
|
|
81
|
+
--host HOST bind interface (default: 127.0.0.1)
|
|
82
|
+
--port PORT bind port (default: 8000)
|
|
83
|
+
--graphviz-engine EXECUTABLE Graphviz executable (default: dot)
|
|
84
|
+
--graphviz-timeout SECONDS Graphviz render timeout (default: 10.0)
|
|
85
|
+
--max-graphviz-source-bytes BYTES maximum DOT source size (default: 2000000)
|
|
86
|
+
--max-graphviz-output-bytes BYTES maximum rendered SVG size (default: 32000000)
|
|
87
|
+
--max-text-file-bytes BYTES maximum text document size (default: 5000000)
|
|
88
|
+
--max-tree-depth DEPTH maximum directory tree depth (default: 32)
|
|
89
|
+
--tree-cache-ttl SECONDS directory tree cache lifetime (default: 2.0)
|
|
90
|
+
--max-embedded-diagrams COUNT embedded diagrams per document (default: 32)
|
|
91
|
+
--render-deadline SECONDS per-document render deadline (default: 30.0)
|
|
92
|
+
--render-workers COUNT shared rendering pool size (default: 4)
|
|
93
|
+
--svg-cache-entries COUNT rendered SVGs kept in memory (default: 32)
|
|
94
|
+
--version print the version
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
The root must already exist and be readable. If it contains `README.md`,
|
|
98
|
+
`readme.md`, `index.md` or `INDEX.md`, `/` redirects to that document; otherwise a
|
|
99
|
+
welcome page is shown.
|
|
100
|
+
|
|
101
|
+
## Supported formats
|
|
102
|
+
|
|
103
|
+
| Extension | Display |
|
|
104
|
+
|---|---|
|
|
105
|
+
| `.md`, `.markdown` | Rendered Markdown with headings and links |
|
|
106
|
+
| `.dot`, `.gv` | SVG rendered by Graphviz |
|
|
107
|
+
| `.svg`, `.png`, `.jpg`, `.jpeg`, `.gif`, `.webp` | Image asset |
|
|
108
|
+
| `.txt` | Escaped plain text |
|
|
109
|
+
| directory | Index of the visible entries |
|
|
110
|
+
|
|
111
|
+
All other file types are omitted from the tree and rejected by direct requests.
|
|
112
|
+
|
|
113
|
+
### Embedded Graphviz
|
|
114
|
+
|
|
115
|
+
Fence DOT source in Markdown with `dot` or `graphviz`:
|
|
116
|
+
|
|
117
|
+
````markdown
|
|
118
|
+
```dot
|
|
119
|
+
digraph G {
|
|
120
|
+
a -> b;
|
|
121
|
+
}
|
|
122
|
+
```
|
|
123
|
+
````
|
|
124
|
+
|
|
125
|
+
The diagram is rendered when the page is requested and embedded as an SVG data URI.
|
|
126
|
+
No temporary files are written.
|
|
127
|
+
|
|
128
|
+
### Relative links
|
|
129
|
+
|
|
130
|
+
Links and images in Markdown are resolved relative to the source document. Supported
|
|
131
|
+
documents are served through the viewer, images through the asset route and Graphviz
|
|
132
|
+
images through the SVG route. Unsafe URL schemes are removed, and raw HTML is
|
|
133
|
+
disabled.
|
|
134
|
+
|
|
135
|
+
## Remote access
|
|
136
|
+
|
|
137
|
+
Keep the default loopback bind and forward the port over SSH:
|
|
138
|
+
|
|
139
|
+
```bash
|
|
140
|
+
# On the server
|
|
141
|
+
python -m markdotserver --root /srv/docs --port 8765
|
|
142
|
+
|
|
143
|
+
# On the client
|
|
144
|
+
ssh -L 8765:127.0.0.1:8765 user@server.example.com
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
Then open <http://127.0.0.1:8765/> locally.
|
|
148
|
+
|
|
149
|
+
## Security summary
|
|
150
|
+
|
|
151
|
+
- Route paths are validated and resolved against the documentation root; traversal,
|
|
152
|
+
absolute paths, hidden names and symlink escapes are rejected. Reads and asset
|
|
153
|
+
responses open the final component with `O_NOFOLLOW` so it cannot be swapped for
|
|
154
|
+
a symlink in between.
|
|
155
|
+
- Markdown raw HTML is disabled and unsafe URL schemes are stripped.
|
|
156
|
+
- SVGs are served as image assets with `nosniff` and a sandboxing CSP.
|
|
157
|
+
- Graphviz runs without a shell, with fixed arguments, stdin/stdout only, source
|
|
158
|
+
and output size limits and a hard timeout, and its output is validated as SVG
|
|
159
|
+
without scripts, event handlers or `javascript:` links before it is served.
|
|
160
|
+
- Every response carries `nosniff`, `Referrer-Policy`, `X-Frame-Options` and a
|
|
161
|
+
Content-Security-Policy; pages use a strict policy with no `'unsafe-inline'`.
|
|
162
|
+
- Rendering is bounded: tree depth, embedded diagrams per document, a per-document
|
|
163
|
+
render deadline and a fixed-size worker pool.
|
|
164
|
+
- The server has no write endpoints and never modifies the documentation directory.
|
|
165
|
+
- There is no authentication or HTTPS. Do not expose the viewer to untrusted
|
|
166
|
+
networks.
|
|
167
|
+
|
|
168
|
+
**Graphviz is not a sandbox.** DOT files must be trusted; malicious graphs can still
|
|
169
|
+
consume resources or exploit Graphviz bugs. See [Security](docs/security.md).
|
|
170
|
+
|
|
171
|
+
## Testing
|
|
172
|
+
|
|
173
|
+
```bash
|
|
174
|
+
python -m pip install --group test
|
|
175
|
+
pytest -q
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
Lint and type checks, enforced by CI:
|
|
179
|
+
|
|
180
|
+
```bash
|
|
181
|
+
python -m pip install --group dev
|
|
182
|
+
ruff check src tests
|
|
183
|
+
black --check src tests
|
|
184
|
+
mypy
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
The suite uses temporary directories and fake renderers, with optional integration
|
|
188
|
+
tests against the real `dot` executable. Browser-only interactions are verified
|
|
189
|
+
manually against `examples/`.
|
|
190
|
+
|
|
191
|
+
## Documentation
|
|
192
|
+
|
|
193
|
+
- [Documentation index](docs/index.md)
|
|
194
|
+
- [Installation](docs/installation.md)
|
|
195
|
+
- [Usage](docs/usage.md)
|
|
196
|
+
- [Supported formats](docs/formats.md)
|
|
197
|
+
- [Architecture](docs/architecture.md)
|
|
198
|
+
- [Security](docs/security.md)
|
|
199
|
+
- [Testing](docs/testing.md)
|
|
200
|
+
- [Limitations](docs/limitations.md)
|
|
201
|
+
- [Detailed design](docs/design.md)
|
|
202
|
+
- [Security policy](SECURITY.md)
|
|
203
|
+
- [Third-party notices](THIRD_PARTY_NOTICES.md)
|
|
204
|
+
|
|
205
|
+
## Project status
|
|
206
|
+
|
|
207
|
+
The project is feature-complete: package scaffolding, configuration and path
|
|
208
|
+
confinement, Graphviz and Markdown rendering, the HTTP interface, the two-pane
|
|
209
|
+
interface, the example tree, complete documentation, hardening and acceptance
|
|
210
|
+
verification are all in place. See the [detailed design](docs/design.md) for the
|
|
211
|
+
architecture and implementation decisions.
|
|
212
|
+
|
|
213
|
+
## Licence
|
|
214
|
+
|
|
215
|
+
MIT. See [LICENSE](LICENSE). Reuse and redistribution are permitted provided the
|
|
216
|
+
copyright notice and permission notice in that file are retained with the software.
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=77"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "markdotserver"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Lightweight, read-only HTTP viewer for Markdown and Graphviz documentation"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.12"
|
|
11
|
+
license = "MIT"
|
|
12
|
+
license-files = ["LICENSE"]
|
|
13
|
+
authors = [
|
|
14
|
+
{ name = "Alexey Agafonov", email = "128855676+lucir13@users.noreply.github.com" },
|
|
15
|
+
]
|
|
16
|
+
keywords = ["markdown", "graphviz", "documentation", "viewer", "dot", "svg"]
|
|
17
|
+
classifiers = [
|
|
18
|
+
"Programming Language :: Python :: 3.12",
|
|
19
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
20
|
+
"Topic :: Documentation",
|
|
21
|
+
"Topic :: Internet :: WWW/HTTP :: HTTP Servers",
|
|
22
|
+
"Intended Audience :: Developers",
|
|
23
|
+
]
|
|
24
|
+
# Lower bounds are the oldest releases the implementation is verified against.
|
|
25
|
+
# They are deliberately permissive so embedders can resolve markdotserver
|
|
26
|
+
# alongside their own pins, but they do exclude versions whose behaviour the
|
|
27
|
+
# code relies on changing (core-ruler ordering, Jinja2Templates.env, FileResponse
|
|
28
|
+
# header merging).
|
|
29
|
+
dependencies = [
|
|
30
|
+
"fastapi>=0.115",
|
|
31
|
+
"uvicorn>=0.30",
|
|
32
|
+
"starlette>=0.40",
|
|
33
|
+
"jinja2>=3.1",
|
|
34
|
+
"markdown-it-py>=3.0",
|
|
35
|
+
"mdit-py-plugins>=0.4",
|
|
36
|
+
"pygments>=2.21",
|
|
37
|
+
]
|
|
38
|
+
|
|
39
|
+
[project.scripts]
|
|
40
|
+
markdotserver = "markdotserver.__main__:main"
|
|
41
|
+
|
|
42
|
+
[project.urls]
|
|
43
|
+
Homepage = "https://github.com/lucir13/markdotserver"
|
|
44
|
+
Repository = "https://github.com/lucir13/markdotserver"
|
|
45
|
+
Issues = "https://github.com/lucir13/markdotserver/issues"
|
|
46
|
+
|
|
47
|
+
[dependency-groups]
|
|
48
|
+
# Starlette 1.x imports httpx2 for its TestClient and falls back to httpx, so
|
|
49
|
+
# httpx2 is the package that actually has to be present.
|
|
50
|
+
test = [
|
|
51
|
+
"pytest>=8.0",
|
|
52
|
+
"httpx2>=2.10.0",
|
|
53
|
+
]
|
|
54
|
+
dev = [
|
|
55
|
+
"ruff>=0.6",
|
|
56
|
+
"black>=24.0",
|
|
57
|
+
"mypy>=1.11",
|
|
58
|
+
"types-Pygments>=2.17",
|
|
59
|
+
]
|
|
60
|
+
|
|
61
|
+
[tool.setuptools.packages.find]
|
|
62
|
+
where = ["src"]
|
|
63
|
+
|
|
64
|
+
[tool.setuptools.package-data]
|
|
65
|
+
markdotserver = [
|
|
66
|
+
"py.typed",
|
|
67
|
+
"templates/*.html",
|
|
68
|
+
"templates/partials/*.html",
|
|
69
|
+
"static/css/*",
|
|
70
|
+
"static/js/*",
|
|
71
|
+
]
|
|
72
|
+
|
|
73
|
+
[tool.pytest.ini_options]
|
|
74
|
+
pythonpath = ["src"]
|
|
75
|
+
testpaths = ["tests"]
|
|
76
|
+
|
|
77
|
+
[tool.black]
|
|
78
|
+
target-version = ["py312"]
|
|
79
|
+
line-length = 88
|
|
80
|
+
|
|
81
|
+
[tool.darker]
|
|
82
|
+
revision = "HEAD"
|
|
83
|
+
src = ["src", "tests"]
|
|
84
|
+
isort = true # optional: run isort
|
|
85
|
+
formatter = "black" # default; could be "ruff" or "pyupgrade"
|
|
86
|
+
|
|
87
|
+
[tool.ruff]
|
|
88
|
+
target-version = "py312"
|
|
89
|
+
line-length = 88
|
|
90
|
+
src = ["src", "tests"]
|
|
91
|
+
|
|
92
|
+
[tool.ruff.lint]
|
|
93
|
+
select = [
|
|
94
|
+
"E", # pycodestyle errors
|
|
95
|
+
"W", # pycodestyle warnings
|
|
96
|
+
"F", # pyflakes
|
|
97
|
+
"I", # isort
|
|
98
|
+
"UP", # pyupgrade
|
|
99
|
+
"B", # flake8-bugbear
|
|
100
|
+
"BLE", # flake8-blind-except
|
|
101
|
+
"C4", # flake8-comprehensions
|
|
102
|
+
"SIM", # flake8-simplify
|
|
103
|
+
"RUF", # ruff-specific
|
|
104
|
+
]
|
|
105
|
+
ignore = [
|
|
106
|
+
# The tree and heading builders are naturally recursive over a bounded depth.
|
|
107
|
+
"RUF012",
|
|
108
|
+
]
|
|
109
|
+
|
|
110
|
+
[tool.ruff.lint.per-file-ignores]
|
|
111
|
+
"tests/*" = ["B011"]
|
|
112
|
+
|
|
113
|
+
[tool.mypy]
|
|
114
|
+
python_version = "3.12"
|
|
115
|
+
files = ["src/markdotserver", "tests"]
|
|
116
|
+
strict = true
|
|
117
|
+
# Modules define __all__ for their public API, but tests legitimately reach
|
|
118
|
+
# internals such as ``graphviz_renderer.subprocess`` in order to monkeypatch them.
|
|
119
|
+
implicit_reexport = true
|
|
120
|
+
# markdown-it-py and mdit-py-plugins ship no type information.
|
|
121
|
+
[[tool.mypy.overrides]]
|
|
122
|
+
module = ["markdown_it.*", "mdit_py_plugins.*"]
|
|
123
|
+
ignore_missing_imports = true
|