Skip to content

Commit

Permalink
Merge branch 'release/3.9.3'
Browse files Browse the repository at this point in the history
  • Loading branch information
mikitex70 committed Feb 10, 2024
2 parents 17d348b + 1f35852 commit 0a8f037
Showing 7 changed files with 69 additions and 41 deletions.
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@
# Changelog


## 3.9.2 (2024-02-10)

### Other

* Chore: add source tarball with requirements.txt at the root, for publishing to https://pypi.org/project/plantuml-markdown/#files. [Nick Boldt]

* Update README.md. [Mark Moretto]

Aiming to clear-up some of the installation instructions.

* Update plantuml_markdown.py. [Mark Moretto]

Updated `https://pythonhosted.org/..` URLs within file to `https://python-markdown.github.io/...`


## 3.9.2 (2023-06-22)

### Fix
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -14,6 +14,6 @@ RUN apk update && \
font-noto-cjk \
wget && \
rm -rf /var/cache/apk/* && \
sed "s/Markdown/Markdown==$MARKDOWN_VER/" requirements.txt > /tmp/requirements.txt && \
sed "s/Markdown.*/Markdown==$MARKDOWN_VER/" requirements.txt > /tmp/requirements.txt && \
cat test-requirements.txt >> /tmp/requirements.txt && \
pip install -r /tmp/requirements.txt
51 changes: 26 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
@@ -82,34 +82,35 @@ GitLab/GitHub block syntax.
Installation
------------

To use the plugin with [Python-Markdown][] you have these choices:

* with `pip`, do a simple `pip install plantuml-markdown`, and the plugin should be ready to be used
* on Windows you can use [Chocolatey](https://chocolatey.org/), a package manager for Windows: do a
`choco install plantuml` and you are ready to work (this command will install all dependencies, Java and Graphviz
included, see https://chocolatey.org/packages/plantuml for details)
* copy the file `plantuml-markdown.py` in the `extensions` folder of [Python-Markdown][]. For example, for Python 2.7
you must do:

```console
$ sudo cp plantuml-markdown.py /usr/lib/python27/site-packages/markdown/extensions/
```
* copy the file somewhere in your home. A good choice may be the `user-site` path, for example (`bash` syntax):
To use the plugin with [Python-Markdown][] you have the following options. Please note that before using the package, you will need to configure which [PlantUML] binary to use: a local binary, or a remote server (see below for further details).

1. [Linux] Use Python's `pip` package manager and run the following command. After running, the package should be ready to use.
```console
$ pip install plantuml-markdown
```
1. [Windows] You can use [Chocolatey](https://chocolatey.org/), a package manager for Windows.
From an elevated terminal, run the following command:
```console
>>> choco install plantuml
```
(__Note__: This command will install all dependencies, Java and Graphviz included, see [https://chocolatey.org/packages/plantuml](https://chocolatey.org/packages/plantuml) for details.)
1. Copy the file `./plantuml-markdown.py` into the `extensions` folder of [Python-Markdown][]. For example, for Python 2.7, you must do:
```console
$ sudo cp plantuml-markdown.py /usr/lib/python27/site-packages/markdown/extensions/
```
1. Copy the file somewhere in your home. A good choice may be the `user-site` path. For example, on Linux using `bash`:
```console
$ export INSTALLPATH="`python -m site --user-site`/plantuml-markdown"
$ mkdir -p "$INSTALLPATH"
$ cp plantuml-markdown.py "$INSTALLPATH/mdx_plantuml-markdown.py"
$ export PYTHONPATH="${PYTHONPATH}:${INSTALLPATH}"
```
You must export `PYTHONPATH` before running `markdown_py`, or you can put the definition in a bash config file (eg - `~/.bashrc`), then restart the terminal or use `source ~/.bashrc` or `. ~/.bashrc` to update the variable without closing the terminal.

After the package is installed, you can use this plugin by activating it in the `markdown_py` command. For example:
```console
$ export INSTALLPATH="`python -m site --user-site`/plantuml-markdown"
$ mkdir -p "$INSTALLPATH"
$ cp plantuml-markdown.py "$INSTALLPATH/mdx_plantuml-markdown.py"
$ export PYTHONPATH="$INSTALLPATH"
$ markdown_py -x plantuml_markdown mydoc.md > out.html
```

You must export `PYTHONPATH` before running `markdown_py`, or you can put the definition in `~/.bashrc`.

After installed, you can use this plugin by activating it in the `markdown_py` command. For example:

markdown_py -x plantuml_markdown mydoc.md > out.html

But before to use it, you need to configure which [PlantUML] binary to use: a local binary, or a remote server.

### Using a local PlantUML binary

10 changes: 5 additions & 5 deletions plantuml_markdown.py
Original file line number Diff line number Diff line change
@@ -48,8 +48,8 @@
the ebuild and the `files` subfolder or you can add the `zugaina` repository with [layman][]
(recommended).
[Python-Markdown]: http://pythonhosted.org/Markdown/
[PlantUML]: http://plantuml.sourceforge.net/
[Python-Markdown]: https://python-markdown.github.io
[PlantUML]: https://plantuml.com
[Graphviz]: http://www.graphviz.org
[Gentoo]: http://www.gentoo.org
[layman]: http://wiki.gentoo.org/wiki/Layman
@@ -82,7 +82,7 @@
b64_to_plantuml = bytes.maketrans(base64_alphabet.encode('utf-8'), plantuml_alphabet.encode('utf-8'))


# For details see https://pythonhosted.org/Markdown/extensions/api.html#blockparser
# For details see https://python-markdown.github.io/extensions/api/#blockparser
class PlantUMLPreprocessor(markdown.preprocessors.Preprocessor):
# Regular expression inspired from fenced_code
BLOCK_RE = re.compile(r'''
@@ -618,9 +618,9 @@ def _load_file(self, inc_file_abs: str):
raise exc


# For details see https://pythonhosted.org/Markdown/extensions/api.html#extendmarkdown
# For details see https://python-markdown.github.io/extensions/api/#extendmarkdown
class PlantUMLMarkdownExtension(markdown.Extension):
# For details see https://pythonhosted.org/Markdown/extensions/api.html#configsettings
# For details see https://python-markdown.github.io/extensions/api/#configsettings
def __init__(self, **kwargs):
self.config = {
'classes': ["uml", "Space separated list of classes for the generated image. Defaults to 'uml'."],
10 changes: 9 additions & 1 deletion release.sh
Original file line number Diff line number Diff line change
@@ -6,7 +6,15 @@
# Build package for Python 3
. .env3*/bin/activate
pip install setuptools twine wheel
python setup.py bdist_wheel

python setup.py bdist_wheel sdist --formats tar
pushd dist >/dev/null || exit
distrib=$(ls *.tar); distrib=${distrib/.tar/}
mkdir -p ${distrib}
cp ../requirements.txt ${distrib}
tar rvf ${distrib}.tar ${distrib}/requirements.txt && gzip ${distrib}.tar
rm -fr ${distrib}
popd >/dev/null || exit

# Check that packages are ok
twine check dist/*
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
@@ -15,9 +15,9 @@

setuptools.setup(
name="plantuml-markdown",
version="3.9.2",
version="3.9.3",
author="Michele Tessaro",
author_email="michele.tessaro@email.it",
author_email="michele.tessaro[email protected]",
description="A PlantUML plugin for Markdown",
long_description=long_description,
long_description_content_type="text/markdown",
18 changes: 11 additions & 7 deletions test/test_plantuml.py
Original file line number Diff line number Diff line change
@@ -117,19 +117,19 @@ def sort_attributes(groups):

def test_priority_after_snippets(self):
"""
Verifies the normal priority of the plantuml_markdown plugin: it must be execute before the fenced code
Verifies the normal priority of the plantuml_markdown plugin: it must be executed before the fenced code
but after the snippets plugin.
"""
self._test_snippets(30, 'A --> B\n')

def test_priority_before_snippets(self):
"""
Verifies changing plugin priority: in must be execute even before the snippets plugin.
Verifies changing plugin priority: in must be executed even before the snippets plugin.
:return:
"""
# raising priority, so the plantuml plugin is executed before the snippet plugin
# expecting that the snippet is not inserted in the plantuml source code
self._test_snippets(40, '--8<-- "'+os.path.join(tempfile.gettempdir(), 'test-defs.puml')+'"\n')
self._test_snippets(40, '--8<-- "test-defs.puml"\n')

def _test_snippets(self, priority, expected):
"""
@@ -139,26 +139,30 @@ def _test_snippets(self, priority, expected):
:param priority: execution priority of the plantuml_markdown plugin
:param expected: expected generated plantuml source code
"""
tempdir = tempfile.gettempdir()
self.md = markdown.Markdown(extensions=['markdown.extensions.fenced_code',
'pymdownx.snippets', 'plantuml_markdown'],
extension_configs={
'plantuml_markdown': {
'priority': priority
},
'pymdownx.snippets': {
'base_path': [tempdir] # override default include path
}
})
tempdir = tempfile.gettempdir()
defs_file = os.path.join(tempdir, 'test-defs.puml')
defs_filename = 'test-defs.puml'
defs_file = os.path.join(tempdir, defs_filename)
# preparing a file to include
with open(defs_file, 'w') as f:
f.write('A --> B')

from test.markdown_builder import MarkdownBuilder
# from test.markdown_builder import MarkdownBuilder
from plantuml_markdown import PlantUMLPreprocessor

# mocking a method to capture the generated PlantUML source code
with mock.patch.object(PlantUMLPreprocessor, '_render_diagram',
return_value=('testing'.encode('utf8'), None)) as mocked_plugin:
text = self.text_builder.diagram("--8<-- \"" + defs_file + "\"").build()
text = self.text_builder.diagram("--8<-- \""+defs_filename+"\"").build()
self.md.convert(text)
mocked_plugin.assert_called_with(expected, 'map')

0 comments on commit 0a8f037

Please sign in to comment.