markbook 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.
Files changed (38) hide show
  1. markbook-0.1.0/.gitignore +90 -0
  2. markbook-0.1.0/.pre-commit-config.yaml +26 -0
  3. markbook-0.1.0/LICENCSE +21 -0
  4. markbook-0.1.0/PKG-INFO +140 -0
  5. markbook-0.1.0/README.md +128 -0
  6. markbook-0.1.0/docs/skills/SKILL.md +173 -0
  7. markbook-0.1.0/docs/skills/SYNTAX.md +185 -0
  8. markbook-0.1.0/examples/diabetes.ipynb +411 -0
  9. markbook-0.1.0/examples/diabetes.md +148 -0
  10. markbook-0.1.0/markbook/__init__.py +0 -0
  11. markbook-0.1.0/markbook/cli/__init__.py +3 -0
  12. markbook-0.1.0/markbook/cli/app.py +52 -0
  13. markbook-0.1.0/markbook/compiler.py +21 -0
  14. markbook-0.1.0/markbook/emitter/__init__.py +5 -0
  15. markbook-0.1.0/markbook/emitter/notebook.py +38 -0
  16. markbook-0.1.0/markbook/exceptions.py +4 -0
  17. markbook-0.1.0/markbook/parser/__init__.py +7 -0
  18. markbook-0.1.0/markbook/parser/nodes/__init__.py +22 -0
  19. markbook-0.1.0/markbook/parser/nodes/base.py +17 -0
  20. markbook-0.1.0/markbook/parser/nodes/chapter.py +64 -0
  21. markbook-0.1.0/markbook/parser/nodes/code.py +52 -0
  22. markbook-0.1.0/markbook/parser/nodes/divider.py +27 -0
  23. markbook-0.1.0/markbook/parser/nodes/frontmatter.py +43 -0
  24. markbook-0.1.0/markbook/parser/nodes/markdown.py +32 -0
  25. markbook-0.1.0/markbook/parser/nodes/registry.py +19 -0
  26. markbook-0.1.0/markbook/parser/nodes/toc.py +40 -0
  27. markbook-0.1.0/markbook/parser/service.py +33 -0
  28. markbook-0.1.0/markbook/parser/tokenizer.py +87 -0
  29. markbook-0.1.0/markbook/parser/views.py +24 -0
  30. markbook-0.1.0/markbook/watcher.py +36 -0
  31. markbook-0.1.0/pyproject.toml +46 -0
  32. markbook-0.1.0/test/parser/nodes/test_chapter.py +86 -0
  33. markbook-0.1.0/test/parser/nodes/test_code.py +45 -0
  34. markbook-0.1.0/test/parser/nodes/test_divider.py +27 -0
  35. markbook-0.1.0/test/parser/nodes/test_frontmatter.py +63 -0
  36. markbook-0.1.0/test/parser/nodes/test_markdown.py +43 -0
  37. markbook-0.1.0/test/parser/nodes/test_toc.py +80 -0
  38. markbook-0.1.0/uv.lock +464 -0
@@ -0,0 +1,90 @@
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+
6
+ # Virtual environments
7
+ venv/
8
+ env/
9
+ .venv/
10
+ .env/
11
+
12
+ # Distribution / packaging
13
+ build/
14
+ develop-eggs/
15
+ dist/
16
+ downloads/
17
+ eggs/
18
+ .eggs/
19
+ lib/
20
+ lib64/
21
+ parts/
22
+ sdist/
23
+ var/
24
+ *.egg-info/
25
+ .installed.cfg
26
+ *.egg
27
+
28
+ # PyInstaller
29
+ *.manifest
30
+ *.spec
31
+
32
+ # Installer logs
33
+ pip-log.txt
34
+ pip-delete-this-directory.txt
35
+
36
+ # Unit test / coverage reports
37
+ htmlcov/
38
+ .tox/
39
+ .nox/
40
+ .coverage
41
+ .coverage.*
42
+ .cache
43
+ nosetests.xml
44
+ coverage.xml
45
+ *.cover
46
+ .hypothesis/
47
+ .pytest_cache/
48
+
49
+ # Jupyter Notebook checkpoints
50
+ .ipynb_checkpoints
51
+
52
+ # pyenv
53
+ .python-version
54
+
55
+ # mypy
56
+ .mypy_cache/
57
+ .dmypy.json
58
+ dmypy.json
59
+
60
+ # Pyre
61
+ .pyre/
62
+
63
+ # Pytype
64
+ .pytype/
65
+
66
+ # Cython debug symbols
67
+ cython_debug/
68
+
69
+ # VS Code
70
+ .vscode/
71
+
72
+ # JetBrains IDEs (PyCharm, etc.)
73
+ .idea/
74
+
75
+ # MacOS
76
+ .DS_Store
77
+
78
+ # Windows
79
+ Thumbs.db
80
+ ehthumbs.db
81
+ desktop.ini
82
+
83
+ # dotenv files
84
+ .env
85
+
86
+ .ruff_cache/
87
+
88
+ site/
89
+
90
+ .claude/
@@ -0,0 +1,26 @@
1
+ repos:
2
+ - repo: https://github.com/pre-commit/pre-commit-hooks
3
+ rev: v4.6.0
4
+ hooks:
5
+ - id: trailing-whitespace
6
+ - id: end-of-file-fixer
7
+ - id: check-yaml
8
+ exclude: ^mkdocs\.yml$
9
+ - id: check-toml
10
+ - id: check-merge-conflict
11
+ - id: check-added-large-files
12
+ args: ["--maxkb=1000"]
13
+ - id: check-case-conflict
14
+
15
+ - repo: https://github.com/astral-sh/ruff-pre-commit
16
+ rev: v0.13.1
17
+ hooks:
18
+ - id: ruff
19
+ args: [--fix, --exit-non-zero-on-fix]
20
+ - id: ruff-format
21
+
22
+ - repo: https://github.com/asottile/pyupgrade
23
+ rev: v3.15.2
24
+ hooks:
25
+ - id: pyupgrade
26
+ args: [--py39-plus]
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Mathis Kristoffer Arends
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
13
+ all 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
21
+ THE SOFTWARE.
@@ -0,0 +1,140 @@
1
+ Metadata-Version: 2.4
2
+ Name: markbook
3
+ Version: 0.1.0
4
+ Summary: Write Jupyter notebooks in Markdown, render them beautifully
5
+ Requires-Python: >=3.14
6
+ Requires-Dist: nbformat>=5.10.4
7
+ Requires-Dist: pyyaml>=6.0.3
8
+ Requires-Dist: rich>=14.3.3
9
+ Requires-Dist: typer>=0.24.1
10
+ Requires-Dist: watchdog>=6.0.0
11
+ Description-Content-Type: text/markdown
12
+
13
+ # markbook
14
+
15
+ A CLI tool that compiles a custom Markdown DSL into styled Jupyter Notebooks (`.ipynb`).
16
+ Write in plain Markdown, render beautifully in Jupyter.
17
+
18
+ ## Installation
19
+
20
+ ```bash
21
+ pip install -e .
22
+ ```
23
+
24
+ ## Usage
25
+
26
+ ### Build a notebook
27
+
28
+ ```bash
29
+ markbook build notebook.md
30
+ markbook build notebook.md -o output.ipynb
31
+ ```
32
+
33
+ ### Watch for changes
34
+
35
+ ```bash
36
+ markbook watch notebook.md
37
+ ```
38
+
39
+ Recompiles automatically on every save.
40
+
41
+ ## DSL Syntax
42
+
43
+ ### Frontmatter
44
+
45
+ YAML block at the top of the file. Renders as a title heading and author name in the first cell.
46
+
47
+ ```yaml
48
+ ---
49
+ title: "My Notebook"
50
+ kernel: python3
51
+ author: "Your Name"
52
+ ---
53
+ ```
54
+
55
+ ### Headings
56
+
57
+ Use `##`, `###` and `####` to structure your notebook into chapters and sections. Each heading becomes its own styled markdown cell. Optional anchor IDs enable linking from the table of contents.
58
+
59
+ ```markdown
60
+ ## 1. Business Understanding {#chapter1}
61
+
62
+ ### 1.1 Project Context {#chap1_1}
63
+
64
+ #### 1.1.1 Goals {#chap1_1_1}
65
+ ```
66
+
67
+ | Level | Rendered Style |
68
+ |--------|----------------------------------------------------|
69
+ | `##` | Large (1.6em), accent color `#2E86AB`, 4px left border |
70
+ | `###` | Medium (1.3em), accent color `#2E86AB`, 3px left border |
71
+ | `####` | Small (1.1em), muted color `#555`, no border |
72
+
73
+ Anchor IDs (`{#id}`) are optional — if omitted, markbook auto-generates them by slugifying the heading text.
74
+
75
+ > **Note:** `#` (h1) is **not** recognized as a chapter heading. It passes through as regular markdown. Use `##` and below.
76
+
77
+ ### Table of Contents
78
+
79
+ Place `[TOC]` on its own line to auto-generate a linked table of contents from all headings in the document:
80
+
81
+ ```markdown
82
+ [TOC]
83
+ ```
84
+
85
+ This produces a cell like:
86
+
87
+ ```
88
+ ## Gliederung
89
+
90
+ * **[1. Business Understanding](#chapter1)**
91
+ * [1.1 Project Context](#chap1_1)
92
+ * [1.1.1 Goals](#chap1_1_1)
93
+ * **[2. Data Loading](#chapter2)**
94
+ * [2.1 Imports](#chap2_1)
95
+ ```
96
+
97
+ `##` headings become bold top-level entries, `###` are indented, `####` double-indented. All entries link to their heading's anchor ID.
98
+
99
+ ### Code Cells
100
+
101
+ Fenced code blocks with a recognized language tag become notebook code cells:
102
+
103
+ ````markdown
104
+ ```python
105
+ import pandas as pd
106
+ df = pd.read_csv("data.csv")
107
+ ```
108
+ ````
109
+
110
+ Supported languages: `python`, `bash`, `sql`, `r`, `julia`, `sh`, `javascript`, `typescript`, `java`, `c`, `cpp`, `go`, `rust`.
111
+
112
+ Fenced blocks with other or no language tags become markdown cells.
113
+
114
+ ### Section Dividers
115
+
116
+ A horizontal rule becomes a styled `<hr>`:
117
+
118
+ ```markdown
119
+ ---
120
+ ```
121
+
122
+ ### Regular Markdown
123
+
124
+ Everything else (paragraphs, bold, italic, lists, tables, blockquotes) passes through as-is into markdown cells.
125
+
126
+ ## Example
127
+
128
+ See [`examples/diabetes.md`](examples/diabetes.md) for a full example. Build it with:
129
+
130
+ ```bash
131
+ markbook build examples/diabetes.md
132
+ ```
133
+
134
+ ## Dependencies
135
+
136
+ - [nbformat](https://github.com/jupyter/nbformat) - Jupyter notebook format
137
+ - [PyYAML](https://pyyaml.org/) - YAML frontmatter parsing
138
+ - [Typer](https://typer.tiangolo.com/) - CLI framework
139
+ - [Rich](https://rich.readthedocs.io/) - Terminal output
140
+ - [watchdog](https://github.com/gorakhargosh/watchdog) - File watching
@@ -0,0 +1,128 @@
1
+ # markbook
2
+
3
+ A CLI tool that compiles a custom Markdown DSL into styled Jupyter Notebooks (`.ipynb`).
4
+ Write in plain Markdown, render beautifully in Jupyter.
5
+
6
+ ## Installation
7
+
8
+ ```bash
9
+ pip install -e .
10
+ ```
11
+
12
+ ## Usage
13
+
14
+ ### Build a notebook
15
+
16
+ ```bash
17
+ markbook build notebook.md
18
+ markbook build notebook.md -o output.ipynb
19
+ ```
20
+
21
+ ### Watch for changes
22
+
23
+ ```bash
24
+ markbook watch notebook.md
25
+ ```
26
+
27
+ Recompiles automatically on every save.
28
+
29
+ ## DSL Syntax
30
+
31
+ ### Frontmatter
32
+
33
+ YAML block at the top of the file. Renders as a title heading and author name in the first cell.
34
+
35
+ ```yaml
36
+ ---
37
+ title: "My Notebook"
38
+ kernel: python3
39
+ author: "Your Name"
40
+ ---
41
+ ```
42
+
43
+ ### Headings
44
+
45
+ Use `##`, `###` and `####` to structure your notebook into chapters and sections. Each heading becomes its own styled markdown cell. Optional anchor IDs enable linking from the table of contents.
46
+
47
+ ```markdown
48
+ ## 1. Business Understanding {#chapter1}
49
+
50
+ ### 1.1 Project Context {#chap1_1}
51
+
52
+ #### 1.1.1 Goals {#chap1_1_1}
53
+ ```
54
+
55
+ | Level | Rendered Style |
56
+ |--------|----------------------------------------------------|
57
+ | `##` | Large (1.6em), accent color `#2E86AB`, 4px left border |
58
+ | `###` | Medium (1.3em), accent color `#2E86AB`, 3px left border |
59
+ | `####` | Small (1.1em), muted color `#555`, no border |
60
+
61
+ Anchor IDs (`{#id}`) are optional — if omitted, markbook auto-generates them by slugifying the heading text.
62
+
63
+ > **Note:** `#` (h1) is **not** recognized as a chapter heading. It passes through as regular markdown. Use `##` and below.
64
+
65
+ ### Table of Contents
66
+
67
+ Place `[TOC]` on its own line to auto-generate a linked table of contents from all headings in the document:
68
+
69
+ ```markdown
70
+ [TOC]
71
+ ```
72
+
73
+ This produces a cell like:
74
+
75
+ ```
76
+ ## Gliederung
77
+
78
+ * **[1. Business Understanding](#chapter1)**
79
+ * [1.1 Project Context](#chap1_1)
80
+ * [1.1.1 Goals](#chap1_1_1)
81
+ * **[2. Data Loading](#chapter2)**
82
+ * [2.1 Imports](#chap2_1)
83
+ ```
84
+
85
+ `##` headings become bold top-level entries, `###` are indented, `####` double-indented. All entries link to their heading's anchor ID.
86
+
87
+ ### Code Cells
88
+
89
+ Fenced code blocks with a recognized language tag become notebook code cells:
90
+
91
+ ````markdown
92
+ ```python
93
+ import pandas as pd
94
+ df = pd.read_csv("data.csv")
95
+ ```
96
+ ````
97
+
98
+ Supported languages: `python`, `bash`, `sql`, `r`, `julia`, `sh`, `javascript`, `typescript`, `java`, `c`, `cpp`, `go`, `rust`.
99
+
100
+ Fenced blocks with other or no language tags become markdown cells.
101
+
102
+ ### Section Dividers
103
+
104
+ A horizontal rule becomes a styled `<hr>`:
105
+
106
+ ```markdown
107
+ ---
108
+ ```
109
+
110
+ ### Regular Markdown
111
+
112
+ Everything else (paragraphs, bold, italic, lists, tables, blockquotes) passes through as-is into markdown cells.
113
+
114
+ ## Example
115
+
116
+ See [`examples/diabetes.md`](examples/diabetes.md) for a full example. Build it with:
117
+
118
+ ```bash
119
+ markbook build examples/diabetes.md
120
+ ```
121
+
122
+ ## Dependencies
123
+
124
+ - [nbformat](https://github.com/jupyter/nbformat) - Jupyter notebook format
125
+ - [PyYAML](https://pyyaml.org/) - YAML frontmatter parsing
126
+ - [Typer](https://typer.tiangolo.com/) - CLI framework
127
+ - [Rich](https://rich.readthedocs.io/) - Terminal output
128
+ - [watchdog](https://github.com/gorakhargosh/watchdog) - File watching
@@ -0,0 +1,173 @@
1
+ ---
2
+ name: markbook
3
+ description: Generate well-structured Jupyter Notebooks by writing Markdown DSL files and compiling them with the markbook CLI
4
+ version: 0.1.0
5
+ ---
6
+
7
+ # markbook — Generate Jupyter Notebooks from Markdown
8
+
9
+ You are using **markbook**, a CLI that compiles a Markdown DSL into styled Jupyter Notebooks (`.ipynb`). Your workflow is: write a `.md` file using markbook's DSL syntax, then compile it.
10
+
11
+ ## Workflow
12
+
13
+ ### 1. Write the `.md` file
14
+
15
+ Create a Markdown file using markbook's DSL. See [SYNTAX.md](SYNTAX.md) for the complete reference.
16
+
17
+ ### 2. Compile to notebook
18
+
19
+ ```bash
20
+ markbook build <file>.md # outputs <file>.ipynb
21
+ markbook build <file>.md -o output.ipynb # custom output path
22
+ ```
23
+
24
+ That's it. There are only two commands: `build` and `watch` (auto-rebuild on save).
25
+
26
+ ## How to Structure a Good Notebook
27
+
28
+ When generating a `.md` file for markbook, follow this structure:
29
+
30
+ ### Start with frontmatter
31
+
32
+ Always begin the file with YAML frontmatter:
33
+
34
+ ```yaml
35
+ ---
36
+ title: "Descriptive Title"
37
+ kernel: python3
38
+ author: "Author Name"
39
+ ---
40
+ ```
41
+
42
+ ### Add a table of contents
43
+
44
+ Place `[TOC]` right after frontmatter for navigable notebooks. It auto-generates from all headings.
45
+
46
+ ### Use `---` dividers between major sections
47
+
48
+ Dividers create visual separation. Place them between top-level chapters.
49
+
50
+ ### Structure with `##`, `###`, `####` headings
51
+
52
+ Use heading levels consistently:
53
+
54
+ - `##` — top-level chapters (e.g., `## 1. Data Loading`)
55
+ - `###` — sub-sections (e.g., `### 1.1 Import Libraries`)
56
+ - `####` — minor sections when needed
57
+
58
+ Always add anchor IDs to headings for TOC links: `## Title {#anchor_id}`
59
+
60
+ ### Alternate prose and code
61
+
62
+ Good notebooks explain what the code does **before** the code cell. Write a markdown paragraph or bullet list, then the code block:
63
+
64
+ ```markdown
65
+ ### 2.1 Load the Dataset {#load_data}
66
+
67
+ We load the CSV and inspect the first rows.
68
+
69
+ \`\`\`python
70
+ import pandas as pd
71
+ df = pd.read_csv("data.csv")
72
+ df.head()
73
+ \`\`\`
74
+ ```
75
+
76
+ ### Use recognized languages for code cells
77
+
78
+ Only these language tags produce code cells:
79
+ `python`, `bash`, `sql`, `r`, `julia`, `sh`, `javascript`, `typescript`, `java`, `c`, `cpp`, `go`, `rust`
80
+
81
+ Any other tag (or no tag) creates a markdown cell — useful for showing example output or pseudocode.
82
+
83
+ ## Full Template
84
+
85
+ Here is a template for a data science notebook:
86
+
87
+ ```markdown
88
+ ---
89
+ title: "Project Title"
90
+ kernel: python3
91
+ author: "Your Name"
92
+ ---
93
+
94
+ [TOC]
95
+
96
+ ---
97
+
98
+ ## 1. Introduction {#intro}
99
+
100
+ Brief description of the project goal.
101
+
102
+ - Objective 1
103
+ - Objective 2
104
+
105
+ ---
106
+
107
+ ## 2. Data Loading {#data}
108
+
109
+ ### 2.1 Imports {#imports}
110
+
111
+ \`\`\`python
112
+ import pandas as pd
113
+ import numpy as np
114
+ import matplotlib.pyplot as plt
115
+ \`\`\`
116
+
117
+ ### 2.2 Read Data {#read_data}
118
+
119
+ \`\`\`python
120
+ df = pd.read_csv("data.csv")
121
+ print(f"Shape: {df.shape}")
122
+ df.head()
123
+ \`\`\`
124
+
125
+ ---
126
+
127
+ ## 3. Exploratory Analysis {#eda}
128
+
129
+ ### 3.1 Overview {#overview}
130
+
131
+ \`\`\`python
132
+ df.describe()
133
+ \`\`\`
134
+
135
+ ### 3.2 Visualizations {#viz}
136
+
137
+ \`\`\`python
138
+ fig, ax = plt.subplots(figsize=(8, 5))
139
+
140
+ # plotting code
141
+
142
+ plt.show()
143
+ \`\`\`
144
+
145
+ ---
146
+
147
+ ## 4. Modeling {#modeling}
148
+
149
+ ### 4.1 Train/Test Split {#split}
150
+
151
+ \`\`\`python
152
+ from sklearn.model_selection import train_test_split
153
+ X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
154
+ \`\`\`
155
+
156
+ ---
157
+
158
+ ## 5. Evaluation {#eval}
159
+
160
+ \`\`\`python
161
+ from sklearn.metrics import classification_report
162
+ print(classification_report(y_test, y_pred))
163
+ \`\`\`
164
+ ```
165
+
166
+ ## Common Mistakes to Avoid
167
+
168
+ - **Missing frontmatter** — always start with `---` on line 1. Without it, no title/kernel metadata.
169
+ - **Using `#` (h1)** — single `#` is NOT recognized as a chapter. Use `##` and below.
170
+ - **Forgetting anchor IDs** — without `{#id}`, TOC links still work (auto-slugified), but explicit anchors are cleaner.
171
+ - **Unclosed code fences** — every ` ``` ` must have a matching closing ` ``` `. Unclosed blocks cause a build error.
172
+ - **Wrong language tag** — `\`\`\`py`does not work, use`\`\`\`python`. Tags are matched exactly against the supported list.
173
+ - **`---` on line 0** — the first `---` in the file always opens frontmatter, not a divider. Dividers only work after frontmatter.