Skip to content

Commit

Permalink
feat: add simple web server for mermaid diagrams preview
Browse files Browse the repository at this point in the history
  • Loading branch information
unRARed committed Nov 29, 2024
1 parent 66902e8 commit 4c7b4a2
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 0 deletions.
1 change: 1 addition & 0 deletions Procfile.dev
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
# text only UI and force loading / no cache
mpf: mpf both -Xtav -c development
monitor: mpf monitor
docs: cd web && flask run
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@ Machine](http://www.ipdb.org/machine.cgi?id=1072) by Williams.

![Playfield](https://github.com/deathsave/grand-prix/raw/main/monitor/playfield.jpg)

### Docs

A simple web server is included to serve up the markdown docs and
Mermaid diagrams. To setup, run `pip install -r requirements.txt`
in the `./web/` root. Then to run it, use `bin/docs`.

```mermaid
graph TD
TODO --> DIAGRAM["Diagram Modes"]
```

Proposed OPP Build
------------------
Expand Down
26 changes: 26 additions & 0 deletions web/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import os
import markdown
import markdown_mermaidjs

from flask import Flask
from settings import MACHINE_ROOT

SIMPLE_CSS = '<link rel="stylesheet" ' \
'href="https://unpkg.com/simpledotcss/simple.min.css">' \
'<style>' \
'h1,h2,h3,h4,h5,h6 { margin: 0.5rem; }' \
'p { margin: 0.5rem; }' \
'</style>'

app = Flask(__name__)

@app.route('/')
def readme():
with open(os.path.join(MACHINE_ROOT, 'README.md')) as f:
html = markdown.markdown(
f.read(), extensions=["markdown_mermaidjs"]
)
return SIMPLE_CSS + html

if __name__ == '__main__':
app.run()
3 changes: 3 additions & 0 deletions web/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
mistune
flask
markdown-mermaidjs
4 changes: 4 additions & 0 deletions web/settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import os
# __file__ refers to the file settings.py
APP_ROOT = os.path.dirname(os.path.abspath(__file__))
MACHINE_ROOT = os.path.join(APP_ROOT, '../')

0 comments on commit 4c7b4a2

Please sign in to comment.