wenmode 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.
- wenmode-0.1.0/.editorconfig +11 -0
- wenmode-0.1.0/.github/CODE_OF_CONDUCT.md +13 -0
- wenmode-0.1.0/.github/FUNDING.yml +2 -0
- wenmode-0.1.0/.github/workflows/docs.yml +54 -0
- wenmode-0.1.0/.github/workflows/pypi.yml +75 -0
- wenmode-0.1.0/.github/workflows/test.yml +83 -0
- wenmode-0.1.0/.gitignore +19 -0
- wenmode-0.1.0/.python-version +1 -0
- wenmode-0.1.0/LICENSE +28 -0
- wenmode-0.1.0/PKG-INFO +269 -0
- wenmode-0.1.0/README.md +239 -0
- wenmode-0.1.0/docs/.gitignore +1 -0
- wenmode-0.1.0/docs/_static/custom.css +201 -0
- wenmode-0.1.0/docs/_static/dark-logo.svg +45 -0
- wenmode-0.1.0/docs/_static/light-logo.svg +45 -0
- wenmode-0.1.0/docs/_static/wenmode-mark.svg +43 -0
- wenmode-0.1.0/docs/api/directives.rst +21 -0
- wenmode-0.1.0/docs/api/helpers.rst +28 -0
- wenmode-0.1.0/docs/api/main.rst +14 -0
- wenmode-0.1.0/docs/api/nodes.rst +8 -0
- wenmode-0.1.0/docs/api/renderers.rst +24 -0
- wenmode-0.1.0/docs/api/rules.rst +111 -0
- wenmode-0.1.0/docs/api.rst +25 -0
- wenmode-0.1.0/docs/benchmarks.md +99 -0
- wenmode-0.1.0/docs/changelog.md +26 -0
- wenmode-0.1.0/docs/compatibility.md +63 -0
- wenmode-0.1.0/docs/compliance.md +55 -0
- wenmode-0.1.0/docs/conf.py +45 -0
- wenmode-0.1.0/docs/custom-rules.md +462 -0
- wenmode-0.1.0/docs/development.md +82 -0
- wenmode-0.1.0/docs/directives.md +254 -0
- wenmode-0.1.0/docs/index.md +184 -0
- wenmode-0.1.0/docs/integrations.md +192 -0
- wenmode-0.1.0/docs/internals.md +154 -0
- wenmode-0.1.0/docs/migration/commonmark-py.md +147 -0
- wenmode-0.1.0/docs/migration/index.md +98 -0
- wenmode-0.1.0/docs/migration/markdown-it-py.md +230 -0
- wenmode-0.1.0/docs/migration/markdown2.md +187 -0
- wenmode-0.1.0/docs/migration/marko.md +182 -0
- wenmode-0.1.0/docs/migration/mistune.md +223 -0
- wenmode-0.1.0/docs/migration/python-markdown.md +233 -0
- wenmode-0.1.0/docs/presets.md +129 -0
- wenmode-0.1.0/docs/recipes.md +214 -0
- wenmode-0.1.0/docs/references/core-blocks.md +372 -0
- wenmode-0.1.0/docs/references/core-inlines.md +418 -0
- wenmode-0.1.0/docs/references/extension-blocks.md +474 -0
- wenmode-0.1.0/docs/references/extension-inlines.md +379 -0
- wenmode-0.1.0/docs/references/index.md +35 -0
- wenmode-0.1.0/docs/references/nodes.md +36 -0
- wenmode-0.1.0/docs/rule-matrix.md +128 -0
- wenmode-0.1.0/docs/rules.md +118 -0
- wenmode-0.1.0/docs/security.md +176 -0
- wenmode-0.1.0/docs/troubleshooting.md +111 -0
- wenmode-0.1.0/docs/usage.md +257 -0
- wenmode-0.1.0/pyproject.toml +119 -0
- wenmode-0.1.0/scripts/benchmark.py +372 -0
- wenmode-0.1.0/scripts/download_commonmark_spec.py +19 -0
- wenmode-0.1.0/scripts/download_gfm_spec.py +119 -0
- wenmode-0.1.0/src/wenmode/__init__.py +17 -0
- wenmode-0.1.0/src/wenmode/directives/__init__.py +9 -0
- wenmode-0.1.0/src/wenmode/directives/abbr.py +27 -0
- wenmode-0.1.0/src/wenmode/directives/admonition.py +36 -0
- wenmode-0.1.0/src/wenmode/directives/details.py +32 -0
- wenmode-0.1.0/src/wenmode/directives/figure.py +34 -0
- wenmode-0.1.0/src/wenmode/directives/toc.py +60 -0
- wenmode-0.1.0/src/wenmode/directives/util.py +15 -0
- wenmode-0.1.0/src/wenmode/headings.py +110 -0
- wenmode-0.1.0/src/wenmode/nodes.py +358 -0
- wenmode-0.1.0/src/wenmode/parser.py +440 -0
- wenmode-0.1.0/src/wenmode/presets.py +101 -0
- wenmode-0.1.0/src/wenmode/py.typed +1 -0
- wenmode-0.1.0/src/wenmode/renderers/__init__.py +18 -0
- wenmode-0.1.0/src/wenmode/renderers/base.py +103 -0
- wenmode-0.1.0/src/wenmode/renderers/html.py +532 -0
- wenmode-0.1.0/src/wenmode/renderers/markdown.py +421 -0
- wenmode-0.1.0/src/wenmode/renderers/rst.py +469 -0
- wenmode-0.1.0/src/wenmode/rules/__init__.py +79 -0
- wenmode-0.1.0/src/wenmode/rules/base.py +106 -0
- wenmode-0.1.0/src/wenmode/rules/blocks/__init__.py +30 -0
- wenmode-0.1.0/src/wenmode/rules/blocks/abbr.py +142 -0
- wenmode-0.1.0/src/wenmode/rules/blocks/blockquote.py +87 -0
- wenmode-0.1.0/src/wenmode/rules/blocks/definition_list.py +115 -0
- wenmode-0.1.0/src/wenmode/rules/blocks/directive.py +153 -0
- wenmode-0.1.0/src/wenmode/rules/blocks/fenced_code.py +73 -0
- wenmode-0.1.0/src/wenmode/rules/blocks/heading.py +115 -0
- wenmode-0.1.0/src/wenmode/rules/blocks/html.py +164 -0
- wenmode-0.1.0/src/wenmode/rules/blocks/indented_code.py +63 -0
- wenmode-0.1.0/src/wenmode/rules/blocks/list.py +258 -0
- wenmode-0.1.0/src/wenmode/rules/blocks/math.py +49 -0
- wenmode-0.1.0/src/wenmode/rules/blocks/spoiler.py +48 -0
- wenmode-0.1.0/src/wenmode/rules/blocks/table.py +142 -0
- wenmode-0.1.0/src/wenmode/rules/blocks/thematic_break.py +34 -0
- wenmode-0.1.0/src/wenmode/rules/blocks/util.py +38 -0
- wenmode-0.1.0/src/wenmode/rules/directives.py +136 -0
- wenmode-0.1.0/src/wenmode/rules/footnotes.py +188 -0
- wenmode-0.1.0/src/wenmode/rules/inlines/__init__.py +30 -0
- wenmode-0.1.0/src/wenmode/rules/inlines/code.py +45 -0
- wenmode-0.1.0/src/wenmode/rules/inlines/directive.py +92 -0
- wenmode-0.1.0/src/wenmode/rules/inlines/emphasis.py +268 -0
- wenmode-0.1.0/src/wenmode/rules/inlines/extended_autolink.py +195 -0
- wenmode-0.1.0/src/wenmode/rules/inlines/formatting.py +139 -0
- wenmode-0.1.0/src/wenmode/rules/inlines/html.py +95 -0
- wenmode-0.1.0/src/wenmode/rules/inlines/link.py +350 -0
- wenmode-0.1.0/src/wenmode/rules/inlines/math.py +83 -0
- wenmode-0.1.0/src/wenmode/rules/inlines/ruby.py +82 -0
- wenmode-0.1.0/src/wenmode/rules/inlines/spoiler.py +32 -0
- wenmode-0.1.0/src/wenmode/rules/inlines/strikethrough.py +57 -0
- wenmode-0.1.0/src/wenmode/rules/inlines/text.py +106 -0
- wenmode-0.1.0/src/wenmode/rules/references.py +209 -0
- wenmode-0.1.0/src/wenmode/rules/transforms.py +31 -0
- wenmode-0.1.0/src/wenmode/state.py +193 -0
- wenmode-0.1.0/src/wenmode/toc.py +72 -0
- wenmode-0.1.0/src/wenmode/utils.py +80 -0
- wenmode-0.1.0/src/wenmode/wenmode.py +102 -0
- wenmode-0.1.0/tests/__init__.py +1 -0
- wenmode-0.1.0/tests/_edge_helpers.py +63 -0
- wenmode-0.1.0/tests/_renderer_fixtures.py +128 -0
- wenmode-0.1.0/tests/fixtures/block_rule_edges.json +99 -0
- wenmode-0.1.0/tests/fixtures/commonmark-0.31.2.json +5218 -0
- wenmode-0.1.0/tests/fixtures/directive_reference_edges.json +14 -0
- wenmode-0.1.0/tests/fixtures/directives_ast.json +244 -0
- wenmode-0.1.0/tests/fixtures/directives_html.json +28 -0
- wenmode-0.1.0/tests/fixtures/footnotes.json +32 -0
- wenmode-0.1.0/tests/fixtures/gfm-0.29.json +4064 -0
- wenmode-0.1.0/tests/fixtures/html_render.json +205 -0
- wenmode-0.1.0/tests/fixtures/inline_rule_edges.json +32 -0
- wenmode-0.1.0/tests/fixtures/markdown_render.json +255 -0
- wenmode-0.1.0/tests/fixtures/math.json +52 -0
- wenmode-0.1.0/tests/fixtures/rst_render.json +338 -0
- wenmode-0.1.0/tests/test_base_render.py +35 -0
- wenmode-0.1.0/tests/test_block_rule_edges.py +262 -0
- wenmode-0.1.0/tests/test_commonmark_spec.py +36 -0
- wenmode-0.1.0/tests/test_core_edges.py +185 -0
- wenmode-0.1.0/tests/test_directive_reference_edges.py +153 -0
- wenmode-0.1.0/tests/test_directives.py +182 -0
- wenmode-0.1.0/tests/test_docs_examples.py +87 -0
- wenmode-0.1.0/tests/test_extended_rules.py +219 -0
- wenmode-0.1.0/tests/test_gfm_spec.py +44 -0
- wenmode-0.1.0/tests/test_html_render.py +170 -0
- wenmode-0.1.0/tests/test_inline_rule_edges.py +203 -0
- wenmode-0.1.0/tests/test_markdown_render.py +82 -0
- wenmode-0.1.0/tests/test_parser_design.py +324 -0
- wenmode-0.1.0/tests/test_performance.py +34 -0
- wenmode-0.1.0/tests/test_rst_render.py +31 -0
- wenmode-0.1.0/tests/test_toc.py +95 -0
- wenmode-0.1.0/tests/test_wenmode.py +43 -0
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# Contributor Code of Conduct
|
|
2
|
+
|
|
3
|
+
As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
|
|
4
|
+
|
|
5
|
+
We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, age, or religion.
|
|
6
|
+
|
|
7
|
+
Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
|
|
8
|
+
|
|
9
|
+
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
|
|
10
|
+
|
|
11
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
|
|
12
|
+
|
|
13
|
+
This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
name: Publish docs
|
|
2
|
+
|
|
3
|
+
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
|
|
4
|
+
permissions:
|
|
5
|
+
contents: read
|
|
6
|
+
pages: write
|
|
7
|
+
id-token: write
|
|
8
|
+
|
|
9
|
+
# Allow one concurrent deployment
|
|
10
|
+
concurrency:
|
|
11
|
+
group: "pages"
|
|
12
|
+
cancel-in-progress: true
|
|
13
|
+
|
|
14
|
+
on:
|
|
15
|
+
push:
|
|
16
|
+
branches:
|
|
17
|
+
- main
|
|
18
|
+
paths-ignore:
|
|
19
|
+
- "tests/**"
|
|
20
|
+
workflow_dispatch:
|
|
21
|
+
|
|
22
|
+
jobs:
|
|
23
|
+
build:
|
|
24
|
+
runs-on: ubuntu-latest
|
|
25
|
+
|
|
26
|
+
steps:
|
|
27
|
+
- uses: actions/checkout@v6
|
|
28
|
+
- uses: actions/setup-python@v6
|
|
29
|
+
with:
|
|
30
|
+
python-version: "3.13"
|
|
31
|
+
|
|
32
|
+
- name: install dependencies
|
|
33
|
+
run: python -m pip install --upgrade uv
|
|
34
|
+
|
|
35
|
+
- name: sphinx build
|
|
36
|
+
run: uv run --group docs sphinx-build -b html docs public -W --keep-going
|
|
37
|
+
|
|
38
|
+
- name: Upload artifact
|
|
39
|
+
uses: actions/upload-pages-artifact@v5
|
|
40
|
+
with:
|
|
41
|
+
path: public
|
|
42
|
+
|
|
43
|
+
deploy:
|
|
44
|
+
environment:
|
|
45
|
+
name: github-pages
|
|
46
|
+
url: ${{ steps.deployment.outputs.page_url }}
|
|
47
|
+
|
|
48
|
+
runs-on: ubuntu-latest
|
|
49
|
+
needs: build
|
|
50
|
+
|
|
51
|
+
steps:
|
|
52
|
+
- name: Deploy to GitHub Pages
|
|
53
|
+
id: deployment
|
|
54
|
+
uses: actions/deploy-pages@v5
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
name: Release to PyPI
|
|
2
|
+
|
|
3
|
+
permissions:
|
|
4
|
+
contents: read
|
|
5
|
+
|
|
6
|
+
on:
|
|
7
|
+
push:
|
|
8
|
+
tags:
|
|
9
|
+
- "[0-9]*"
|
|
10
|
+
workflow_dispatch:
|
|
11
|
+
|
|
12
|
+
jobs:
|
|
13
|
+
build:
|
|
14
|
+
name: build dist files
|
|
15
|
+
runs-on: ubuntu-latest
|
|
16
|
+
|
|
17
|
+
steps:
|
|
18
|
+
- uses: actions/checkout@v6
|
|
19
|
+
|
|
20
|
+
- uses: actions/setup-python@v6
|
|
21
|
+
with:
|
|
22
|
+
python-version: "3.10"
|
|
23
|
+
|
|
24
|
+
- name: install uv
|
|
25
|
+
run: python -m pip install --upgrade uv
|
|
26
|
+
|
|
27
|
+
- name: build dist
|
|
28
|
+
run: uv build
|
|
29
|
+
|
|
30
|
+
- name: check dist metadata
|
|
31
|
+
run: uv run --with twine twine check dist/*
|
|
32
|
+
|
|
33
|
+
- uses: actions/upload-artifact@v7
|
|
34
|
+
with:
|
|
35
|
+
name: artifacts
|
|
36
|
+
path: dist/*
|
|
37
|
+
if-no-files-found: error
|
|
38
|
+
|
|
39
|
+
publish:
|
|
40
|
+
environment:
|
|
41
|
+
name: pypi
|
|
42
|
+
url: https://pypi.org/project/wenmode/
|
|
43
|
+
permissions:
|
|
44
|
+
id-token: write
|
|
45
|
+
name: release to pypi
|
|
46
|
+
needs: build
|
|
47
|
+
runs-on: ubuntu-latest
|
|
48
|
+
|
|
49
|
+
steps:
|
|
50
|
+
- uses: actions/download-artifact@v8
|
|
51
|
+
with:
|
|
52
|
+
name: artifacts
|
|
53
|
+
path: dist
|
|
54
|
+
|
|
55
|
+
- name: Push build artifacts to PyPI
|
|
56
|
+
uses: pypa/gh-action-pypi-publish@release/v1
|
|
57
|
+
|
|
58
|
+
release:
|
|
59
|
+
name: write release note
|
|
60
|
+
runs-on: ubuntu-latest
|
|
61
|
+
needs: publish
|
|
62
|
+
permissions:
|
|
63
|
+
contents: write
|
|
64
|
+
|
|
65
|
+
steps:
|
|
66
|
+
- uses: actions/checkout@v6
|
|
67
|
+
with:
|
|
68
|
+
fetch-depth: 0
|
|
69
|
+
- uses: actions/setup-node@v6
|
|
70
|
+
with:
|
|
71
|
+
node-version: 24
|
|
72
|
+
- run: npx changelogithub --no-group
|
|
73
|
+
continue-on-error: true
|
|
74
|
+
env:
|
|
75
|
+
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
name: Test
|
|
2
|
+
permissions:
|
|
3
|
+
contents: read
|
|
4
|
+
|
|
5
|
+
on:
|
|
6
|
+
push:
|
|
7
|
+
branches-ignore:
|
|
8
|
+
- 'wip-*'
|
|
9
|
+
paths-ignore:
|
|
10
|
+
- 'docs/**'
|
|
11
|
+
- '*.md'
|
|
12
|
+
- '*.rst'
|
|
13
|
+
pull_request:
|
|
14
|
+
branches-ignore:
|
|
15
|
+
- 'wip-*'
|
|
16
|
+
paths-ignore:
|
|
17
|
+
- 'docs/**'
|
|
18
|
+
- '*.md'
|
|
19
|
+
- '*.rst'
|
|
20
|
+
workflow_dispatch:
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
jobs:
|
|
24
|
+
lint:
|
|
25
|
+
runs-on: ubuntu-latest
|
|
26
|
+
steps:
|
|
27
|
+
- uses: actions/checkout@v6
|
|
28
|
+
- uses: actions/setup-python@v6
|
|
29
|
+
with:
|
|
30
|
+
python-version: "3.13"
|
|
31
|
+
|
|
32
|
+
- name: Install dependencies
|
|
33
|
+
run: python -m pip install --upgrade uv
|
|
34
|
+
|
|
35
|
+
- name: ruff lint
|
|
36
|
+
run: uv run --group lint ruff check .
|
|
37
|
+
|
|
38
|
+
- name: mypy lint
|
|
39
|
+
run: uv run --group lint mypy
|
|
40
|
+
|
|
41
|
+
test:
|
|
42
|
+
needs: lint
|
|
43
|
+
runs-on: ubuntu-latest
|
|
44
|
+
permissions:
|
|
45
|
+
contents: read
|
|
46
|
+
code-quality: write
|
|
47
|
+
pull-requests: read
|
|
48
|
+
|
|
49
|
+
strategy:
|
|
50
|
+
fail-fast: false
|
|
51
|
+
max-parallel: 3
|
|
52
|
+
matrix:
|
|
53
|
+
python-version:
|
|
54
|
+
- "3.10"
|
|
55
|
+
- "3.11"
|
|
56
|
+
- "3.12"
|
|
57
|
+
- "3.13"
|
|
58
|
+
- "3.14"
|
|
59
|
+
|
|
60
|
+
steps:
|
|
61
|
+
- uses: actions/checkout@v6
|
|
62
|
+
with:
|
|
63
|
+
ref: ${{ github.event.pull_request.head.sha || github.sha }}
|
|
64
|
+
|
|
65
|
+
- name: Set up Python ${{ matrix.python-version }}
|
|
66
|
+
uses: actions/setup-python@v6
|
|
67
|
+
with:
|
|
68
|
+
python-version: ${{ matrix.python-version }}
|
|
69
|
+
|
|
70
|
+
- name: Install dependencies
|
|
71
|
+
run: python -m pip install --upgrade uv
|
|
72
|
+
|
|
73
|
+
- name: Report coverage
|
|
74
|
+
run: uv run --group test pytest --cov=wenmode --cov-report=xml
|
|
75
|
+
|
|
76
|
+
- name: Upload coverage to GitHub
|
|
77
|
+
if: ${{ matrix.python-version == '3.14' }}
|
|
78
|
+
uses: actions/upload-code-coverage@v1
|
|
79
|
+
with:
|
|
80
|
+
file: coverage.xml
|
|
81
|
+
language: Python
|
|
82
|
+
label: code-coverage/pytest
|
|
83
|
+
fail-on-error: false
|
wenmode-0.1.0/.gitignore
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
3.12
|
wenmode-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
BSD 3-Clause License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026, Hsiaoming Yang
|
|
4
|
+
|
|
5
|
+
Redistribution and use in source and binary forms, with or without
|
|
6
|
+
modification, are permitted provided that the following conditions are met:
|
|
7
|
+
|
|
8
|
+
1. Redistributions of source code must retain the above copyright notice, this
|
|
9
|
+
list of conditions and the following disclaimer.
|
|
10
|
+
|
|
11
|
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
12
|
+
this list of conditions and the following disclaimer in the documentation
|
|
13
|
+
and/or other materials provided with the distribution.
|
|
14
|
+
|
|
15
|
+
3. Neither the name of the copyright holder nor the names of its
|
|
16
|
+
contributors may be used to endorse or promote products derived from
|
|
17
|
+
this software without specific prior written permission.
|
|
18
|
+
|
|
19
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
20
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
21
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
22
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
23
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
24
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
25
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
26
|
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
27
|
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
28
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
wenmode-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: wenmode
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A fast, composable Markdown parser and renderer toolkit.
|
|
5
|
+
Project-URL: Homepage, https://github.com/lepture/wenmode
|
|
6
|
+
Project-URL: Repository, https://github.com/lepture/wenmode
|
|
7
|
+
Project-URL: Issues, https://github.com/lepture/wenmode/issues
|
|
8
|
+
Project-URL: Documentation, https://wenmode.lepture.com
|
|
9
|
+
Author-email: Hsiaoming Yang <me@lepture.com>
|
|
10
|
+
License-Expression: BSD-3-Clause
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Keywords: commonmark,markdown,mdast,parser,renderer
|
|
13
|
+
Classifier: Development Status :: 4 - Beta
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: License :: OSI Approved :: BSD License
|
|
16
|
+
Classifier: Operating System :: OS Independent
|
|
17
|
+
Classifier: Programming Language :: Python
|
|
18
|
+
Classifier: Programming Language :: Python :: 3
|
|
19
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
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 :: Software Development :: Libraries :: Python Modules
|
|
26
|
+
Classifier: Topic :: Text Processing :: Markup
|
|
27
|
+
Classifier: Topic :: Text Processing :: Markup :: Markdown
|
|
28
|
+
Requires-Python: >=3.10
|
|
29
|
+
Description-Content-Type: text/markdown
|
|
30
|
+
|
|
31
|
+
# Wenmode
|
|
32
|
+
|
|
33
|
+
Wenmode is a composable Markdown toolkit for Python by the same author as
|
|
34
|
+
[Mistune](https://mistune.lepture.com/). It is a rewrite informed by Mistune's
|
|
35
|
+
design, with a stronger focus on explicit rule composition, mdast-compatible AST
|
|
36
|
+
output, extension state, and pluggable rendering.
|
|
37
|
+
|
|
38
|
+
The top-level `Wenmode` class combines a parser and a renderer. By default it
|
|
39
|
+
parses CommonMark-style Markdown and renders HTML.
|
|
40
|
+
|
|
41
|
+
Documentation: <https://wenmode.lepture.com>
|
|
42
|
+
|
|
43
|
+
## Installation
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
pip install wenmode
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## Quick start
|
|
50
|
+
|
|
51
|
+
```python
|
|
52
|
+
from wenmode import Wenmode
|
|
53
|
+
|
|
54
|
+
wenmode = Wenmode()
|
|
55
|
+
|
|
56
|
+
text = '''
|
|
57
|
+
# Hello
|
|
58
|
+
|
|
59
|
+
This is **wenmode**.
|
|
60
|
+
'''
|
|
61
|
+
expected = '''
|
|
62
|
+
<h1>Hello</h1>
|
|
63
|
+
<p>This is <strong>wenmode</strong>.</p>
|
|
64
|
+
'''
|
|
65
|
+
|
|
66
|
+
html = wenmode.render(text)
|
|
67
|
+
assert html == expected.lstrip()
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
Use `parse()` when you need the mdast-compatible syntax tree:
|
|
71
|
+
|
|
72
|
+
```python
|
|
73
|
+
from wenmode import Wenmode
|
|
74
|
+
|
|
75
|
+
wenmode = Wenmode()
|
|
76
|
+
text = 'A [link](https://example.com).'
|
|
77
|
+
|
|
78
|
+
tree = wenmode.parse(text)
|
|
79
|
+
ast = tree.to_ast()
|
|
80
|
+
|
|
81
|
+
assert ast == {
|
|
82
|
+
'type': 'root',
|
|
83
|
+
'children': [
|
|
84
|
+
{
|
|
85
|
+
'type': 'paragraph',
|
|
86
|
+
'children': [
|
|
87
|
+
{'type': 'text', 'value': 'A '},
|
|
88
|
+
{
|
|
89
|
+
'type': 'link',
|
|
90
|
+
'children': [{'type': 'text', 'value': 'link'}],
|
|
91
|
+
'url': 'https://example.com',
|
|
92
|
+
},
|
|
93
|
+
{'type': 'text', 'value': '.'},
|
|
94
|
+
],
|
|
95
|
+
}
|
|
96
|
+
],
|
|
97
|
+
}
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
Pass a different renderer when you want another output format:
|
|
101
|
+
|
|
102
|
+
```python
|
|
103
|
+
from wenmode import RSTRenderer, Wenmode
|
|
104
|
+
|
|
105
|
+
wenmode = Wenmode(renderer=RSTRenderer())
|
|
106
|
+
|
|
107
|
+
text = '# Hello'
|
|
108
|
+
expected = '''
|
|
109
|
+
Hello
|
|
110
|
+
=====
|
|
111
|
+
'''
|
|
112
|
+
|
|
113
|
+
rst = wenmode.render(text)
|
|
114
|
+
assert rst == expected.lstrip()
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
## Rules
|
|
118
|
+
|
|
119
|
+
Rules are opt-in and composable. `Wenmode()` uses the `commonmark` preset by
|
|
120
|
+
default; pass an explicit rule list when you want a custom Markdown dialect.
|
|
121
|
+
|
|
122
|
+
```python
|
|
123
|
+
from wenmode import Wenmode
|
|
124
|
+
from wenmode.rules import AtxHeading, FencedCode, Image, InlineCode, Link
|
|
125
|
+
|
|
126
|
+
wenmode = Wenmode([AtxHeading, FencedCode, Link, Image, InlineCode])
|
|
127
|
+
text = '''
|
|
128
|
+
# h1
|
|
129
|
+
|
|
130
|
+
hi `code` **strong**
|
|
131
|
+
'''
|
|
132
|
+
expected = '''
|
|
133
|
+
<h1>h1</h1>
|
|
134
|
+
<p>hi <code>code</code> **strong**</p>
|
|
135
|
+
'''
|
|
136
|
+
|
|
137
|
+
assert wenmode.render(text) == expected.lstrip()
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
Because `Emphasis` is not enabled above, `**strong**` stays as text.
|
|
141
|
+
|
|
142
|
+
Use `Parser` directly when you only need an AST and want to choose rendering
|
|
143
|
+
separately:
|
|
144
|
+
|
|
145
|
+
```python
|
|
146
|
+
from wenmode import HTMLRenderer, Parser
|
|
147
|
+
from wenmode.presets import commonmark
|
|
148
|
+
|
|
149
|
+
parser = Parser(commonmark)
|
|
150
|
+
text = '# Hello'
|
|
151
|
+
|
|
152
|
+
tree = parser.parse(text)
|
|
153
|
+
|
|
154
|
+
html = HTMLRenderer().render(tree)
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
Use the `github` preset for GitHub-flavored Markdown features such as tables,
|
|
158
|
+
task lists, strikethrough, extended autolinks, and footnotes:
|
|
159
|
+
|
|
160
|
+
```python
|
|
161
|
+
from wenmode import Wenmode
|
|
162
|
+
from wenmode.presets import github
|
|
163
|
+
|
|
164
|
+
wenmode = Wenmode(github)
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
## Benchmark
|
|
168
|
+
|
|
169
|
+
Wenmode is designed so enabling more rules adds limited dispatch overhead. The
|
|
170
|
+
benchmark script compares Markdown-to-HTML throughput across Wenmode and the
|
|
171
|
+
libraries covered by the migration guides:
|
|
172
|
+
|
|
173
|
+
```bash
|
|
174
|
+
uv run --group benchmark python scripts/benchmark.py --case all
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
`wenmode-core` uses CommonMark-style rules plus pipe tables. The other parsers
|
|
178
|
+
are configured to match that feature set as closely as their APIs allow:
|
|
179
|
+
CommonMark-style parsing plus pipe table support. `commonmark.py` is included
|
|
180
|
+
as a CommonMark-only parser because it does not support pipe tables.
|
|
181
|
+
|
|
182
|
+
`wenmode-all` uses the `github` preset plus Wenmode's remaining built-in rules,
|
|
183
|
+
including directives, math, definition lists, abbreviations, spoilers, ruby
|
|
184
|
+
text, and additional inline formatting. These extra rules are mostly unused by
|
|
185
|
+
the benchmark corpora, so `wenmode-all` measures the overhead of carrying many
|
|
186
|
+
additional rules rather than a syntax-equivalent comparison with the other
|
|
187
|
+
parsers.
|
|
188
|
+
|
|
189
|
+
All benchmark targets are created once before warmup and timed iterations, then
|
|
190
|
+
reused for every render call. Python-Markdown is the exception only in that the
|
|
191
|
+
same `Markdown` instance is reset before each conversion, matching its reusable
|
|
192
|
+
API shape. Marko uses `marko.ext.gfm.gfm`, which is a reusable `Markdown`
|
|
193
|
+
instance rather than a newly created converter per iteration.
|
|
194
|
+
|
|
195
|
+
The rule sets are intentionally close, not identical. `wenmode-core` uses
|
|
196
|
+
CommonMark-style rules plus pipe tables with raw HTML passthrough and URL
|
|
197
|
+
sanitization disabled for parity with the other HTML renderers. Mistune,
|
|
198
|
+
Python-Markdown, markdown-it-py, and markdown2 enable their table support.
|
|
199
|
+
Marko uses its GFM helper, which is broader than just tables. `commonmark.py`
|
|
200
|
+
is included as a CommonMark-only baseline because it has no pipe table support.
|
|
201
|
+
`wenmode-all` is deliberately broader than the other targets.
|
|
202
|
+
|
|
203
|
+
Versions used in these snapshots:
|
|
204
|
+
|
|
205
|
+
| Library | Version |
|
|
206
|
+
| --- | ---: |
|
|
207
|
+
| wenmode | 0.1.0 |
|
|
208
|
+
| mistune | 3.2.1 |
|
|
209
|
+
| python-markdown | 3.10.2 |
|
|
210
|
+
| markdown-it-py | 4.2.0 |
|
|
211
|
+
| markdown2 | 2.5.5 |
|
|
212
|
+
| marko | 2.2.3 |
|
|
213
|
+
| commonmark.py | 0.9.2 |
|
|
214
|
+
|
|
215
|
+
Mean time from one local `--case all` run:
|
|
216
|
+
|
|
217
|
+
| Case | Bytes | Library | Mean | MB/s | vs core |
|
|
218
|
+
| --- | ---: | --- | ---: | ---: | ---: |
|
|
219
|
+
| docs | 53,792 | wenmode-core | 4.84ms | 11.58 | 1.00x |
|
|
220
|
+
| docs | 53,792 | wenmode-all | 5.89ms | 9.59 | 0.82x |
|
|
221
|
+
| docs | 53,792 | mistune | 8.64ms | 6.89 | 0.56x |
|
|
222
|
+
| docs | 53,792 | markdown-it-py | 13.27ms | 4.19 | 0.36x |
|
|
223
|
+
| docs | 53,792 | commonmark.py | 20.72ms | 2.67 | 0.23x |
|
|
224
|
+
| docs | 53,792 | python-markdown | 28.98ms | 1.88 | 0.17x |
|
|
225
|
+
| docs | 53,792 | markdown2 | 43.34ms | 1.25 | 0.11x |
|
|
226
|
+
| docs | 53,792 | marko | 49.65ms | 1.11 | 0.10x |
|
|
227
|
+
| rust-book | 1,225,464 | wenmode-core | 138.87ms | 9.07 | 1.00x |
|
|
228
|
+
| rust-book | 1,225,464 | wenmode-all | 156.48ms | 8.09 | 0.89x |
|
|
229
|
+
| rust-book | 1,225,464 | mistune | 214.92ms | 6.53 | 0.65x |
|
|
230
|
+
| rust-book | 1,225,464 | markdown-it-py | 360.20ms | 3.49 | 0.39x |
|
|
231
|
+
| rust-book | 1,225,464 | python-markdown | 624.73ms | 2.00 | 0.22x |
|
|
232
|
+
| rust-book | 1,225,464 | marko | 1.178s | 1.04 | 0.12x |
|
|
233
|
+
| rust-book | 1,225,464 | markdown2 | 4.082s | 0.30 | 0.03x |
|
|
234
|
+
| rust-book | 1,225,464 | commonmark.py | 9.619s | 0.14 | 0.01x |
|
|
235
|
+
| progit | 502,090 | wenmode-core | 26.61ms | 19.24 | 1.00x |
|
|
236
|
+
| progit | 502,090 | wenmode-all | 35.31ms | 16.36 | 0.75x |
|
|
237
|
+
| progit | 502,090 | mistune | 44.01ms | 12.40 | 0.60x |
|
|
238
|
+
| progit | 502,090 | markdown-it-py | 76.29ms | 7.15 | 0.35x |
|
|
239
|
+
| progit | 502,090 | python-markdown | 149.01ms | 3.47 | 0.18x |
|
|
240
|
+
| progit | 502,090 | commonmark.py | 347.45ms | 1.49 | 0.08x |
|
|
241
|
+
| progit | 502,090 | marko | 357.08ms | 1.43 | 0.07x |
|
|
242
|
+
| progit | 502,090 | markdown2 | 1.425s | 0.35 | 0.02x |
|
|
243
|
+
|
|
244
|
+
In this run, `wenmode-all` remains faster than the other parsers even after
|
|
245
|
+
loading many extra rules that the benchmark inputs mostly do not use.
|
|
246
|
+
|
|
247
|
+
## Streaming
|
|
248
|
+
|
|
249
|
+
Use the `streaming` preset when you want to render HTML chunks without waiting
|
|
250
|
+
for the entire document to be parsed and rendered:
|
|
251
|
+
|
|
252
|
+
```python
|
|
253
|
+
from wenmode import Wenmode
|
|
254
|
+
from wenmode.presets import streaming
|
|
255
|
+
|
|
256
|
+
wenmode = Wenmode(streaming)
|
|
257
|
+
|
|
258
|
+
text = '''
|
|
259
|
+
# Hello
|
|
260
|
+
|
|
261
|
+
A [link](/url).
|
|
262
|
+
'''
|
|
263
|
+
|
|
264
|
+
for chunk in wenmode.stream(text):
|
|
265
|
+
send(chunk)
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
The returned iterator can be passed to streaming responses in frameworks such
|
|
269
|
+
as Django, Flask, and FastAPI.
|