diff --git a/.build.yml b/.build.yml deleted file mode 100644 index df0e041..0000000 --- a/.build.yml +++ /dev/null @@ -1,50 +0,0 @@ -image: ubuntu/bionic - -packages: - - python - - python-pip - - python3 - - python3-pip - -secrets: - - d622464e-897f-41d3-ba3e-99999999999 - -sources: - - https://github.com/flywire/caption - -tasks: - - setup: | - pip3 install setuptools wheel twine virtualenv - - - tests: | - # Access the virtualenv binary - export PATH=$PATH:~/.local/bin - - # Begin tests - cd caption - - virtualenv -p python2 venv - . venv/bin/activate - pip install -r requirements.txt - python -m unittest discover - deactivate - rm -rf venv - - virtualenv -p python3 venv - . venv/bin/activate - pip install -r requirements.txt - python -m unittest discover - deactivate - rm -rf venv - - - deploy: | - cd caption - if [ "$(git tag --points-at HEAD)" == "$(grep version setup.py | sed 's/.*\"\(.*\)\",/v\1/')" ]; then - python3 setup.py sdist bdist_wheel --universal - python3 -m twine upload --config-file ~/.pypirc dist/* - fi - -triggers: - - action: email - condition: failure - to: "flywire " diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml new file mode 100644 index 0000000..3796a30 --- /dev/null +++ b/.github/workflows/publish.yaml @@ -0,0 +1,26 @@ +name: Upload Python Package + +on: + release: + types: [published] + +jobs: + deploy: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: '3.x' + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install setuptools wheel + - name: Build package + run: | + python setup.py sdist bdist_wheel --universal + - name: Publish package + uses: pypa/gh-action-pypi-publish@release/v1 + with: + password: ${{ secrets.PYPI_API_TOKEN }} diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml new file mode 100644 index 0000000..c8390bb --- /dev/null +++ b/.github/workflows/test.yaml @@ -0,0 +1,32 @@ +name: Python package + +on: [push] + +jobs: + build: + + runs-on: ubuntu-latest + strategy: + matrix: + python-version: ["2.7", "3.7", "3.8", "3.9", "3.10"] + + steps: + - uses: actions/checkout@v3 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v4 + with: + python-version: ${{ matrix.python-version }} + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install flake8 setuptools wheel twine pytest pytest-cov + pip install -r requirements.txt + - name: Lint with flake8 + run: | + # stop the build if there are Python syntax errors or undefined names + flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics + # exit-zero treats all errors as warnings. + flake8 . --count --exit-zero --max-complexity=10 --max-line-length=89 --statistics + - name: Test with pytest + run: | + pytest --cov diff --git a/.gitignore b/.gitignore index f49c7b7..5092483 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,5 @@ /build/ /dist/ /venv/ +/.idea/ +/.coverage diff --git a/README.md b/README.md index f69f6d9..ea9ae95 100644 --- a/README.md +++ b/README.md @@ -46,7 +46,7 @@ Python markdown extensions are incorporated into other applications. MkDocs users can add *caption* to their generator process by adding it to the `mkdocs.yml` `markdown_extensions` section: -```python +```yaml site_name: captionTest # theme: # name: material @@ -63,23 +63,34 @@ nav: Python will parse input to Markdown with *caption* as follows: ```python -import caption +import markdown +from caption import CaptionExtension # ... -outputString = markdown.markdown(inputString, extensions = [caption.captionExtension(numbering=false)]) +outputString = markdown.markdown( + input_string, extensions=[CaptionExtension(numbering=False)] +) ``` ### Options Currently supported options are listed below: -* `captionPrefix` (default: `"Figure"`): +* `figure_caption_prefix` (default: `"Figure"`): The text to show at the front of the caption. A final non-breaking space - is inserted between the content of `captionPrefix` and the actual figure + is inserted between the content of `table_caption_prefix` and the actual figure number. +* `table_caption_prefix` (default: `"Table"`): + + Same as `figure_caption_prefix`, but for tables. + +* `listing_caption_prefix` (default: `"Listing"`): + + Same as `figure_caption_prefix`, but for listings. + * `numbering` (default: `True`): Adds a caption number like "Figure 1:" in front of the caption. It's diff --git a/caption/__init__.py b/caption/__init__.py index e6b6a97..36d352c 100644 --- a/caption/__init__.py +++ b/caption/__init__.py @@ -3,4 +3,7 @@ # Copyright (c) 2020 flywire # # SPDX-License-Identifier: GPL-3.0-or-later -from .caption import makeExtension, captionExtension + +from .caption import makeExtension, CaptionExtension + +__all__ = ['makeExtension', 'CaptionExtension'] diff --git a/caption/caption.py b/caption/caption.py index 2b93516..dc4a9cb 100644 --- a/caption/caption.py +++ b/caption/caption.py @@ -1,4 +1,4 @@ -''' +""" caption - Manage markdown captions Applying style and auto-numbering to Python-Markdown content. @@ -9,174 +9,231 @@ Copyright (c) 2019-2020 Philipp Trommler SPDX-License-Identifier: GPL-3.0-or-later -''' +""" from markdown.treeprocessors import Treeprocessor from markdown.extensions import Extension from xml.etree import ElementTree -class captionTreeprocessor(Treeprocessor): +class CaptionTreeprocessor(Treeprocessor): + """Base class for Caption processors.""" + + name = "" + content_tag = "" + caption_tag = "figcaption" + def __init__( - # Make content types and attributes self, - name = "figure", - caption_prefix = None, - numbering = True, - top_caption = True, - caption_prefix_class = None, - caption_class = None, - content_class = None, - id_prefix = None, - link_process = None, - content_tag = None, - caption_tag = "figcaption", - prefix_tag = "span", - id = None - ): - - self.name = name - if caption_prefix is not None: - self.caption_prefix = caption_prefix - else: - self.caption_prefix = name.capitalize() + md=None, + caption_prefix="", + numbering=True, + caption_prefix_class=None, + caption_class=None, + content_class=None, + link_process=None, + ): + self.caption_prefix = caption_prefix self.numbering = numbering self.number = 0 - self.top_caption = top_caption self.caption_prefix_class = caption_prefix_class self.caption_class = caption_class self.content_class = content_class - self.id_prefix = id_prefix self.link_process = link_process - if content_tag is not None: - self.content_tag = content_tag - else: - self.content_tag = "div class={}".format(name) - self.caption_tag = caption_tag - self.prefix_tag = prefix_tag - if id is not None: - self.id = id - else: - self.id = "_{}-".format(name) - - @staticmethod - def matchChildren(par): - # Find images in links - a = None - img = par.find("./img") - if img is None: - a = par.find("./a") - if a is not None: - img = a.find("./img") - if img is None: - a = None - return (img, a) - - def buildContentElement(self, par, Type): - # Format the content element containing the caption + + def build_content_element(self, par): + """Format the content element containing the caption""" attrib = par.attrib par.clear() - par.tag = Type.content_tag + par.tag = self.content_tag for k, v in attrib.items(): par.set(k, v) - if Type.content_class is not None: - par.set("class", Type.content_class) - par.set("id", "_{}-{}".format(Type.name, Type.number)) + if self.content_class: + par.set("class", self.content_class) + par.set("id", "_{}-{}".format(self.name, self.number)) par.text = "\n" par.tail = "\n" - def buildCaptionElement(self, par, title, Type): - # Format the caption - caption = ElementTree.SubElement(par, Type.caption_tag) - if Type.caption_class is not None: - caption.set("class", Type.caption_class) - if Type.numbering: - caption_prefixSpan = ElementTree.SubElement(caption, Type.prefix_tag) - caption_prefixSpan.text = "{} {}:".format(Type.caption_prefix, Type.number) - caption_prefixSpan.tail = " {}".format(title) - if Type.caption_prefix_class is not None: - caption_prefixSpan.set("class", Type.caption_prefix_class) - else: + def build_caption_element(self, par, title): + """Format the caption.""" + caption = ElementTree.SubElement(par, self.caption_tag) + caption.tail = "\n" + + if self.caption_class: + caption.set("class", self.caption_class) + if not self.numbering: caption.text = title + return + caption_prefix_span = ElementTree.SubElement(caption, "span") + if title: + caption_prefix_span.text = "{} {}:".format( + self.caption_prefix, self.number + ) + caption_prefix_span.tail = " {}".format(title) + else: + caption_prefix_span.text = "{} {}".format( + self.caption_prefix, self.number + ) + caption_prefix_span.tail = "" + if self.caption_prefix_class: + caption_prefix_span.set("class", self.caption_prefix_class) - caption.tail = "\n" + def matches(self, par): + """ + Whether the element tree part matches the object to be captioned. + + This will be overriden by the subclasses. + """ + raise NotImplementedError + + def get_title(self, par): + """Title of the element. This will be overriden by the subclasses.""" + raise NotImplementedError def run(self, root): - # Find and format all captions - # Define content types and attributes - Figure = captionTreeprocessor( - top_caption = False, - content_tag = "figure", - link_process = "strip_title") - Table = captionTreeprocessor( - name = "table", - content_tag = "table", - caption_tag = "caption", - link_process = "line_2_caption") - Listing = captionTreeprocessor( - name = "listing") + """Find and format all captions.""" for par in root.findall("./p"): - if par.text and par.text.startswith("Table: "): - Type = Table - title = par.text[len("Table: "):] - elif par.text and par.text.startswith("Listing: "): - Type = Listing - title = par.text[len("Listing: "):] - else: - img, a = captionTreeprocessor.matchChildren(par) - if img is None: - continue - Type = Figure - - Type.number += 1 - self.buildContentElement(par, Type) - - if Type.name == "figure": - if a is not None: - a.tail = "\n" - par.append(a) - else: - if img.tail is None: - img.tail = "\n" - else: - img.tail += "\n" - par.append(img) - title = img.get("title") - - self.buildCaptionElement(par, title, Type) - if Type.name == "figure" and Type.link_process == "strip_title": - del img.attrib["title"] - - -class captionExtension(Extension): + if not self.matches(par): + continue + self.number += 1 + title = self.get_title(par) + self.build_content_element(par) + self.build_caption_element(par, title) + + +class ListingCaptionTreeProcessor(CaptionTreeprocessor): + name = "listing" + content_tag = "div class=listing" + + def matches(self, par): + return par.text and par.text.startswith("Listing: ") + + def get_title(self, par): + return par.text[9:] + + +class FigureCaptionTreeProcessor(CaptionTreeprocessor): + name = "figure" + content_tag = "figure" + + def matches(self, par): + self._a = None + self._img = par.find("./img") + if self._img is None: + self._a = par.find("./a") + if self._a is None: + return False + self._img = self._a.find("./img") + return self._img is not None + + def get_title(self, par): + return self._img.get("title") + + def build_content_element(self, par): + super(FigureCaptionTreeProcessor, self).build_content_element(par) + if self._a is not None: + self._a.tail = "\n" + par.append(self._a) + else: + self._img.tail = self._img.tail or "" + "\n" + par.append(self._img) + + def build_caption_element(self, par, title): + super(FigureCaptionTreeProcessor, self).build_caption_element(par, title) + if self.link_process == "strip_title" and title: + del self._img.attrib["title"] + + +class TableCaptionTreeProcessor(CaptionTreeprocessor): + name = "table" + content_tag = "div class=table" + caption_tag = "caption" + # link_process = self.link_process or "line_2_caption", + + def matches(self, par): + return par.text and par.text.startswith("Table: ") + + def get_title(self, par): + return par.text[7:] + + +class CaptionExtension(Extension): # caption Extension def __init__(self, **kwargs): # Setup configs self.config = { - "caption_prefix" : ["Figure", "The text to show in front of the image caption."], - "numbering" : [True, "Add the caption number to the prefix."], - "caption_prefix_class" : ["", "CSS class to add to the caption prefix element."], - "caption_class" : ["", "CSS class to add to the caption element."], - "content_class" : ["", "CSS class to add to the content element."], - "link_process" : ["", "Some content types support linked processes."], + "figure_caption_prefix": [ + "Figure", + "The text to show in front of the image caption.", + ], + "table_caption_prefix": [ + "Table", + "The text to show in front of the table caption.", + ], + "listing_caption_prefix": [ + "Listing", + "The text to show in front of the listing caption.", + ], + "numbering": [True, "Add the caption number to the prefix."], + "caption_prefix_class": [ + "", + "CSS class to add to the caption prefix element.", + ], + "caption_class": ["", "CSS class to add to the caption element."], + "content_class": ["", "CSS class to add to the content element."], + "link_process": ["", "Some content types support linked processes."], } - super(captionExtension, self).__init__(**kwargs) + super(CaptionExtension, self).__init__(**kwargs) def extendMarkdown(self, md): # Add pieces to Markdown + numbering = self.getConfig("numbering") + caption_prefix_class = self.getConfig("caption_prefix_class") + caption_class = self.getConfig("caption_class") + content_class = self.getConfig("content_class") + link_process = self.getConfig("link_process") + md.treeprocessors.register( - captionTreeprocessor( + FigureCaptionTreeProcessor( md, - caption_prefix=self.getConfig("caption_prefix"), - numbering=self.getConfig("numbering"), - caption_prefix_class=self.getConfig("caption_prefix_class"), - caption_class=self.getConfig("caption_class"), - content_class=self.getConfig("content_class"), - link_process=self.getConfig("link_process"), + caption_prefix=self.getConfig("figure_caption_prefix"), + numbering=numbering, + caption_prefix_class=caption_prefix_class, + caption_class=caption_class, + content_class=content_class, + link_process=link_process or "strip_title", ), - "captiontreeprocessor", - 8) + "figurecaptiontreeprocessor", + 8, + ) + md.treeprocessors.register( + TableCaptionTreeProcessor( + md, + caption_prefix=self.getConfig("table_caption_prefix"), + numbering=numbering, + caption_prefix_class=caption_prefix_class, + caption_class=caption_class, + content_class=content_class, + link_process=link_process, + ), + "tablecaptiontreeprocessor", + 8, + ) + md.treeprocessors.register( + ListingCaptionTreeProcessor( + md, + caption_prefix=self.getConfig("listing_caption_prefix"), + numbering=numbering, + caption_prefix_class=caption_prefix_class, + caption_class=caption_class, + content_class=content_class, + link_process=link_process, + ), + "listingcaptiontreeprocessor", + 8, + ) + def makeExtension(**kwargs): - return captionExtension(**kwargs) + return CaptionExtension(**kwargs) diff --git a/setup.py b/setup.py index 9b05d4e..943f6e9 100644 --- a/setup.py +++ b/setup.py @@ -14,37 +14,35 @@ requirements = fh.read().splitlines() setuptools.setup( - author = "flywire", - author_email = "flywire0@gmail.com", - classifiers = [ - "Development Status :: 4 - Beta", - "Environment :: Plugins", - "Intended Audience :: Developers", - "License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)", - "Operating System :: OS Independent", - "Programming Language :: Python", - "Programming Language :: Python :: 2", - "Programming Language :: Python :: 2.7", - "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.6", - "Programming Language :: Python :: Implementation :: CPython", - "Topic :: Documentation", - "Topic :: Text Processing :: Markup", - ], - description = "Manage markdown captions extension", - entry_points = { - "markdown.extensions": ["caption = caption:captionExtension"] - }, - install_requires = requirements, - keywords = "markdown image figure caption html a11y", - license = "GPLv3+", - long_description = long_description, - long_description_content_type = "text/markdown", - maintainer = "flywire", - maintainer_email = "flywire0@gmail.com", - name = "caption", - packages = setuptools.find_packages(), - python_requires = ">=2.7.15, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*, !=3.5.*, <4", - url = "https://github.com/flywire/caption", - version = "0.2.3", + author="flywire", + author_email="flywire0@gmail.com", + classifiers=[ + "Development Status :: 4 - Beta", + "Environment :: Plugins", + "Intended Audience :: Developers", + "License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)", + "Operating System :: OS Independent", + "Programming Language :: Python", + "Programming Language :: Python :: 2", + "Programming Language :: Python :: 2.7", + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3.6", + "Programming Language :: Python :: Implementation :: CPython", + "Topic :: Documentation", + "Topic :: Text Processing :: Markup", + ], + description="Manage markdown captions extension", + entry_points={"markdown.extensions": ["caption = caption:CaptionExtension"]}, + install_requires=requirements, + keywords="markdown image figure caption html a11y", + license="GPLv3+", + long_description=long_description, + long_description_content_type="text/markdown", + maintainer="flywire", + maintainer_email="flywire0@gmail.com", + name="caption", + packages=setuptools.find_packages(), + python_requires=">=2.7.15, >=3, <4", + url="https://github.com/flywire/caption", + version="0.2.3", ) diff --git a/test/__init__.py b/test/__init__.py index f911255..24af772 100644 --- a/test/__init__.py +++ b/test/__init__.py @@ -3,4 +3,3 @@ # Copyright (c) 2020 flywire # # SPDX-License-Identifier: GPL-3.0-or-later - diff --git a/test/test_caption.py b/test/test_caption.py index f11d8cf..59f5635 100644 --- a/test/test_caption.py +++ b/test/test_caption.py @@ -6,24 +6,18 @@ # # SPDX-License-Identifier: GPL-3.0-or-later import markdown -import unittest -import caption +from caption import CaptionExtension -class captionTestCase(unittest.TestCase): - def setUp(self): - pass - def tearDown(self): - pass +def test_empty_input(): + in_string = "" + out_string = markdown.markdown(in_string, extensions=[CaptionExtension()]) + assert out_string == in_string - def test_empty_input(self): - inString = "" - outString = markdown.markdown(inString, extensions = [caption.captionExtension()]) - self.assertEqual(inString, outString) - def test_no_images(self): - inString = """\ +def test_no_images(): + in_string = """\ This is a test text. It contains multiple paragraphs as well as [links](https://example.com). @@ -36,98 +30,143 @@ def test_no_images(self): # This is a headline. Nothing should change here whilst using caption.""" - expectedString = markdown.markdown(inString) - outString = markdown.markdown(inString, extensions = [caption.captionExtension()]) - self.assertEqual(expectedString, outString) + expected_string = markdown.markdown(in_string) + out_string = markdown.markdown(in_string, extensions=[CaptionExtension()]) + assert out_string == expected_string - def test_listing(self): - inString = """\ + +def test_listing(): + in_string = """\ Listing: Simple listing test""" - expectedString = """\ + expected_string = """\
Listing 1: Simple listing test
""" - outString = markdown.markdown(inString, extensions = [caption.captionExtension()]) - self.assertEqual(expectedString, outString) + out_string = markdown.markdown(in_string, extensions=[CaptionExtension()]) + assert out_string == expected_string + - def test_simple_image(self): - inString = """\ +def test_simple_image(): + in_string = """\ ![alt text](/path/to/image.png "Title")""" - expectedString = """\ + expected_string = """\
alt text
Figure 1: Title
""" - outString = markdown.markdown(inString, extensions = [caption.captionExtension()]) - self.assertEqual(expectedString, outString) + out_string = markdown.markdown(in_string, extensions=[CaptionExtension()]) + assert out_string == expected_string + + +def test_simple_image_without_title(): + in_string = """\ +![alt text](/path/to/image.png)""" + expected_string = """\ +
+alt text +
Figure 1
+
""" + out_string = markdown.markdown(in_string, extensions=[CaptionExtension()]) + assert out_string == expected_string - def test_multiline_alt(self): - inString = """\ + +def test_multiline_alt(): + in_string = """\ ![This is a rather long alt text that spans multiple lines. This may be necessary to describe a picture for the blind.](/path/to/image.png "Title")""" - expectedString = """\ + expected_string = """\
This is a rather long alt text that spans multiple lines. This may be
 necessary to describe a picture for the blind.
Figure 1: Title
""" - outString = markdown.markdown(inString, extensions = [caption.captionExtension()]) - self.assertEqual(expectedString, outString) + out_string = markdown.markdown(in_string, extensions=[CaptionExtension()]) + assert out_string == expected_string + - def test_multiline_title(self): - inString = """\ +def test_multiline_title(): + in_string = """\ ![alt text](/path/to/image.png "This is a very long title. It is used to give the readers a good figcaption. It may contain a description of the image as well as sources.")""" - expectedString = """\ -
-alt text -
This is a very long title. It is used to give -the readers a good figcaption. It may contain a description of the image as well -as sources.
+ expected_string = """\ +
+alt text +
Figure 1: This is a very long title. It is used to give the readers a good figcaption. It may contain a description of the image as well as sources.
""" + out_string = markdown.markdown(in_string, extensions=[CaptionExtension()]) + assert out_string == expected_string - def test_strip_title_None(self): - inString = """\ + +def test_multiline_title_no_strip(): + in_string = """\ +![alt text](/path/to/image.png "This is a very long title. It is used to give the readers a good figcaption. It may contain a description of the image as well as sources.")""" + expected_string = """\ +
+alt text +
This is a very long title. It is used to give the readers a good figcaption. It may contain a description of the image as well as sources.
+
""" + out_string = markdown.markdown( + in_string, + extensions=[ + CaptionExtension( + link_process="none", + figure_caption_prefix="", + numbering=False, + ) + ], + ) + assert out_string == expected_string + + +def test_strip_title_none(): + in_string = """\ ![alt text](/path/to/image.png "Title")""" - expectedString = """\ + expected_string = """\
alt text
Figure 1: Title
""" - outString = markdown.markdown(inString, extensions = [caption.captionExtension(link_process=None)]) - self.assertEqual(expectedString, outString) + out_string = markdown.markdown( + in_string, extensions=[CaptionExtension(link_process="none")] + ) + assert out_string == expected_string + - def test_content_class(self): - inString = """\ +def test_content_class(): + in_string = """\ ![alt text](/path/to/image.png "Title")""" - expectedString = """\ + expected_string = """\
alt text
Figure 1: Title
""" - outString = markdown.markdown(inString, extensions = [caption.captionExtension(content_class="testclass")]) - self.assertEqual(expectedString, outString) + out_string = markdown.markdown( + in_string, extensions=[CaptionExtension(content_class="testclass")] + ) + assert out_string == expected_string - def test_caption_class(self): - inString = """\ + +def test_caption_class(): + in_string = """\ ![alt text](/path/to/image.png "Title")""" - expectedString = """\ + expected_string = """\
alt text
Figure 1: Title
-
>""" - outString = markdown.markdown(inString, extensions = [caption.captionExtension(caption_class="testclass")]) - self.assertEqual(expectedString, outString) +
""" + out_string = markdown.markdown( + in_string, extensions=[CaptionExtension(caption_class="testclass")] + ) + assert out_string == expected_string + - def test_numbering_false(self): - inString = """\ +def test_numbering_false(): + in_string = """\ ![alt text](/path/to/image.png "Title") ![alt text 2](/path/to/image2.png "Title 2")""" - expectedString = """\ + expected_string = """\
alt text
Title
@@ -136,62 +175,86 @@ def test_numbering_false(self): alt text 2
Title 2
""" - outString = markdown.markdown(inString, extensions = [caption.captionExtension(numbering=False)]) - self.assertEqual(expectedString, outString) + out_string = markdown.markdown( + in_string, extensions=[CaptionExtension(numbering=False)] + ) + assert out_string == expected_string - def test_caption_prefix_class(self): - inString = """\ + +def test_caption_prefix_class(): + in_string = """\ ![alt text](/path/to/image.png "Title")""" - expectedString = """\ + expected_string = """\
alt text
Figure 1: Title
""" - outString = markdown.markdown(inString, extensions = [caption.captionExtension(caption_prefix_class="testclass")]) - self.assertEqual(expectedString, outString) + out_string = markdown.markdown( + in_string, + extensions=[CaptionExtension(caption_prefix_class="testclass")], + ) + assert out_string == expected_string + - def test_caption_prefix(self): - inString = """\ +def test_caption_prefix(): + in_string = """\ ![alt text](/path/to/image.png "Title")""" - expectedString = """\ + expected_string = """\
alt text
Abbildung 1: Title
""" - outString = markdown.markdown(inString, extensions = [caption.captionExtension(caption_prefix="Abbildung")]) - self.assertEqual(expectedString, outString) + out_string = markdown.markdown( + in_string, extensions=[CaptionExtension(figure_caption_prefix="Abbildung")] + ) + assert out_string == expected_string - def test_attribute_preservation(self): - inString = """\ +def test_attribute_preservation(): + in_string = """\ ![alt text](/path/to/image.png "Title"){: #someid .someclass somekey='some value' }""" - expectedString = """\ + expected_string = """\
alt text
Figure 1: Title
""" - outString = markdown.markdown(inString, extensions = ["attr_list", caption.captionExtension()]) - self.assertEqual(expectedString, outString) + out_string = markdown.markdown( + in_string, extensions=["attr_list", CaptionExtension()] + ) + assert out_string == expected_string + - def test_image_in_link(self): - inString = """\ +def test_image_in_link(): + in_string = """\ [![alt text](/path/to/image.png "Title")](/path/to/link.html)""" - expectedString = """\ + expected_string = """\
alt text
Figure 1: Title
""" - outString = markdown.markdown(inString, extensions = [caption.captionExtension()]) - self.assertEqual(expectedString, outString) + out_string = markdown.markdown(in_string, extensions=[CaptionExtension()]) + assert out_string == expected_string - def test_combined_options(self): - inString = """\ +def test_combined_options(): + in_string = """\ ![alt text](/path/to/image.png "Title")""" - expectedString = """\ + expected_string = """\
alt text
Abbildung 1: Title
""" - outString = markdown.markdown(inString, extensions = [caption.captionExtension(caption_prefix="Abbildung", numbering=True, content_class="testclass1", caption_class="testclass2", caption_prefix_class="testclass3", link_process="strip_title")]) - self.assertEqual(expectedString, outString) + out_string = markdown.markdown( + in_string, + extensions=[ + CaptionExtension( + figure_caption_prefix="Abbildung", + numbering=True, + content_class="testclass1", + caption_class="testclass2", + caption_prefix_class="testclass3", + link_process="strip_title", + ) + ], + ) + assert out_string == expected_string