File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ # Mettere i Docs
2+
3+ Digitate:
4+
5+ ``` bash
6+ pip install flask markdown
7+ ```
8+
9+ Avviate il server:
10+
11+ ``` bash
12+ python pyos_docs.py
13+ ```
14+
15+ ---
16+
17+ # ` pyos_docs.py `
18+
19+ ``` python
20+ from flask import Flask, abort
21+ import markdown
22+ import os
23+
24+ app = Flask(__name__ )
25+
26+ @app.route (" /pyos-docs/<path:file>" )
27+ def docs (file ):
28+ if not os.path.exists(file ):
29+ abort(404 )
30+
31+ if not file .endswith(" .md" ):
32+ abort(403 )
33+
34+ with open (file , " r" , encoding = " utf-8" ) as f:
35+ md = f.read()
36+
37+ html = markdown.markdown(
38+ md,
39+ extensions = [" fenced_code" , " tables" ]
40+ )
41+
42+ return f """
43+ <!DOCTYPE html>
44+ <html>
45+ <head>
46+ <meta charset="utf-8">
47+ <title> { file } </title>
48+ <style>
49+ body {{
50+ max-width: 900px;
51+ margin: auto;
52+ font-family: Arial, sans-serif;
53+ padding: 20px;
54+ }}
55+ pre {{
56+ background: #f4f4f4;
57+ padding: 10px;
58+ overflow-x: auto;
59+ }}
60+ code {{
61+ background: #eee;
62+ padding: 2px 4px;
63+ }}
64+ </style>
65+ </head>
66+ <body>
67+ { html}
68+ </body>
69+ </html>
70+ """
71+
72+ app.run(host = " 0.0.0.0" , port = 8000 )
73+ ```
74+
75+ Ora potrai aprire http://localhost:8000/pyos-docs/01-start.md e http://localhost:8000/pyos-docs/02-apps.md
You can’t perform that action at this time.
0 commit comments