mockitdown 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 (89) hide show
  1. mockitdown-0.1.0/LICENSE +21 -0
  2. mockitdown-0.1.0/PKG-INFO +126 -0
  3. mockitdown-0.1.0/README.md +92 -0
  4. mockitdown-0.1.0/pyproject.toml +51 -0
  5. mockitdown-0.1.0/setup.cfg +4 -0
  6. mockitdown-0.1.0/src/mockitdown/__init__.py +32 -0
  7. mockitdown-0.1.0/src/mockitdown/api.py +96 -0
  8. mockitdown-0.1.0/src/mockitdown/assets.py +84 -0
  9. mockitdown-0.1.0/src/mockitdown/cli.py +194 -0
  10. mockitdown-0.1.0/src/mockitdown/diagnostics.py +95 -0
  11. mockitdown-0.1.0/src/mockitdown/evaluate.py +687 -0
  12. mockitdown-0.1.0/src/mockitdown/extension.py +147 -0
  13. mockitdown-0.1.0/src/mockitdown/fence.py +69 -0
  14. mockitdown-0.1.0/src/mockitdown/icons.py +358 -0
  15. mockitdown-0.1.0/src/mockitdown/model.py +129 -0
  16. mockitdown-0.1.0/src/mockitdown/options.py +93 -0
  17. mockitdown-0.1.0/src/mockitdown/packs/__init__.py +214 -0
  18. mockitdown-0.1.0/src/mockitdown/packs/android/pack.css +691 -0
  19. mockitdown-0.1.0/src/mockitdown/packs/android/pack.json +310 -0
  20. mockitdown-0.1.0/src/mockitdown/packs/angular-material/pack.css +725 -0
  21. mockitdown-0.1.0/src/mockitdown/packs/angular-material/pack.json +237 -0
  22. mockitdown-0.1.0/src/mockitdown/packs/base/pack.css +963 -0
  23. mockitdown-0.1.0/src/mockitdown/packs/base/pack.json +1037 -0
  24. mockitdown-0.1.0/src/mockitdown/packs/bootstrap/pack.css +969 -0
  25. mockitdown-0.1.0/src/mockitdown/packs/bootstrap/pack.json +320 -0
  26. mockitdown-0.1.0/src/mockitdown/packs/cde/pack.css +234 -0
  27. mockitdown-0.1.0/src/mockitdown/packs/cde/pack.json +716 -0
  28. mockitdown-0.1.0/src/mockitdown/packs/fluent/pack.css +710 -0
  29. mockitdown-0.1.0/src/mockitdown/packs/fluent/pack.json +288 -0
  30. mockitdown-0.1.0/src/mockitdown/packs/gsos/pack.css +490 -0
  31. mockitdown-0.1.0/src/mockitdown/packs/gsos/pack.json +567 -0
  32. mockitdown-0.1.0/src/mockitdown/packs/gtk/pack.css +583 -0
  33. mockitdown-0.1.0/src/mockitdown/packs/gtk/pack.json +357 -0
  34. mockitdown-0.1.0/src/mockitdown/packs/hologram/pack.css +494 -0
  35. mockitdown-0.1.0/src/mockitdown/packs/hologram/pack.json +436 -0
  36. mockitdown-0.1.0/src/mockitdown/packs/kde-plasma/pack.css +508 -0
  37. mockitdown-0.1.0/src/mockitdown/packs/kde-plasma/pack.json +347 -0
  38. mockitdown-0.1.0/src/mockitdown/packs/lcars/pack.css +627 -0
  39. mockitdown-0.1.0/src/mockitdown/packs/lcars/pack.json +236 -0
  40. mockitdown-0.1.0/src/mockitdown/packs/lisa/pack.css +1030 -0
  41. mockitdown-0.1.0/src/mockitdown/packs/lisa/pack.json +615 -0
  42. mockitdown-0.1.0/src/mockitdown/packs/mac-classic/pack.css +930 -0
  43. mockitdown-0.1.0/src/mockitdown/packs/mac-classic/pack.json +697 -0
  44. mockitdown-0.1.0/src/mockitdown/packs/macos9/pack.css +738 -0
  45. mockitdown-0.1.0/src/mockitdown/packs/macos9/pack.json +783 -0
  46. mockitdown-0.1.0/src/mockitdown/packs/mui/pack.css +866 -0
  47. mockitdown-0.1.0/src/mockitdown/packs/mui/pack.json +292 -0
  48. mockitdown-0.1.0/src/mockitdown/packs/phosphor/pack.css +413 -0
  49. mockitdown-0.1.0/src/mockitdown/packs/phosphor/pack.json +468 -0
  50. mockitdown-0.1.0/src/mockitdown/packs/qt/pack.css +604 -0
  51. mockitdown-0.1.0/src/mockitdown/packs/qt/pack.json +341 -0
  52. mockitdown-0.1.0/src/mockitdown/packs/sapui5/pack.css +819 -0
  53. mockitdown-0.1.0/src/mockitdown/packs/sapui5/pack.json +1395 -0
  54. mockitdown-0.1.0/src/mockitdown/packs/shadcn/pack.css +707 -0
  55. mockitdown-0.1.0/src/mockitdown/packs/shadcn/pack.json +325 -0
  56. mockitdown-0.1.0/src/mockitdown/packs/swiftui/pack.css +1441 -0
  57. mockitdown-0.1.0/src/mockitdown/packs/swiftui/pack.json +277 -0
  58. mockitdown-0.1.0/src/mockitdown/packs/vista/pack.css +899 -0
  59. mockitdown-0.1.0/src/mockitdown/packs/vista/pack.json +938 -0
  60. mockitdown-0.1.0/src/mockitdown/packs/win2/pack.css +187 -0
  61. mockitdown-0.1.0/src/mockitdown/packs/win2/pack.json +235 -0
  62. mockitdown-0.1.0/src/mockitdown/packs/win31/pack.css +706 -0
  63. mockitdown-0.1.0/src/mockitdown/packs/win31/pack.json +1164 -0
  64. mockitdown-0.1.0/src/mockitdown/packs/winxp/pack.css +894 -0
  65. mockitdown-0.1.0/src/mockitdown/packs/winxp/pack.json +886 -0
  66. mockitdown-0.1.0/src/mockitdown/packs/xerox-star/pack.css +137 -0
  67. mockitdown-0.1.0/src/mockitdown/packs/xerox-star/pack.json +209 -0
  68. mockitdown-0.1.0/src/mockitdown/page.css +138 -0
  69. mockitdown-0.1.0/src/mockitdown/render/__init__.py +108 -0
  70. mockitdown-0.1.0/src/mockitdown/render/charts.py +507 -0
  71. mockitdown-0.1.0/src/mockitdown/render/chrome.py +80 -0
  72. mockitdown-0.1.0/src/mockitdown/render/html.py +2370 -0
  73. mockitdown-0.1.0/src/mockitdown/render/style.py +439 -0
  74. mockitdown-0.1.0/src/mockitdown/styles.py +98 -0
  75. mockitdown-0.1.0/src/mockitdown/syntax/__init__.py +7 -0
  76. mockitdown-0.1.0/src/mockitdown/syntax/ast.py +217 -0
  77. mockitdown-0.1.0/src/mockitdown/syntax/lexer.py +245 -0
  78. mockitdown-0.1.0/src/mockitdown/syntax/parser.py +573 -0
  79. mockitdown-0.1.0/src/mockitdown/vocabulary.py +53 -0
  80. mockitdown-0.1.0/src/mockitdown.egg-info/PKG-INFO +126 -0
  81. mockitdown-0.1.0/src/mockitdown.egg-info/SOURCES.txt +87 -0
  82. mockitdown-0.1.0/src/mockitdown.egg-info/dependency_links.txt +1 -0
  83. mockitdown-0.1.0/src/mockitdown.egg-info/entry_points.txt +2 -0
  84. mockitdown-0.1.0/src/mockitdown.egg-info/requires.txt +4 -0
  85. mockitdown-0.1.0/src/mockitdown.egg-info/top_level.txt +1 -0
  86. mockitdown-0.1.0/tests/test_examples.py +111 -0
  87. mockitdown-0.1.0/tests/test_packs.py +134 -0
  88. mockitdown-0.1.0/tests/test_render.py +117 -0
  89. mockitdown-0.1.0/tests/test_syntax.py +64 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Brian Bogovich
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,126 @@
1
+ Metadata-Version: 2.4
2
+ Name: mockitdown
3
+ Version: 0.1.0
4
+ Summary: UI mockups written in SwiftUI syntax inside Markdown, rendered as HTML styled after real UI frameworks.
5
+ Author: Brian Bogovich
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/bbogovich/mockitdown
8
+ Project-URL: Documentation, https://bbogovich.github.io/mockitdown/
9
+ Project-URL: Demos, https://bbogovich.github.io/mockitdown/demos/
10
+ Project-URL: Source, https://github.com/bbogovich/mockitdown
11
+ Project-URL: Issues, https://github.com/bbogovich/mockitdown/issues
12
+ Keywords: mockup,wireframe,markdown,mkdocs,zensical,swiftui,fluent,material,sapui5
13
+ Classifier: Development Status :: 4 - Beta
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: Framework :: MkDocs
16
+ Classifier: Operating System :: OS Independent
17
+ Classifier: Programming Language :: Python :: 3
18
+ Classifier: Programming Language :: Python :: 3 :: Only
19
+ Classifier: Programming Language :: Python :: 3.11
20
+ Classifier: Programming Language :: Python :: 3.12
21
+ Classifier: Programming Language :: Python :: 3.13
22
+ Classifier: Programming Language :: Python :: 3.14
23
+ Classifier: Topic :: Documentation
24
+ Classifier: Topic :: Software Development :: Documentation
25
+ Classifier: Topic :: Software Development :: User Interfaces
26
+ Classifier: Topic :: Text Processing :: Markup :: Markdown
27
+ Requires-Python: >=3.11
28
+ Description-Content-Type: text/markdown
29
+ License-File: LICENSE
30
+ Provides-Extra: markdown
31
+ Requires-Dist: Markdown<4,>=3.6; extra == "markdown"
32
+ Requires-Dist: pymdown-extensions<14,>=10; extra == "markdown"
33
+ Dynamic: license-file
34
+
35
+ # mockitdown
36
+
37
+ UI mockups written in **SwiftUI syntax** inside Markdown, rendered at build time as HTML and CSS that
38
+ look like a real UI framework, in light and dark: **SwiftUI** (iOS, iPadOS, macOS), **Fluent (WinUI 3)**,
39
+ **Material UI**, **Angular Material**, **SAPUI5 (Fiori Horizon)**, **Bootstrap**, **shadcn/ui**,
40
+ **Android (Material 3)**, **GTK 4 / libadwaita**, **Qt 6** and **KDE Plasma** — plus retro systems
41
+ from the Xerox Star to Windows Vista. Charts, spreadsheets, boards, numbered callouts, pointers and
42
+ drag-select overlays are built in.
43
+
44
+ **[Demos](https://bbogovich.github.io/mockitdown/demos/)** ·
45
+ **[Documentation](https://bbogovich.github.io/mockitdown/)** ·
46
+ **[Source](https://github.com/bbogovich/mockitdown)**
47
+
48
+ ````markdown
49
+ ```mockitdown device="phone" appearance="both"
50
+ import SwiftUI
51
+
52
+ NavigationStack {
53
+ List {
54
+ Row("Wi-Fi", detail: "Home", systemImage: "wifi", chevron: true)
55
+ Toggle("Airplane Mode", isOn: false)
56
+ }
57
+ .navigationTitle("Settings")
58
+ }
59
+ ```
60
+ ````
61
+
62
+ - **One notation, many frameworks.** `import SwiftUI`, `import FluentUI`, `import MUI`, … selects a
63
+ *design pack*; each pack adds the framework's own component names and styles.
64
+ - **Custom components.** Declare `struct MyRow: View { … }` in a block or in a `.mockitdown`
65
+ library and `import "shared/rows"` it anywhere in the site.
66
+ - **Self-contained output.** No JavaScript, no CDN, no web fonts; local images are embedded.
67
+ - **MkDocs and Zensical.** A Python-Markdown extension plus a superfences fence; no MkDocs plugin.
68
+
69
+ ## Install and configure
70
+
71
+ ```bash
72
+ pip install "mockitdown[markdown]"
73
+ # not yet on PyPI? install from GitHub:
74
+ pip install "mockitdown[markdown] @ git+https://github.com/bbogovich/mockitdown@main"
75
+ ```
76
+
77
+ Python 3.11 or later. The core has no dependencies; the `markdown` extra adds Python-Markdown and
78
+ pymdown-extensions for the MkDocs / Zensical integration.
79
+
80
+ `mkdocs.yml` (read by both MkDocs and Zensical; any theme, Material recommended):
81
+
82
+ ```yaml
83
+ markdown_extensions:
84
+ - mockitdown:
85
+ default_pack: swiftui # pack for blocks that name none
86
+ default_appearance: auto # light | dark | auto (follow the page) | both
87
+ import_paths: [docs/mockups] # where import "…" looks
88
+ asset_paths: [docs] # where Image("…") looks
89
+ strict: true # fail the build on mockup errors
90
+ - pymdownx.superfences:
91
+ custom_fences:
92
+ - name: mockitdown
93
+ class: mockitdown
94
+ format: !!python/name:mockitdown.fence.format
95
+ validator: !!python/name:mockitdown.fence.validate
96
+ ```
97
+
98
+ ## Command line
99
+
100
+ ```bash
101
+ mockitdown render screen.mockitdown --standalone -o screen.html # a full page with CSS
102
+ mockitdown check docs/mockups/*.mockitdown # diagnostics, exit 1 on errors
103
+ mockitdown css --pack fluent -o docs/assets/mockitdown.css # for `css: none` sites
104
+ mockitdown packs # installed packs
105
+ mockitdown elements mui --markdown # a pack's element catalogue
106
+ ```
107
+
108
+ ## Repository
109
+
110
+ | Path | Holds |
111
+ |---|---|
112
+ | `src/mockitdown/` | the library: `syntax/` (lexer, parser), `evaluate.py`, `render/`, `packs/<id>/`, `styles.py`, `extension.py`, `fence.py`, `cli.py` |
113
+ | `examples/site/` | the example site (Zensical): one page per pack; also the end-to-end test fixture |
114
+ | `tests/` | unit tests and the example-site test |
115
+ | `tools/snapshot.py` | render a mockup and screenshot it with headless Chrome |
116
+
117
+ The definition, specification and implementation documentation are on the `docs` branch (worktree
118
+ `../mockitdown.docs`), published to GitHub Pages.
119
+
120
+ ```bash
121
+ python3.14 -m venv .venv && .venv/bin/pip install -e ".[markdown]" zensical
122
+ .venv/bin/python -m unittest discover -s tests -t .
123
+ cd examples/site && ../../.venv/bin/zensical serve
124
+ ```
125
+
126
+ Licence: MIT.
@@ -0,0 +1,92 @@
1
+ # mockitdown
2
+
3
+ UI mockups written in **SwiftUI syntax** inside Markdown, rendered at build time as HTML and CSS that
4
+ look like a real UI framework, in light and dark: **SwiftUI** (iOS, iPadOS, macOS), **Fluent (WinUI 3)**,
5
+ **Material UI**, **Angular Material**, **SAPUI5 (Fiori Horizon)**, **Bootstrap**, **shadcn/ui**,
6
+ **Android (Material 3)**, **GTK 4 / libadwaita**, **Qt 6** and **KDE Plasma** — plus retro systems
7
+ from the Xerox Star to Windows Vista. Charts, spreadsheets, boards, numbered callouts, pointers and
8
+ drag-select overlays are built in.
9
+
10
+ **[Demos](https://bbogovich.github.io/mockitdown/demos/)** ·
11
+ **[Documentation](https://bbogovich.github.io/mockitdown/)** ·
12
+ **[Source](https://github.com/bbogovich/mockitdown)**
13
+
14
+ ````markdown
15
+ ```mockitdown device="phone" appearance="both"
16
+ import SwiftUI
17
+
18
+ NavigationStack {
19
+ List {
20
+ Row("Wi-Fi", detail: "Home", systemImage: "wifi", chevron: true)
21
+ Toggle("Airplane Mode", isOn: false)
22
+ }
23
+ .navigationTitle("Settings")
24
+ }
25
+ ```
26
+ ````
27
+
28
+ - **One notation, many frameworks.** `import SwiftUI`, `import FluentUI`, `import MUI`, … selects a
29
+ *design pack*; each pack adds the framework's own component names and styles.
30
+ - **Custom components.** Declare `struct MyRow: View { … }` in a block or in a `.mockitdown`
31
+ library and `import "shared/rows"` it anywhere in the site.
32
+ - **Self-contained output.** No JavaScript, no CDN, no web fonts; local images are embedded.
33
+ - **MkDocs and Zensical.** A Python-Markdown extension plus a superfences fence; no MkDocs plugin.
34
+
35
+ ## Install and configure
36
+
37
+ ```bash
38
+ pip install "mockitdown[markdown]"
39
+ # not yet on PyPI? install from GitHub:
40
+ pip install "mockitdown[markdown] @ git+https://github.com/bbogovich/mockitdown@main"
41
+ ```
42
+
43
+ Python 3.11 or later. The core has no dependencies; the `markdown` extra adds Python-Markdown and
44
+ pymdown-extensions for the MkDocs / Zensical integration.
45
+
46
+ `mkdocs.yml` (read by both MkDocs and Zensical; any theme, Material recommended):
47
+
48
+ ```yaml
49
+ markdown_extensions:
50
+ - mockitdown:
51
+ default_pack: swiftui # pack for blocks that name none
52
+ default_appearance: auto # light | dark | auto (follow the page) | both
53
+ import_paths: [docs/mockups] # where import "…" looks
54
+ asset_paths: [docs] # where Image("…") looks
55
+ strict: true # fail the build on mockup errors
56
+ - pymdownx.superfences:
57
+ custom_fences:
58
+ - name: mockitdown
59
+ class: mockitdown
60
+ format: !!python/name:mockitdown.fence.format
61
+ validator: !!python/name:mockitdown.fence.validate
62
+ ```
63
+
64
+ ## Command line
65
+
66
+ ```bash
67
+ mockitdown render screen.mockitdown --standalone -o screen.html # a full page with CSS
68
+ mockitdown check docs/mockups/*.mockitdown # diagnostics, exit 1 on errors
69
+ mockitdown css --pack fluent -o docs/assets/mockitdown.css # for `css: none` sites
70
+ mockitdown packs # installed packs
71
+ mockitdown elements mui --markdown # a pack's element catalogue
72
+ ```
73
+
74
+ ## Repository
75
+
76
+ | Path | Holds |
77
+ |---|---|
78
+ | `src/mockitdown/` | the library: `syntax/` (lexer, parser), `evaluate.py`, `render/`, `packs/<id>/`, `styles.py`, `extension.py`, `fence.py`, `cli.py` |
79
+ | `examples/site/` | the example site (Zensical): one page per pack; also the end-to-end test fixture |
80
+ | `tests/` | unit tests and the example-site test |
81
+ | `tools/snapshot.py` | render a mockup and screenshot it with headless Chrome |
82
+
83
+ The definition, specification and implementation documentation are on the `docs` branch (worktree
84
+ `../mockitdown.docs`), published to GitHub Pages.
85
+
86
+ ```bash
87
+ python3.14 -m venv .venv && .venv/bin/pip install -e ".[markdown]" zensical
88
+ .venv/bin/python -m unittest discover -s tests -t .
89
+ cd examples/site && ../../.venv/bin/zensical serve
90
+ ```
91
+
92
+ Licence: MIT.
@@ -0,0 +1,51 @@
1
+ [build-system]
2
+ requires = ["setuptools>=68"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "mockitdown"
7
+ version = "0.1.0"
8
+ description = "UI mockups written in SwiftUI syntax inside Markdown, rendered as HTML styled after real UI frameworks."
9
+ readme = "README.md"
10
+ requires-python = ">=3.11"
11
+ license = "MIT"
12
+ authors = [{ name = "Brian Bogovich" }]
13
+ keywords = ["mockup", "wireframe", "markdown", "mkdocs", "zensical", "swiftui", "fluent", "material", "sapui5"]
14
+ classifiers = [
15
+ "Development Status :: 4 - Beta",
16
+ "Intended Audience :: Developers",
17
+ "Framework :: MkDocs",
18
+ "Operating System :: OS Independent",
19
+ "Programming Language :: Python :: 3",
20
+ "Programming Language :: Python :: 3 :: Only",
21
+ "Programming Language :: Python :: 3.11",
22
+ "Programming Language :: Python :: 3.12",
23
+ "Programming Language :: Python :: 3.13",
24
+ "Programming Language :: Python :: 3.14",
25
+ "Topic :: Documentation",
26
+ "Topic :: Software Development :: Documentation",
27
+ "Topic :: Software Development :: User Interfaces",
28
+ "Topic :: Text Processing :: Markup :: Markdown",
29
+ ]
30
+ # The core (parser, renderer, CLI) has no runtime dependencies. The Markdown extension needs
31
+ # Python-Markdown, and the fence needs pymdown-extensions' superfences: the `markdown` extra.
32
+ dependencies = []
33
+
34
+ [project.urls]
35
+ Homepage = "https://github.com/bbogovich/mockitdown"
36
+ Documentation = "https://bbogovich.github.io/mockitdown/"
37
+ Demos = "https://bbogovich.github.io/mockitdown/demos/"
38
+ Source = "https://github.com/bbogovich/mockitdown"
39
+ Issues = "https://github.com/bbogovich/mockitdown/issues"
40
+
41
+ [project.optional-dependencies]
42
+ markdown = ["Markdown>=3.6,<4", "pymdown-extensions>=10,<14"]
43
+
44
+ [project.scripts]
45
+ mockitdown = "mockitdown.cli:main"
46
+
47
+ [tool.setuptools.packages.find]
48
+ where = ["src"]
49
+
50
+ [tool.setuptools.package-data]
51
+ mockitdown = ["page.css", "packs/*/pack.json", "packs/*/pack.css"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,32 @@
1
+ """mockitdown — UI mockups written in SwiftUI syntax inside Markdown, rendered as HTML styled
2
+ after a real UI framework (SwiftUI, Fluent, Material UI, Angular Material, SAPUI5, Bootstrap, …).
3
+
4
+ Library use::
5
+
6
+ from mockitdown import render, stylesheet
7
+ result = render('import SwiftUI\\nText("Hello")', device="phone")
8
+ page = f"<style>{stylesheet(result.packs)}</style>{result.html}"
9
+
10
+ In a MkDocs or Zensical site, add the ``mockitdown`` Markdown extension and the superfences fence
11
+ (``mockitdown.fence.format`` / ``mockitdown.fence.validate``); see the documentation.
12
+ """
13
+
14
+ from __future__ import annotations
15
+
16
+ from .api import RenderResult, check, evaluate, render, stylesheet
17
+ from .diagnostics import Diagnostic, MockitdownError, MockitdownSyntaxError, Severity
18
+ from .options import RenderOptions
19
+
20
+ __version__ = "0.1.0"
21
+
22
+ __all__ = [
23
+ "render", "check", "evaluate", "stylesheet", "RenderOptions", "RenderResult", "Diagnostic", "Severity",
24
+ "MockitdownError", "MockitdownSyntaxError", "makeExtension", "__version__",
25
+ ]
26
+
27
+
28
+ def makeExtension(**kwargs): # noqa: N802 - Python-Markdown's required name
29
+ """Python-Markdown entry point, so ``markdown_extensions: [mockitdown]`` works."""
30
+ from .extension import MockitdownExtension
31
+
32
+ return MockitdownExtension(**kwargs)
@@ -0,0 +1,96 @@
1
+ """Public entry points: render, check, stylesheet."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from dataclasses import dataclass, field
6
+ from pathlib import Path
7
+
8
+ from .assets import AssetResolver
9
+ from .diagnostics import Diagnostic, Diagnostics, MockitdownSyntaxError, Severity
10
+ from .evaluate import Evaluator, ImportContext
11
+ from .model import Screen
12
+ from .options import RenderOptions
13
+ from .packs import registry as _registry
14
+ from .render import Renderer, render_screen
15
+ from .render.html import esc
16
+ from .styles import stylesheet as _stylesheet
17
+ from .syntax import parse
18
+
19
+
20
+ @dataclass
21
+ class RenderResult:
22
+ html: str
23
+ diagnostics: list[Diagnostic] = field(default_factory=list)
24
+ #: Ids of the packs the output needs CSS for (empty when nothing rendered).
25
+ packs: list[str] = field(default_factory=list)
26
+ screen: Screen | None = None
27
+
28
+ @property
29
+ def errors(self) -> list[Diagnostic]:
30
+ return [d for d in self.diagnostics if d.severity is Severity.ERROR]
31
+
32
+ @property
33
+ def ok(self) -> bool:
34
+ return not self.errors
35
+
36
+
37
+ def _search_paths(paths: tuple[Path, ...]) -> list[Path]:
38
+ return [Path(p) for p in paths]
39
+
40
+
41
+ def evaluate(source: str, options: RenderOptions | None = None,
42
+ diagnostics: Diagnostics | None = None) -> tuple[Screen | None, Diagnostics]:
43
+ """Parse and evaluate ``source``. Returns ``(None, diags)`` on a syntax error."""
44
+ opts = options or RenderOptions()
45
+ diags = diagnostics or Diagnostics()
46
+ src_name = str(opts.source_path) if opts.source_path else ""
47
+ try:
48
+ module = parse(source, source=src_name)
49
+ except MockitdownSyntaxError as e:
50
+ diags.extend([e.diagnostic])
51
+ return None, diags
52
+ reg = _registry(tuple(str(p) for p in opts.pack_paths))
53
+ base_dir = opts.source_path.parent if opts.source_path else None
54
+ ev = Evaluator(reg, diags, default_pack=opts.default_pack, pack_override=opts.pack,
55
+ imports=ImportContext(_search_paths(opts.import_paths), base_dir))
56
+ return ev.evaluate(module), diags
57
+
58
+
59
+ def render(source: str, options: RenderOptions | None = None, **overrides: object) -> RenderResult:
60
+ """Render one mockup to an HTML fragment (no CSS; see :func:`stylesheet`)."""
61
+ opts = (options or RenderOptions()).with_overrides(**overrides)
62
+ screen, diags = evaluate(source, opts)
63
+ if screen is None:
64
+ return RenderResult(error_html(diags.items), diags.items)
65
+ base_dir = opts.source_path.parent if opts.source_path else None
66
+ assets = AssetResolver(_search_paths(opts.asset_paths), base_dir, diags, embed=opts.embed_assets,
67
+ max_bytes=opts.max_embed_bytes)
68
+ renderer = Renderer(screen.pack, diags, assets)
69
+ body = render_screen(screen, renderer, opts, diags)
70
+ errors = diags.errors
71
+ shown = errors + (diags.warnings if opts.show_warnings else [])
72
+ prefix = error_html(shown) if shown else ""
73
+ packs = [p.id for p in screen.pack.lineage()]
74
+ if opts.source:
75
+ body += (f'<details class="mkd-source"><summary>Source</summary><pre><code class="language-swift">'
76
+ f"{esc(source.strip())}</code></pre></details>")
77
+ return RenderResult(prefix + body, diags.items, packs, screen)
78
+
79
+
80
+ def check(source: str, options: RenderOptions | None = None, **overrides: object) -> list[Diagnostic]:
81
+ """All diagnostics for ``source`` (rendering included, so asset and icon problems are found)."""
82
+ return render(source, options, **overrides).diagnostics
83
+
84
+
85
+ def stylesheet(packs: list[str] | None = None, *, pack_paths: tuple[Path, ...] = (), minify: bool = True) -> str:
86
+ """CSS for the given pack ids (all known packs when None)."""
87
+ reg = _registry(tuple(str(p) for p in pack_paths))
88
+ return _stylesheet(packs if packs is not None else reg.ids(), reg, minify=minify)
89
+
90
+
91
+ def error_html(items: list[Diagnostic]) -> str:
92
+ errors = [d for d in items if d.severity is Severity.ERROR]
93
+ title = "mockitdown: " + (f"{len(errors)} error{'s' if len(errors) != 1 else ''}" if errors else "warnings")
94
+ lis = "".join(f"<li>{esc(str(d))}</li>" for d in items)
95
+ return (f'<div class="mkd-error" role="alert"><div class="mkd-error__title">{esc(title)}</div>'
96
+ f"<ul>{lis}</ul></div>")
@@ -0,0 +1,84 @@
1
+ """External assets (images) referenced from a mockup.
2
+
3
+ ``Image("assets/team.jpg")`` is resolved at build time:
4
+
5
+ * ``http(s)://``, protocol-relative ``//`` and ``data:image/…`` references pass through unchanged;
6
+ * a local path is looked up relative to the block's own file (when known), then each asset path;
7
+ * with ``embed`` on (the default) a found file is inlined as a ``data:`` URI, so the rendered page is
8
+ self-contained and the reference works at any page URL; files over ``max_bytes`` are linked instead;
9
+ * with ``embed`` off the reference is emitted as written, for the browser to resolve.
10
+
11
+ A local path is only read when it resolves inside one of the search roots.
12
+ """
13
+
14
+ from __future__ import annotations
15
+
16
+ import base64
17
+ import mimetypes
18
+ import re
19
+ from pathlib import Path
20
+
21
+ from .diagnostics import Diagnostics, Location
22
+
23
+ _MIME = {
24
+ ".png": "image/png", ".jpg": "image/jpeg", ".jpeg": "image/jpeg", ".gif": "image/gif",
25
+ ".webp": "image/webp", ".svg": "image/svg+xml", ".avif": "image/avif", ".ico": "image/x-icon",
26
+ ".bmp": "image/bmp",
27
+ }
28
+ _REMOTE = re.compile(r"^(https?:)?//", re.I)
29
+ _DATA = re.compile(r"^data:image/[a-z0-9.+-]+(;[a-z0-9=.+-]+)*,", re.I)
30
+
31
+
32
+ class AssetResolver:
33
+ def __init__(self, search_paths: list[Path], base_dir: Path | None, diags: Diagnostics, *, embed: bool = True,
34
+ max_bytes: int = 2_000_000) -> None:
35
+ self.roots = [p.resolve() for p in ([base_dir] if base_dir else []) + list(search_paths)]
36
+ self.embed = embed
37
+ self.max_bytes = max_bytes
38
+ self.diags = diags
39
+ self._cache: dict[Path, str] = {}
40
+
41
+ def _find(self, ref: str) -> Path | None:
42
+ rel = Path(ref.split("?", 1)[0].split("#", 1)[0])
43
+ for root in self.roots:
44
+ cand = (root / rel).resolve() if not rel.is_absolute() else rel.resolve()
45
+ if cand.is_file() and any(cand.is_relative_to(r) for r in self.roots):
46
+ return cand
47
+ return None
48
+
49
+ def resolve(self, ref: str, loc: Location | None = None) -> str | None:
50
+ """A URL for ``ref`` to put in ``src``, or None when a local file cannot be found."""
51
+ ref = ref.strip()
52
+ if not ref:
53
+ return None
54
+ if _REMOTE.match(ref):
55
+ return ref
56
+ if ref.lower().startswith("data:"):
57
+ if _DATA.match(ref):
58
+ return ref
59
+ self.diags.warning("only data:image/… URIs are accepted", loc, "asset")
60
+ return None
61
+ if re.match(r"^[a-z][a-z0-9+.-]*:", ref, re.I): # javascript:, file:, …
62
+ self.diags.warning(f"unsupported asset scheme in {ref!r}", loc, "asset")
63
+ return None
64
+ if not self.embed:
65
+ return ref
66
+ path = self._find(ref)
67
+ if path is None:
68
+ searched = ", ".join(str(r) for r in self.roots) or "(no asset paths)"
69
+ self.diags.warning(f"asset {ref!r} not found (searched {searched})", loc, "asset")
70
+ return None
71
+ if path in self._cache:
72
+ return self._cache[path]
73
+ size = path.stat().st_size
74
+ if size > self.max_bytes:
75
+ self.diags.warning(f"asset {ref!r} is {size} bytes, over the {self.max_bytes}-byte embed limit; "
76
+ "it is linked instead", loc, "asset")
77
+ return ref
78
+ mime = _MIME.get(path.suffix.lower()) or mimetypes.guess_type(path.name)[0]
79
+ if not mime or not mime.startswith("image/"):
80
+ self.diags.warning(f"asset {ref!r} is not a recognised image type", loc, "asset")
81
+ return None
82
+ uri = f"data:{mime};base64,{base64.b64encode(path.read_bytes()).decode('ascii')}"
83
+ self._cache[path] = uri
84
+ return uri