pymdownx-inline-blocks 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.
- pymdownx_inline_blocks-0.1.0/.github/workflows/publish-to-pypi.yml +36 -0
- pymdownx_inline_blocks-0.1.0/.gitignore +165 -0
- pymdownx_inline_blocks-0.1.0/PKG-INFO +10 -0
- pymdownx_inline_blocks-0.1.0/README.md +53 -0
- pymdownx_inline_blocks-0.1.0/inline_blocks/__init__.py +51 -0
- pymdownx_inline_blocks-0.1.0/pyproject.toml +30 -0
- pymdownx_inline_blocks-0.1.0/tests/test_inline-blocks.py +82 -0
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
name: Publish Python 🐍 distributions 📦 to PyPI
|
|
2
|
+
on:
|
|
3
|
+
push:
|
|
4
|
+
tags:
|
|
5
|
+
- "*"
|
|
6
|
+
jobs:
|
|
7
|
+
build-n-publish:
|
|
8
|
+
runs-on: ubuntu-latest
|
|
9
|
+
name: Build and publish Python 🐍 distributions 📦 to PyPI
|
|
10
|
+
environment:
|
|
11
|
+
name: pypi
|
|
12
|
+
url: https://pypi.org/p/pygments-shell-console
|
|
13
|
+
permissions:
|
|
14
|
+
id-token: write # IMPORTANT: this permission is mandatory for trusted publishing
|
|
15
|
+
steps:
|
|
16
|
+
- name: Set up Python 3.10
|
|
17
|
+
uses: actions/checkout@master
|
|
18
|
+
- name: Set up Python 3.10
|
|
19
|
+
uses: actions/setup-python@v1
|
|
20
|
+
with:
|
|
21
|
+
python-version: "3.10"
|
|
22
|
+
- name: Install pypa/build
|
|
23
|
+
run: >-
|
|
24
|
+
python -m
|
|
25
|
+
pip install
|
|
26
|
+
build
|
|
27
|
+
--user
|
|
28
|
+
- name: Build a binary wheel and a source tarball
|
|
29
|
+
run: >-
|
|
30
|
+
python -m
|
|
31
|
+
build
|
|
32
|
+
--sdist
|
|
33
|
+
--wheel
|
|
34
|
+
--outdir dist/
|
|
35
|
+
- name: Publish package distributions to PyPI
|
|
36
|
+
uses: pypa/gh-action-pypi-publish@release/v1
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
# Tests generated site
|
|
2
|
+
tests/site/
|
|
3
|
+
|
|
4
|
+
# Byte-compiled / optimized / DLL files
|
|
5
|
+
__pycache__/
|
|
6
|
+
*.py[cod]
|
|
7
|
+
*$py.class
|
|
8
|
+
|
|
9
|
+
# C extensions
|
|
10
|
+
*.so
|
|
11
|
+
|
|
12
|
+
# Distribution / packaging
|
|
13
|
+
.Python
|
|
14
|
+
build/
|
|
15
|
+
develop-eggs/
|
|
16
|
+
dist/
|
|
17
|
+
downloads/
|
|
18
|
+
eggs/
|
|
19
|
+
.eggs/
|
|
20
|
+
lib/
|
|
21
|
+
lib64/
|
|
22
|
+
parts/
|
|
23
|
+
sdist/
|
|
24
|
+
var/
|
|
25
|
+
wheels/
|
|
26
|
+
share/python-wheels/
|
|
27
|
+
*.egg-info/
|
|
28
|
+
.installed.cfg
|
|
29
|
+
*.egg
|
|
30
|
+
MANIFEST
|
|
31
|
+
|
|
32
|
+
# PyInstaller
|
|
33
|
+
# Usually these files are written by a python script from a template
|
|
34
|
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
|
35
|
+
*.manifest
|
|
36
|
+
*.spec
|
|
37
|
+
|
|
38
|
+
# Installer logs
|
|
39
|
+
pip-log.txt
|
|
40
|
+
pip-delete-this-directory.txt
|
|
41
|
+
|
|
42
|
+
# Unit test / coverage reports
|
|
43
|
+
htmlcov/
|
|
44
|
+
.tox/
|
|
45
|
+
.nox/
|
|
46
|
+
.coverage
|
|
47
|
+
.coverage.*
|
|
48
|
+
.cache
|
|
49
|
+
nosetests.xml
|
|
50
|
+
coverage.xml
|
|
51
|
+
*.cover
|
|
52
|
+
*.py,cover
|
|
53
|
+
.hypothesis/
|
|
54
|
+
.pytest_cache/
|
|
55
|
+
cover/
|
|
56
|
+
|
|
57
|
+
# Translations
|
|
58
|
+
*.mo
|
|
59
|
+
*.pot
|
|
60
|
+
|
|
61
|
+
# Django stuff:
|
|
62
|
+
*.log
|
|
63
|
+
local_settings.py
|
|
64
|
+
db.sqlite3
|
|
65
|
+
db.sqlite3-journal
|
|
66
|
+
|
|
67
|
+
# Flask stuff:
|
|
68
|
+
instance/
|
|
69
|
+
.webassets-cache
|
|
70
|
+
|
|
71
|
+
# Scrapy stuff:
|
|
72
|
+
.scrapy
|
|
73
|
+
|
|
74
|
+
# Sphinx documentation
|
|
75
|
+
docs/_build/
|
|
76
|
+
|
|
77
|
+
# PyBuilder
|
|
78
|
+
.pybuilder/
|
|
79
|
+
target/
|
|
80
|
+
|
|
81
|
+
# Jupyter Notebook
|
|
82
|
+
.ipynb_checkpoints
|
|
83
|
+
|
|
84
|
+
# IPython
|
|
85
|
+
profile_default/
|
|
86
|
+
ipython_config.py
|
|
87
|
+
|
|
88
|
+
# pyenv
|
|
89
|
+
# For a library or package, you might want to ignore these files since the code is
|
|
90
|
+
# intended to run in multiple environments; otherwise, check them in:
|
|
91
|
+
# .python-version
|
|
92
|
+
|
|
93
|
+
# pipenv
|
|
94
|
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
|
95
|
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
|
96
|
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
|
97
|
+
# install all needed dependencies.
|
|
98
|
+
#Pipfile.lock
|
|
99
|
+
|
|
100
|
+
# poetry
|
|
101
|
+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
|
102
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
103
|
+
# commonly ignored for libraries.
|
|
104
|
+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
|
105
|
+
#poetry.lock
|
|
106
|
+
|
|
107
|
+
# pdm
|
|
108
|
+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
|
109
|
+
#pdm.lock
|
|
110
|
+
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
|
|
111
|
+
# in version control.
|
|
112
|
+
# https://pdm.fming.dev/latest/usage/project/#working-with-version-control
|
|
113
|
+
.pdm.toml
|
|
114
|
+
.pdm-python
|
|
115
|
+
.pdm-build/
|
|
116
|
+
|
|
117
|
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
|
118
|
+
__pypackages__/
|
|
119
|
+
|
|
120
|
+
# Celery stuff
|
|
121
|
+
celerybeat-schedule
|
|
122
|
+
celerybeat.pid
|
|
123
|
+
|
|
124
|
+
# SageMath parsed files
|
|
125
|
+
*.sage.py
|
|
126
|
+
|
|
127
|
+
# Environments
|
|
128
|
+
.env
|
|
129
|
+
.venv
|
|
130
|
+
env/
|
|
131
|
+
venv/
|
|
132
|
+
ENV/
|
|
133
|
+
env.bak/
|
|
134
|
+
venv.bak/
|
|
135
|
+
|
|
136
|
+
# Spyder project settings
|
|
137
|
+
.spyderproject
|
|
138
|
+
.spyproject
|
|
139
|
+
|
|
140
|
+
# Rope project settings
|
|
141
|
+
.ropeproject
|
|
142
|
+
|
|
143
|
+
# mkdocs documentation
|
|
144
|
+
/site
|
|
145
|
+
|
|
146
|
+
# mypy
|
|
147
|
+
.mypy_cache/
|
|
148
|
+
.dmypy.json
|
|
149
|
+
dmypy.json
|
|
150
|
+
|
|
151
|
+
# Pyre type checker
|
|
152
|
+
.pyre/
|
|
153
|
+
|
|
154
|
+
# pytype static type analyzer
|
|
155
|
+
.pytype/
|
|
156
|
+
|
|
157
|
+
# Cython debug symbols
|
|
158
|
+
cython_debug/
|
|
159
|
+
|
|
160
|
+
# PyCharm
|
|
161
|
+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
|
162
|
+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
|
163
|
+
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
|
164
|
+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
|
165
|
+
#.idea/
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: pymdownx-inline-blocks
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A Python Markdown extension to add inline block elements based on PyMdown Extensions.
|
|
5
|
+
Project-URL: Repository, https://github.com/joapuiib/pymdownx-inline-blocks
|
|
6
|
+
Author-email: Joan Puigcerver <joapuiib@gmail.com>
|
|
7
|
+
Maintainer-email: Joan Puigcerver <joapuiib@gmail.com>
|
|
8
|
+
Requires-Python: >=3.5
|
|
9
|
+
Requires-Dist: markdown>=3.4
|
|
10
|
+
Requires-Dist: pymdown-extensions>=10.0
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# PyMdown Inline Blocks
|
|
2
|
+
A Python Markdown extension to convert inline block shorthand syntax into [PyMdown Block Extension][pymdownx-block] format
|
|
3
|
+
|
|
4
|
+
[pymdownx-block]: https://facelessuser.github.io/pymdown-extensions/extensions/blocks/
|
|
5
|
+
|
|
6
|
+
- Convert single-line inline block syntax into fully-formed block syntax.
|
|
7
|
+
- Supports modifiers for advanced block formatting.
|
|
8
|
+
- Simple and lightweight; integrates easily with Markdown or MkDocs.
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
## Example
|
|
12
|
+
The following markdown inline block syntax:
|
|
13
|
+
|
|
14
|
+
```markdown
|
|
15
|
+

|
|
16
|
+
/// attribution: Unknown author
|
|
17
|
+
/// figure-caption | < ^1 : Caption
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Will be converted to the following PyMdown Block syntax:
|
|
21
|
+
|
|
22
|
+
```markdown
|
|
23
|
+

|
|
24
|
+
/// attribution
|
|
25
|
+
Unknown author
|
|
26
|
+
///
|
|
27
|
+
/// figure-caption | < ^1
|
|
28
|
+
Caption
|
|
29
|
+
///
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
## Installation
|
|
34
|
+
Install the extension via pip:
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
pip install pymdownx-inline-blocks
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
## Usage
|
|
42
|
+
To use the extension, add it to your Markdown or MkDocs configuration:
|
|
43
|
+
|
|
44
|
+
```python
|
|
45
|
+
md = markdown.Markdown(extensions=['inline_blocks'])
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
or, if using MkDocs, add it to your `mkdocs.yml`:
|
|
49
|
+
|
|
50
|
+
```yaml
|
|
51
|
+
markdown_extensions:
|
|
52
|
+
- inline_blocks
|
|
53
|
+
```
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import re
|
|
2
|
+
from markdown.extensions import Extension
|
|
3
|
+
from markdown.preprocessors import Preprocessor
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class InlineBlockPreprocessor(Preprocessor):
|
|
7
|
+
# Match forms:
|
|
8
|
+
# 1. /// block: content
|
|
9
|
+
# 2. /// block | modifiers : content
|
|
10
|
+
RE = re.compile(
|
|
11
|
+
r'^(?P<slashes>/{3,})\s*' # Capture 3+ leading slashes
|
|
12
|
+
r'(?P<block>[a-zA-Z0-9_-]+)' # Block type
|
|
13
|
+
r'(?:\s*\|\s*(?P<modifiers>[^:]+))?' # Optional modifiers
|
|
14
|
+
r'\s*:\s*'
|
|
15
|
+
r'(?P<content>.+)$' # Content
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
def run(self, lines):
|
|
19
|
+
new_lines = []
|
|
20
|
+
for line in lines:
|
|
21
|
+
m = self.RE.match(line)
|
|
22
|
+
if m:
|
|
23
|
+
slashes = m.group("slashes")
|
|
24
|
+
block_type = m.group("block")
|
|
25
|
+
modifiers = m.group("modifiers")
|
|
26
|
+
content = m.group("content").strip()
|
|
27
|
+
|
|
28
|
+
if modifiers:
|
|
29
|
+
new_lines.append(f"{slashes} {block_type} | {modifiers.strip()}")
|
|
30
|
+
else:
|
|
31
|
+
new_lines.append(f"{slashes} {block_type}")
|
|
32
|
+
new_lines.append(content)
|
|
33
|
+
new_lines.append(slashes)
|
|
34
|
+
else:
|
|
35
|
+
new_lines.append(line)
|
|
36
|
+
return new_lines
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
class InlineBlockExtension(Extension):
|
|
40
|
+
def extendMarkdown(self, md):
|
|
41
|
+
md.preprocessors.register(
|
|
42
|
+
InlineBlockPreprocessor(md),
|
|
43
|
+
"inline_blocks",
|
|
44
|
+
25,
|
|
45
|
+
)
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def makeExtension(*args, **kwargs):
|
|
49
|
+
"""Return extension."""
|
|
50
|
+
|
|
51
|
+
return InlineBlockExtension(*args, **kwargs)
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = 'pymdownx-inline-blocks'
|
|
7
|
+
description = "A Python Markdown extension to add inline block elements based on PyMdown Extensions."
|
|
8
|
+
# readme = {file = 'README.md', content-type='text/markdown'}
|
|
9
|
+
version = '0.1.0'
|
|
10
|
+
authors = [
|
|
11
|
+
{name = 'Joan Puigcerver', email = 'joapuiib@gmail.com'}
|
|
12
|
+
]
|
|
13
|
+
maintainers = [
|
|
14
|
+
{name = 'Joan Puigcerver', email = 'joapuiib@gmail.com'}
|
|
15
|
+
]
|
|
16
|
+
# license = {file = 'LICENSE'}
|
|
17
|
+
requires-python = '>=3.5'
|
|
18
|
+
dependencies = [
|
|
19
|
+
"markdown>=3.4",
|
|
20
|
+
"pymdown-extensions>=10.0"
|
|
21
|
+
]
|
|
22
|
+
|
|
23
|
+
[project.urls]
|
|
24
|
+
# 'Homepage' = ''
|
|
25
|
+
'Repository' = 'https://github.com/joapuiib/pymdownx-inline-blocks'
|
|
26
|
+
# 'Issue Tracker' = ''
|
|
27
|
+
|
|
28
|
+
[tool.hatch.build.targets.wheel]
|
|
29
|
+
packages = ["."]
|
|
30
|
+
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import markdown
|
|
2
|
+
import pytest
|
|
3
|
+
from inline_blocks import InlineBlockExtension
|
|
4
|
+
|
|
5
|
+
md = markdown.Markdown(extensions=['inline_blocks'])
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def render(text: str) -> str:
|
|
9
|
+
# Preprocessors run before conversion to HTML.
|
|
10
|
+
return "\n".join(md.preprocessors['inline_blocks'].run(text.splitlines()))
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def test_simple_attribution():
|
|
14
|
+
input_text = "/// attribution: Unknown author"
|
|
15
|
+
expected = "\n".join([
|
|
16
|
+
"/// attribution",
|
|
17
|
+
"Unknown author",
|
|
18
|
+
"///"
|
|
19
|
+
])
|
|
20
|
+
assert render(input_text) == expected
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def test_block_with_modifiers():
|
|
24
|
+
input_text = "/// figure-caption | < ^1 : Caption"
|
|
25
|
+
expected = "\n".join([
|
|
26
|
+
"/// figure-caption | < ^1",
|
|
27
|
+
"Caption",
|
|
28
|
+
"///"
|
|
29
|
+
])
|
|
30
|
+
assert render(input_text) == expected
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def test_multiple_blocks_in_sequence():
|
|
34
|
+
input_text = "\n".join([
|
|
35
|
+
"",
|
|
36
|
+
"/// attribution: Unknown author",
|
|
37
|
+
"/// figure-caption | < ^1 : Caption",
|
|
38
|
+
])
|
|
39
|
+
expected = "\n".join([
|
|
40
|
+
"",
|
|
41
|
+
"/// attribution",
|
|
42
|
+
"Unknown author",
|
|
43
|
+
"///",
|
|
44
|
+
"/// figure-caption | < ^1",
|
|
45
|
+
"Caption",
|
|
46
|
+
"///"
|
|
47
|
+
])
|
|
48
|
+
assert render(input_text) == expected
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def test_non_matching_lines_pass_through():
|
|
52
|
+
input_text = "This is a normal line."
|
|
53
|
+
expected = "This is a normal line."
|
|
54
|
+
assert render(input_text) == expected
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def test_trims_extra_spaces():
|
|
58
|
+
input_text = "/// attribution: Some author "
|
|
59
|
+
expected = "\n".join([
|
|
60
|
+
"/// attribution",
|
|
61
|
+
"Some author",
|
|
62
|
+
"///"
|
|
63
|
+
])
|
|
64
|
+
assert render(input_text) == expected
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
@pytest.mark.parametrize("line", [
|
|
68
|
+
"///not-valid", # missing space after ///
|
|
69
|
+
"/// block only", # no colon
|
|
70
|
+
"/// : no block", # no block type
|
|
71
|
+
])
|
|
72
|
+
def test_invalid_lines_remain_unchanged(line):
|
|
73
|
+
assert render(line) == line
|
|
74
|
+
|
|
75
|
+
def test_more_slashes():
|
|
76
|
+
input_text = "///// attribution: Extra slashes"
|
|
77
|
+
expected = "\n".join([
|
|
78
|
+
"///// attribution",
|
|
79
|
+
"Extra slashes",
|
|
80
|
+
"/////"
|
|
81
|
+
])
|
|
82
|
+
assert render(input_text) == expected
|