asyncapi-viewer 1.2.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.
- asyncapi_viewer-1.2.0/LICENSE +6 -0
- asyncapi_viewer-1.2.0/PKG-INFO +245 -0
- asyncapi_viewer-1.2.0/README.md +202 -0
- asyncapi_viewer-1.2.0/pyproject.toml +62 -0
- asyncapi_viewer-1.2.0/setup.cfg +4 -0
- asyncapi_viewer-1.2.0/src/asyncapi_viewer/__init__.py +29 -0
- asyncapi_viewer-1.2.0/src/asyncapi_viewer/assets.py +143 -0
- asyncapi_viewer-1.2.0/src/asyncapi_viewer/extension.py +385 -0
- asyncapi_viewer-1.2.0/src/asyncapi_viewer/mkdocs_plugin.py +114 -0
- asyncapi_viewer-1.2.0/src/asyncapi_viewer.egg-info/PKG-INFO +245 -0
- asyncapi_viewer-1.2.0/src/asyncapi_viewer.egg-info/SOURCES.txt +16 -0
- asyncapi_viewer-1.2.0/src/asyncapi_viewer.egg-info/dependency_links.txt +1 -0
- asyncapi_viewer-1.2.0/src/asyncapi_viewer.egg-info/entry_points.txt +7 -0
- asyncapi_viewer-1.2.0/src/asyncapi_viewer.egg-info/requires.txt +14 -0
- asyncapi_viewer-1.2.0/src/asyncapi_viewer.egg-info/top_level.txt +1 -0
- asyncapi_viewer-1.2.0/tests/test_extension.py +332 -0
- asyncapi_viewer-1.2.0/tests/test_legacy_shim.py +44 -0
- asyncapi_viewer-1.2.0/tests/test_mkdocs_plugin.py +193 -0
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright [2024] [Weesho Lapara]
|
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
|
+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: asyncapi-viewer
|
|
3
|
+
Version: 1.2.0
|
|
4
|
+
Summary: Render AsyncAPI documents in Markdown: an <asyncapi-viewer> element or an asyncapi fence. Python-Markdown extension with a MkDocs plugin.
|
|
5
|
+
Author-email: Weesho Lapara <support@weesholapara.com>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/Weesho-Lapara/asyncapi-viewer
|
|
8
|
+
Project-URL: Documentation, https://weesho-lapara.github.io/asyncapi-viewer/
|
|
9
|
+
Project-URL: Changelog, https://github.com/Weesho-Lapara/asyncapi-viewer/blob/main/CHANGELOG.md
|
|
10
|
+
Project-URL: Issues, https://github.com/Weesho-Lapara/asyncapi-viewer/issues
|
|
11
|
+
Keywords: asyncapi,markdown,mkdocs,documentation,event-driven,api
|
|
12
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
13
|
+
Classifier: Environment :: Web Environment
|
|
14
|
+
Classifier: Framework :: MkDocs
|
|
15
|
+
Classifier: Intended Audience :: Developers
|
|
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.9
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
23
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
24
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
25
|
+
Classifier: Topic :: Documentation
|
|
26
|
+
Classifier: Topic :: Software Development :: Documentation
|
|
27
|
+
Classifier: Topic :: Text Processing :: Markup :: Markdown
|
|
28
|
+
Requires-Python: >=3.9
|
|
29
|
+
Description-Content-Type: text/markdown
|
|
30
|
+
License-File: LICENSE
|
|
31
|
+
Requires-Dist: Markdown>=3.4
|
|
32
|
+
Provides-Extra: mkdocs
|
|
33
|
+
Requires-Dist: mkdocs>=1.5; extra == "mkdocs"
|
|
34
|
+
Provides-Extra: test
|
|
35
|
+
Requires-Dist: mkdocs>=1.5; extra == "test"
|
|
36
|
+
Requires-Dist: pytest>=7; extra == "test"
|
|
37
|
+
Requires-Dist: certifi; extra == "test"
|
|
38
|
+
Requires-Dist: pymdown-extensions>=10; extra == "test"
|
|
39
|
+
Provides-Extra: docs
|
|
40
|
+
Requires-Dist: mkdocs>=1.5; extra == "docs"
|
|
41
|
+
Requires-Dist: mkdocs-material>=9.5; extra == "docs"
|
|
42
|
+
Dynamic: license-file
|
|
43
|
+
|
|
44
|
+
# asyncapi-viewer
|
|
45
|
+
|
|
46
|
+
Render [AsyncAPI](https://www.asyncapi.com/) documents inside Markdown pages with a single element:
|
|
47
|
+
|
|
48
|
+
```html
|
|
49
|
+
<asyncapi-viewer src="asyncapi.yaml"></asyncapi-viewer>
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
`asyncapi-viewer` is a [Python-Markdown](https://python-markdown.github.io/) extension, so it works in
|
|
53
|
+
any tool built on Python-Markdown. It ships with a plugin for [MkDocs](https://www.mkdocs.org/)
|
|
54
|
+
that resolves document paths the same way MkDocs resolves links. Rendering in the browser is done
|
|
55
|
+
by the official [AsyncAPI React component](https://github.com/asyncapi/asyncapi-react), pinned to
|
|
56
|
+
an exact version and loaded with Subresource Integrity. JSON and YAML documents both work.
|
|
57
|
+
|
|
58
|
+
**Documentation and live demo:** https://weesho-lapara.github.io/asyncapi-viewer/
|
|
59
|
+
|
|
60
|
+
> Formerly published as `asyncapi-tag` (and before that `mkdocs-asyncapi-tag-plugin`). See [Migrating](#migrating-from-older-names).
|
|
61
|
+
|
|
62
|
+
## MkDocs
|
|
63
|
+
|
|
64
|
+
```sh
|
|
65
|
+
pip install asyncapi-viewer
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
```yaml
|
|
69
|
+
# mkdocs.yml
|
|
70
|
+
plugins:
|
|
71
|
+
- asyncapi-viewer
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
Put your AsyncAPI file anywhere under `docs/` and reference it from a page. Paths are relative to
|
|
75
|
+
the Markdown file, or relative to `docs/` when they start with `/`. Absolute `http(s)://` URLs are
|
|
76
|
+
passed through unchanged.
|
|
77
|
+
|
|
78
|
+
```markdown
|
|
79
|
+
<!-- docs/api/events.md -->
|
|
80
|
+
# Events API
|
|
81
|
+
|
|
82
|
+
<asyncapi-viewer src="events.yaml" sidebar="false"></asyncapi-viewer>
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
Prefer plain Markdown over raw HTML? The same thing as a fenced block, with the attribute names as
|
|
86
|
+
`key: value` lines (the path may also follow the language):
|
|
87
|
+
|
|
88
|
+
````markdown
|
|
89
|
+
```asyncapi
|
|
90
|
+
src: events.yaml
|
|
91
|
+
sidebar: false
|
|
92
|
+
```
|
|
93
|
+
````
|
|
94
|
+
|
|
95
|
+
A missing document or an invalid attribute is reported as a MkDocs warning, so `mkdocs build
|
|
96
|
+
--strict` fails instead of shipping a broken page.
|
|
97
|
+
|
|
98
|
+
### Plugin options
|
|
99
|
+
|
|
100
|
+
```yaml
|
|
101
|
+
plugins:
|
|
102
|
+
- asyncapi-viewer:
|
|
103
|
+
load_assets: true # emit the viewer script and stylesheet (default: true)
|
|
104
|
+
embed_css: true # keep the viewer inside its container (default: true)
|
|
105
|
+
viewer_js: https://unpkg.com/@asyncapi/react-component@3.2.1/browser/standalone/index.js
|
|
106
|
+
viewer_js_integrity: sha384-… # set to '' to omit the integrity attribute
|
|
107
|
+
viewer_css: https://unpkg.com/@asyncapi/react-component@3.2.1/styles/default.min.css
|
|
108
|
+
viewer_css_integrity: sha384-…
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
To self-host the viewer, copy the two files into `docs/` and point the options at them.
|
|
112
|
+
Relative paths are resolved per page like `src` is:
|
|
113
|
+
|
|
114
|
+
```yaml
|
|
115
|
+
plugins:
|
|
116
|
+
- asyncapi-viewer:
|
|
117
|
+
viewer_js: assets/asyncapi/index.js
|
|
118
|
+
viewer_js_integrity: ''
|
|
119
|
+
viewer_css: assets/asyncapi/default.min.css
|
|
120
|
+
viewer_css_integrity: ''
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
Or set `load_assets: false` and load the files yourself through `extra_javascript` and
|
|
124
|
+
`extra_css`. The page-side runner script is still needed in that case; copy it from
|
|
125
|
+
`asyncapi_viewer.assets.RUNNER_JS`.
|
|
126
|
+
|
|
127
|
+
## Zensical
|
|
128
|
+
|
|
129
|
+
[Zensical](https://zensical.org/) reads `mkdocs.yml` but does not run MkDocs plugins. Enable the
|
|
130
|
+
extension instead; relative `src` paths are rewritten per page by Zensical itself:
|
|
131
|
+
|
|
132
|
+
```yaml
|
|
133
|
+
markdown_extensions:
|
|
134
|
+
- asyncapi_viewer
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
Listing both the plugin and the extension lets one `mkdocs.yml` build under MkDocs and Zensical.
|
|
138
|
+
A Zensical build of this project's docs runs in CI.
|
|
139
|
+
|
|
140
|
+
## Plain Python-Markdown
|
|
141
|
+
|
|
142
|
+
```python
|
|
143
|
+
import markdown
|
|
144
|
+
|
|
145
|
+
html = markdown.markdown(text, extensions=["asyncapi_viewer"])
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
Extension options (pass them as `extension_configs={"asyncapi_viewer": {...}}`):
|
|
149
|
+
|
|
150
|
+
| Option | Default | Description |
|
|
151
|
+
|---|---|---|
|
|
152
|
+
| `viewer_js`, `viewer_css` | pinned unpkg URLs | Where to load the viewer from |
|
|
153
|
+
| `viewer_js_integrity`, `viewer_css_integrity` | matching SRI hashes | Empty string omits the attribute |
|
|
154
|
+
| `load_assets` | `True` | Emit the loader with the first tag on a page |
|
|
155
|
+
| `embed_css` | `True` | Emit the small stylesheet that keeps the viewer inside its container |
|
|
156
|
+
| `url_resolver` | identity | Callable mapping `src` (and relative asset URLs) to what the browser fetches |
|
|
157
|
+
| `warn` | `logging` | Callable receiving warning messages |
|
|
158
|
+
|
|
159
|
+
## Attributes
|
|
160
|
+
|
|
161
|
+
The same names work as element attributes and as `key: value` lines in an `asyncapi` fence.
|
|
162
|
+
Only `src` is required. Attribute names are case-insensitive. Boolean attributes accept
|
|
163
|
+
`true`/`false`, `1`/`0`, `yes`/`no`, `on`/`off`; a bare attribute means `true`.
|
|
164
|
+
|
|
165
|
+
| Attribute | Values | Default | Effect |
|
|
166
|
+
|---|---|---|---|
|
|
167
|
+
| `src` | path or URL | required | The AsyncAPI document (JSON or YAML) |
|
|
168
|
+
| `id` | string | `asyncapi-viewer-N` | HTML id of the container element |
|
|
169
|
+
| `sidebar` | boolean | `false` | Show the navigation sidebar (a toggle button inside the viewer when the column is narrow) |
|
|
170
|
+
| `info` | boolean | `true` | Show the info section |
|
|
171
|
+
| `servers` | boolean | `true` | Show servers |
|
|
172
|
+
| `operations` | boolean | `true` | Show operations |
|
|
173
|
+
| `messages` | boolean | `true` | Show messages |
|
|
174
|
+
| `schemas` | boolean | `true` | Show schemas |
|
|
175
|
+
| `errors` | boolean | `true` | Show parser errors |
|
|
176
|
+
| `showMessageExamples` | boolean | viewer default | Show examples for standalone messages |
|
|
177
|
+
| `messageExamples` | boolean | `true` | Expand message examples |
|
|
178
|
+
| `showServers` | `byDefault`, `bySpecTags`, `byServersTags` | `byDefault` | How the sidebar groups servers |
|
|
179
|
+
| `showOperations` | `byDefault`, `bySpecTags`, `byOperationsTags` | `byDefault` | How the sidebar groups operations |
|
|
180
|
+
| `useChannelAddressAsIdentifier` | boolean | viewer default | AsyncAPI v3: label operations by channel address |
|
|
181
|
+
| `publishLabel`, `subscribeLabel` | string | `PUB`, `SUB` | Operation labels for AsyncAPI v2 |
|
|
182
|
+
| `sendLabel`, `receiveLabel`, `requestLabel`, `replyLabel` | string | `SEND`, `RECEIVE`, `REQUEST`, `REPLY` | Operation labels for AsyncAPI v3 |
|
|
183
|
+
| `parserOptions` | JSON object | viewer default | Passed to the AsyncAPI parser, e.g. `parserOptions='{"applyTraits": false}'` |
|
|
184
|
+
| `schemaID` | string | container id | The viewer's `schemaID` option |
|
|
185
|
+
|
|
186
|
+
These map onto the React component's
|
|
187
|
+
[configuration](https://github.com/asyncapi/asyncapi-react/blob/master/docs/configuration/config-modification.md).
|
|
188
|
+
The default for `messageExamples` follows earlier releases of this plugin rather than the viewer.
|
|
189
|
+
|
|
190
|
+
## How it works
|
|
191
|
+
|
|
192
|
+
Each tag becomes a `<div class="asyncapi-viewer">` carrying the document URL and the viewer
|
|
193
|
+
configuration as HTML-escaped data attributes. The first tag on a page also emits the viewer's
|
|
194
|
+
stylesheet and script and a short runner script. The runner fetches each document as text, hands it
|
|
195
|
+
to `AsyncApiStandalone.render`, and prints a visible error inside the container if fetching or
|
|
196
|
+
rendering fails. No content from the Markdown source is interpolated into JavaScript.
|
|
197
|
+
|
|
198
|
+
Elements inside fenced or indented code blocks and inline code spans are left alone, and an
|
|
199
|
+
`asyncapi` fence nested in a longer fence stays code, so you can document the syntax.
|
|
200
|
+
|
|
201
|
+
Material for MkDocs users with `navigation.instant` enabled are covered: the runner re-scans the
|
|
202
|
+
page on Material's `document$` event.
|
|
203
|
+
|
|
204
|
+
## Migrating from older names
|
|
205
|
+
|
|
206
|
+
**From `asyncapi-tag` (1.0 and 1.1).** Replace `asyncapi-tag` with `asyncapi-viewer` in your
|
|
207
|
+
requirements. Nothing else has to change: the plugin id `asyncapi-tag`, the extension name
|
|
208
|
+
`asyncapi_tag` and the `<asyncapi-tag>` element are still accepted, and `asyncapi-tag` 1.2.0 on PyPI
|
|
209
|
+
is a shim that only depends on this package. When convenient, switch to `asyncapi-viewer`,
|
|
210
|
+
`asyncapi_viewer` and `<asyncapi-viewer>`; the old names will be removed in 3.0. Default container
|
|
211
|
+
ids changed from `asyncapi-tag-N` to `asyncapi-viewer-N`; set `id` if you link to them.
|
|
212
|
+
|
|
213
|
+
**From `mkdocs-asyncapi-tag-plugin` (0.x).** Also remove the `asyncapi_file` option (MkDocs copies
|
|
214
|
+
non-Markdown files itself), use page-relative paths in `src`, and check pages that set string
|
|
215
|
+
attributes such as `publishLabel`, which earlier versions silently discarded.
|
|
216
|
+
|
|
217
|
+
## Updating the pinned viewer
|
|
218
|
+
|
|
219
|
+
```sh
|
|
220
|
+
python scripts/update_viewer.py # latest @asyncapi/react-component
|
|
221
|
+
python scripts/update_viewer.py 3.2.1 # specific version
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
The script rewrites the version, URLs and SRI hashes in `src/asyncapi_viewer/assets.py`.
|
|
225
|
+
|
|
226
|
+
## Development
|
|
227
|
+
|
|
228
|
+
```sh
|
|
229
|
+
python -m venv .venv && source .venv/bin/activate
|
|
230
|
+
pip install -e ".[test]"
|
|
231
|
+
pytest
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
The JavaScript runner is syntax-checked with `node` when it is installed. Build the docs site with
|
|
235
|
+
`pip install -e ".[docs]" && mkdocs build --strict`. See `AGENTS.md` for the repository layout and
|
|
236
|
+
release procedure.
|
|
237
|
+
|
|
238
|
+
## Roadmap
|
|
239
|
+
|
|
240
|
+
Plans and evaluations of other ecosystems (Docusaurus, Zensical, MkDocs 2.0) are in
|
|
241
|
+
[ROADMAP.md](https://github.com/Weesho-Lapara/asyncapi-viewer/blob/main/ROADMAP.md).
|
|
242
|
+
|
|
243
|
+
## License
|
|
244
|
+
|
|
245
|
+
MIT
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
# asyncapi-viewer
|
|
2
|
+
|
|
3
|
+
Render [AsyncAPI](https://www.asyncapi.com/) documents inside Markdown pages with a single element:
|
|
4
|
+
|
|
5
|
+
```html
|
|
6
|
+
<asyncapi-viewer src="asyncapi.yaml"></asyncapi-viewer>
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
`asyncapi-viewer` is a [Python-Markdown](https://python-markdown.github.io/) extension, so it works in
|
|
10
|
+
any tool built on Python-Markdown. It ships with a plugin for [MkDocs](https://www.mkdocs.org/)
|
|
11
|
+
that resolves document paths the same way MkDocs resolves links. Rendering in the browser is done
|
|
12
|
+
by the official [AsyncAPI React component](https://github.com/asyncapi/asyncapi-react), pinned to
|
|
13
|
+
an exact version and loaded with Subresource Integrity. JSON and YAML documents both work.
|
|
14
|
+
|
|
15
|
+
**Documentation and live demo:** https://weesho-lapara.github.io/asyncapi-viewer/
|
|
16
|
+
|
|
17
|
+
> Formerly published as `asyncapi-tag` (and before that `mkdocs-asyncapi-tag-plugin`). See [Migrating](#migrating-from-older-names).
|
|
18
|
+
|
|
19
|
+
## MkDocs
|
|
20
|
+
|
|
21
|
+
```sh
|
|
22
|
+
pip install asyncapi-viewer
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
```yaml
|
|
26
|
+
# mkdocs.yml
|
|
27
|
+
plugins:
|
|
28
|
+
- asyncapi-viewer
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Put your AsyncAPI file anywhere under `docs/` and reference it from a page. Paths are relative to
|
|
32
|
+
the Markdown file, or relative to `docs/` when they start with `/`. Absolute `http(s)://` URLs are
|
|
33
|
+
passed through unchanged.
|
|
34
|
+
|
|
35
|
+
```markdown
|
|
36
|
+
<!-- docs/api/events.md -->
|
|
37
|
+
# Events API
|
|
38
|
+
|
|
39
|
+
<asyncapi-viewer src="events.yaml" sidebar="false"></asyncapi-viewer>
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
Prefer plain Markdown over raw HTML? The same thing as a fenced block, with the attribute names as
|
|
43
|
+
`key: value` lines (the path may also follow the language):
|
|
44
|
+
|
|
45
|
+
````markdown
|
|
46
|
+
```asyncapi
|
|
47
|
+
src: events.yaml
|
|
48
|
+
sidebar: false
|
|
49
|
+
```
|
|
50
|
+
````
|
|
51
|
+
|
|
52
|
+
A missing document or an invalid attribute is reported as a MkDocs warning, so `mkdocs build
|
|
53
|
+
--strict` fails instead of shipping a broken page.
|
|
54
|
+
|
|
55
|
+
### Plugin options
|
|
56
|
+
|
|
57
|
+
```yaml
|
|
58
|
+
plugins:
|
|
59
|
+
- asyncapi-viewer:
|
|
60
|
+
load_assets: true # emit the viewer script and stylesheet (default: true)
|
|
61
|
+
embed_css: true # keep the viewer inside its container (default: true)
|
|
62
|
+
viewer_js: https://unpkg.com/@asyncapi/react-component@3.2.1/browser/standalone/index.js
|
|
63
|
+
viewer_js_integrity: sha384-… # set to '' to omit the integrity attribute
|
|
64
|
+
viewer_css: https://unpkg.com/@asyncapi/react-component@3.2.1/styles/default.min.css
|
|
65
|
+
viewer_css_integrity: sha384-…
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
To self-host the viewer, copy the two files into `docs/` and point the options at them.
|
|
69
|
+
Relative paths are resolved per page like `src` is:
|
|
70
|
+
|
|
71
|
+
```yaml
|
|
72
|
+
plugins:
|
|
73
|
+
- asyncapi-viewer:
|
|
74
|
+
viewer_js: assets/asyncapi/index.js
|
|
75
|
+
viewer_js_integrity: ''
|
|
76
|
+
viewer_css: assets/asyncapi/default.min.css
|
|
77
|
+
viewer_css_integrity: ''
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
Or set `load_assets: false` and load the files yourself through `extra_javascript` and
|
|
81
|
+
`extra_css`. The page-side runner script is still needed in that case; copy it from
|
|
82
|
+
`asyncapi_viewer.assets.RUNNER_JS`.
|
|
83
|
+
|
|
84
|
+
## Zensical
|
|
85
|
+
|
|
86
|
+
[Zensical](https://zensical.org/) reads `mkdocs.yml` but does not run MkDocs plugins. Enable the
|
|
87
|
+
extension instead; relative `src` paths are rewritten per page by Zensical itself:
|
|
88
|
+
|
|
89
|
+
```yaml
|
|
90
|
+
markdown_extensions:
|
|
91
|
+
- asyncapi_viewer
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
Listing both the plugin and the extension lets one `mkdocs.yml` build under MkDocs and Zensical.
|
|
95
|
+
A Zensical build of this project's docs runs in CI.
|
|
96
|
+
|
|
97
|
+
## Plain Python-Markdown
|
|
98
|
+
|
|
99
|
+
```python
|
|
100
|
+
import markdown
|
|
101
|
+
|
|
102
|
+
html = markdown.markdown(text, extensions=["asyncapi_viewer"])
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
Extension options (pass them as `extension_configs={"asyncapi_viewer": {...}}`):
|
|
106
|
+
|
|
107
|
+
| Option | Default | Description |
|
|
108
|
+
|---|---|---|
|
|
109
|
+
| `viewer_js`, `viewer_css` | pinned unpkg URLs | Where to load the viewer from |
|
|
110
|
+
| `viewer_js_integrity`, `viewer_css_integrity` | matching SRI hashes | Empty string omits the attribute |
|
|
111
|
+
| `load_assets` | `True` | Emit the loader with the first tag on a page |
|
|
112
|
+
| `embed_css` | `True` | Emit the small stylesheet that keeps the viewer inside its container |
|
|
113
|
+
| `url_resolver` | identity | Callable mapping `src` (and relative asset URLs) to what the browser fetches |
|
|
114
|
+
| `warn` | `logging` | Callable receiving warning messages |
|
|
115
|
+
|
|
116
|
+
## Attributes
|
|
117
|
+
|
|
118
|
+
The same names work as element attributes and as `key: value` lines in an `asyncapi` fence.
|
|
119
|
+
Only `src` is required. Attribute names are case-insensitive. Boolean attributes accept
|
|
120
|
+
`true`/`false`, `1`/`0`, `yes`/`no`, `on`/`off`; a bare attribute means `true`.
|
|
121
|
+
|
|
122
|
+
| Attribute | Values | Default | Effect |
|
|
123
|
+
|---|---|---|---|
|
|
124
|
+
| `src` | path or URL | required | The AsyncAPI document (JSON or YAML) |
|
|
125
|
+
| `id` | string | `asyncapi-viewer-N` | HTML id of the container element |
|
|
126
|
+
| `sidebar` | boolean | `false` | Show the navigation sidebar (a toggle button inside the viewer when the column is narrow) |
|
|
127
|
+
| `info` | boolean | `true` | Show the info section |
|
|
128
|
+
| `servers` | boolean | `true` | Show servers |
|
|
129
|
+
| `operations` | boolean | `true` | Show operations |
|
|
130
|
+
| `messages` | boolean | `true` | Show messages |
|
|
131
|
+
| `schemas` | boolean | `true` | Show schemas |
|
|
132
|
+
| `errors` | boolean | `true` | Show parser errors |
|
|
133
|
+
| `showMessageExamples` | boolean | viewer default | Show examples for standalone messages |
|
|
134
|
+
| `messageExamples` | boolean | `true` | Expand message examples |
|
|
135
|
+
| `showServers` | `byDefault`, `bySpecTags`, `byServersTags` | `byDefault` | How the sidebar groups servers |
|
|
136
|
+
| `showOperations` | `byDefault`, `bySpecTags`, `byOperationsTags` | `byDefault` | How the sidebar groups operations |
|
|
137
|
+
| `useChannelAddressAsIdentifier` | boolean | viewer default | AsyncAPI v3: label operations by channel address |
|
|
138
|
+
| `publishLabel`, `subscribeLabel` | string | `PUB`, `SUB` | Operation labels for AsyncAPI v2 |
|
|
139
|
+
| `sendLabel`, `receiveLabel`, `requestLabel`, `replyLabel` | string | `SEND`, `RECEIVE`, `REQUEST`, `REPLY` | Operation labels for AsyncAPI v3 |
|
|
140
|
+
| `parserOptions` | JSON object | viewer default | Passed to the AsyncAPI parser, e.g. `parserOptions='{"applyTraits": false}'` |
|
|
141
|
+
| `schemaID` | string | container id | The viewer's `schemaID` option |
|
|
142
|
+
|
|
143
|
+
These map onto the React component's
|
|
144
|
+
[configuration](https://github.com/asyncapi/asyncapi-react/blob/master/docs/configuration/config-modification.md).
|
|
145
|
+
The default for `messageExamples` follows earlier releases of this plugin rather than the viewer.
|
|
146
|
+
|
|
147
|
+
## How it works
|
|
148
|
+
|
|
149
|
+
Each tag becomes a `<div class="asyncapi-viewer">` carrying the document URL and the viewer
|
|
150
|
+
configuration as HTML-escaped data attributes. The first tag on a page also emits the viewer's
|
|
151
|
+
stylesheet and script and a short runner script. The runner fetches each document as text, hands it
|
|
152
|
+
to `AsyncApiStandalone.render`, and prints a visible error inside the container if fetching or
|
|
153
|
+
rendering fails. No content from the Markdown source is interpolated into JavaScript.
|
|
154
|
+
|
|
155
|
+
Elements inside fenced or indented code blocks and inline code spans are left alone, and an
|
|
156
|
+
`asyncapi` fence nested in a longer fence stays code, so you can document the syntax.
|
|
157
|
+
|
|
158
|
+
Material for MkDocs users with `navigation.instant` enabled are covered: the runner re-scans the
|
|
159
|
+
page on Material's `document$` event.
|
|
160
|
+
|
|
161
|
+
## Migrating from older names
|
|
162
|
+
|
|
163
|
+
**From `asyncapi-tag` (1.0 and 1.1).** Replace `asyncapi-tag` with `asyncapi-viewer` in your
|
|
164
|
+
requirements. Nothing else has to change: the plugin id `asyncapi-tag`, the extension name
|
|
165
|
+
`asyncapi_tag` and the `<asyncapi-tag>` element are still accepted, and `asyncapi-tag` 1.2.0 on PyPI
|
|
166
|
+
is a shim that only depends on this package. When convenient, switch to `asyncapi-viewer`,
|
|
167
|
+
`asyncapi_viewer` and `<asyncapi-viewer>`; the old names will be removed in 3.0. Default container
|
|
168
|
+
ids changed from `asyncapi-tag-N` to `asyncapi-viewer-N`; set `id` if you link to them.
|
|
169
|
+
|
|
170
|
+
**From `mkdocs-asyncapi-tag-plugin` (0.x).** Also remove the `asyncapi_file` option (MkDocs copies
|
|
171
|
+
non-Markdown files itself), use page-relative paths in `src`, and check pages that set string
|
|
172
|
+
attributes such as `publishLabel`, which earlier versions silently discarded.
|
|
173
|
+
|
|
174
|
+
## Updating the pinned viewer
|
|
175
|
+
|
|
176
|
+
```sh
|
|
177
|
+
python scripts/update_viewer.py # latest @asyncapi/react-component
|
|
178
|
+
python scripts/update_viewer.py 3.2.1 # specific version
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
The script rewrites the version, URLs and SRI hashes in `src/asyncapi_viewer/assets.py`.
|
|
182
|
+
|
|
183
|
+
## Development
|
|
184
|
+
|
|
185
|
+
```sh
|
|
186
|
+
python -m venv .venv && source .venv/bin/activate
|
|
187
|
+
pip install -e ".[test]"
|
|
188
|
+
pytest
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
The JavaScript runner is syntax-checked with `node` when it is installed. Build the docs site with
|
|
192
|
+
`pip install -e ".[docs]" && mkdocs build --strict`. See `AGENTS.md` for the repository layout and
|
|
193
|
+
release procedure.
|
|
194
|
+
|
|
195
|
+
## Roadmap
|
|
196
|
+
|
|
197
|
+
Plans and evaluations of other ecosystems (Docusaurus, Zensical, MkDocs 2.0) are in
|
|
198
|
+
[ROADMAP.md](https://github.com/Weesho-Lapara/asyncapi-viewer/blob/main/ROADMAP.md).
|
|
199
|
+
|
|
200
|
+
## License
|
|
201
|
+
|
|
202
|
+
MIT
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=77"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "asyncapi-viewer"
|
|
7
|
+
dynamic = ["version"]
|
|
8
|
+
description = "Render AsyncAPI documents in Markdown: an <asyncapi-viewer> element or an asyncapi fence. Python-Markdown extension with a MkDocs plugin."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = "MIT"
|
|
11
|
+
license-files = ["LICENSE"]
|
|
12
|
+
requires-python = ">=3.9"
|
|
13
|
+
authors = [{ name = "Weesho Lapara", email = "support@weesholapara.com" }]
|
|
14
|
+
keywords = ["asyncapi", "markdown", "mkdocs", "documentation", "event-driven", "api"]
|
|
15
|
+
classifiers = [
|
|
16
|
+
"Development Status :: 5 - Production/Stable",
|
|
17
|
+
"Environment :: Web Environment",
|
|
18
|
+
"Framework :: MkDocs",
|
|
19
|
+
"Intended Audience :: Developers",
|
|
20
|
+
"Operating System :: OS Independent",
|
|
21
|
+
"Programming Language :: Python :: 3",
|
|
22
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
23
|
+
"Programming Language :: Python :: 3.9",
|
|
24
|
+
"Programming Language :: Python :: 3.10",
|
|
25
|
+
"Programming Language :: Python :: 3.11",
|
|
26
|
+
"Programming Language :: Python :: 3.12",
|
|
27
|
+
"Programming Language :: Python :: 3.13",
|
|
28
|
+
"Programming Language :: Python :: 3.14",
|
|
29
|
+
"Topic :: Documentation",
|
|
30
|
+
"Topic :: Software Development :: Documentation",
|
|
31
|
+
"Topic :: Text Processing :: Markup :: Markdown",
|
|
32
|
+
]
|
|
33
|
+
dependencies = ["Markdown>=3.4"]
|
|
34
|
+
|
|
35
|
+
[project.optional-dependencies]
|
|
36
|
+
mkdocs = ["mkdocs>=1.5"]
|
|
37
|
+
test = ["mkdocs>=1.5", "pytest>=7", "certifi", "pymdown-extensions>=10"]
|
|
38
|
+
docs = ["mkdocs>=1.5", "mkdocs-material>=9.5"]
|
|
39
|
+
|
|
40
|
+
[project.urls]
|
|
41
|
+
Homepage = "https://github.com/Weesho-Lapara/asyncapi-viewer"
|
|
42
|
+
Documentation = "https://weesho-lapara.github.io/asyncapi-viewer/"
|
|
43
|
+
Changelog = "https://github.com/Weesho-Lapara/asyncapi-viewer/blob/main/CHANGELOG.md"
|
|
44
|
+
Issues = "https://github.com/Weesho-Lapara/asyncapi-viewer/issues"
|
|
45
|
+
|
|
46
|
+
[project.entry-points."markdown.extensions"]
|
|
47
|
+
asyncapi_viewer = "asyncapi_viewer.extension:AsyncAPIViewerExtension"
|
|
48
|
+
asyncapi_tag = "asyncapi_viewer.extension:AsyncAPIViewerExtension"
|
|
49
|
+
|
|
50
|
+
[project.entry-points."mkdocs.plugins"]
|
|
51
|
+
asyncapi-viewer = "asyncapi_viewer.mkdocs_plugin:AsyncAPIPlugin"
|
|
52
|
+
asyncapi-tag = "asyncapi_viewer.mkdocs_plugin:AsyncAPIPlugin"
|
|
53
|
+
|
|
54
|
+
[tool.setuptools.dynamic]
|
|
55
|
+
version = { attr = "asyncapi_viewer.__version__" }
|
|
56
|
+
|
|
57
|
+
[tool.setuptools.packages.find]
|
|
58
|
+
where = ["src"]
|
|
59
|
+
|
|
60
|
+
[tool.pytest.ini_options]
|
|
61
|
+
testpaths = ["tests"]
|
|
62
|
+
addopts = "-ra"
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"""Render AsyncAPI documents in Markdown with an ``<asyncapi-viewer>`` element.
|
|
2
|
+
|
|
3
|
+
The package is a `Python-Markdown <https://python-markdown.github.io/>`_
|
|
4
|
+
extension (:class:`asyncapi_viewer.extension.AsyncAPIViewerExtension`) and a thin
|
|
5
|
+
MkDocs plugin around it (:class:`asyncapi_viewer.mkdocs_plugin.AsyncAPIPlugin`).
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from asyncapi_viewer.assets import (
|
|
9
|
+
VIEWER_CSS_INTEGRITY,
|
|
10
|
+
VIEWER_CSS_URL,
|
|
11
|
+
VIEWER_JS_INTEGRITY,
|
|
12
|
+
VIEWER_JS_URL,
|
|
13
|
+
VIEWER_VERSION,
|
|
14
|
+
)
|
|
15
|
+
from asyncapi_viewer.extension import AsyncAPITagExtension, AsyncAPIViewerExtension, makeExtension
|
|
16
|
+
|
|
17
|
+
__version__ = "1.2.0"
|
|
18
|
+
|
|
19
|
+
__all__ = [
|
|
20
|
+
"AsyncAPIViewerExtension",
|
|
21
|
+
"AsyncAPITagExtension",
|
|
22
|
+
"makeExtension",
|
|
23
|
+
"VIEWER_VERSION",
|
|
24
|
+
"VIEWER_JS_URL",
|
|
25
|
+
"VIEWER_JS_INTEGRITY",
|
|
26
|
+
"VIEWER_CSS_URL",
|
|
27
|
+
"VIEWER_CSS_INTEGRITY",
|
|
28
|
+
"__version__",
|
|
29
|
+
]
|