diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml index eb64947..481ade5 100644 --- a/.github/workflows/python-app.yml +++ b/.github/workflows/python-app.yml @@ -23,7 +23,10 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip - pip install tox + pip install --upgrade setuptools setuptools_scm wheel build tox - name: Lint and test run: | tox + - name: Build + run: | + python -m build -nwsx . diff --git a/.github/workflows/python-publish.yml b/.github/workflows/python-publish.yml index 9e3a349..c337bab 100644 --- a/.github/workflows/python-publish.yml +++ b/.github/workflows/python-publish.yml @@ -21,11 +21,11 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip - pip install setuptools wheel twine + pip install --upgrade setuptools setuptools_scm wheel build twine - name: Build and publish env: TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }} TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }} run: | - python setup.py sdist bdist_wheel + python -m build -nwsx . twine upload dist/* diff --git a/MANIFEST.in b/MANIFEST.in index 9561fb1..70656c8 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1 +1,2 @@ include README.rst +prune tests diff --git a/README.rst b/README.rst index 35d58fd..55ea7cf 100644 --- a/README.rst +++ b/README.rst @@ -87,7 +87,11 @@ strong_em_symbol sub_symbol, sup_symbol Define the chars that surround ```` and ```` text. Defaults to an empty string, because this is non-standard behavior. Could be something like - ``~`` and ``^`` to result in ``~sub~`` and ``^sup^``. + ``~`` and ``^`` to result in ``~sub~`` and ``^sup^``. If the value starts + with ``<`` and ends with ``>``, it is treated as an HTML tag and a ``/`` is + inserted after the ``<`` in the string used after the text; this allows + specifying ```` to use raw HTML in the output for subscripts, for + example. newline_style Defines the style of marking linebreaks (``
``) in markdown. The default diff --git a/markdownify/__init__.py b/markdownify/__init__.py index d0da098..efb2d15 100644 --- a/markdownify/__init__.py +++ b/markdownify/__init__.py @@ -43,17 +43,22 @@ def abstract_inline_conversion(markup_fn): """ This abstracts all simple inline tags like b, em, del, ... Returns a function that wraps the chomped text in a pair of the string - that is returned by markup_fn. markup_fn is necessary to allow for + that is returned by markup_fn, with '/' inserted in the string used after + the text if it looks like an HTML tag. markup_fn is necessary to allow for references to self.strong_em_symbol etc. """ def implementation(self, el, text, convert_as_inline): - markup = markup_fn(self) + markup_prefix = markup_fn(self) + if markup_prefix.startswith('<') and markup_prefix.endswith('>'): + markup_suffix = '=61.2", "setuptools_scm[toml]>=3.4.3"] +build-backend = "setuptools.build_meta" + +[project] +name = "markdownify" +version = "0.13.1" +authors = [{name = "Matthew Tretter", email = "m@tthewwithanm.com"}] +description = "Convert HTML to markdown." +readme = "README.rst" +classifiers = [ + "Environment :: Web Environment", + "Framework :: Django", + "Intended Audience :: Developers", + "License :: OSI Approved :: MIT License", + "Operating System :: OS Independent", + "Programming Language :: Python :: 2.5", + "Programming Language :: Python :: 2.6", + "Programming Language :: Python :: 2.7", + "Programming Language :: Python :: 3.6", + "Programming Language :: Python :: 3.7", + "Programming Language :: Python :: 3.8", + "Topic :: Utilities", +] +dependencies = [ + "beautifulsoup4>=4.9,<5", + "six>=1.15,<2" +] + +[project.urls] +Homepage = "http://github.com/matthewwithanm/python-markdownify" +Download = "http://github.com/matthewwithanm/python-markdownify/tarball/master" + +[project.scripts] +markdownify = "markdownify.main:main" + +[tool.setuptools] +zip-safe = false +include-package-data = true + +[tool.setuptools.packages.find] +include = ["markdownify", "markdownify.*"] +namespaces = false + +[tool.setuptools_scm] diff --git a/setup.py b/setup.py deleted file mode 100644 index 9a26468..0000000 --- a/setup.py +++ /dev/null @@ -1,52 +0,0 @@ -#/usr/bin/env python -import codecs -import os -from setuptools import setup, find_packages - - -read = lambda filepath: codecs.open(filepath, 'r', 'utf-8').read() - -pkgmeta = { - '__title__': 'markdownify', - '__author__': 'Matthew Tretter', - '__version__': '0.12.1', -} - -read = lambda filepath: codecs.open(filepath, 'r', 'utf-8').read() - -setup( - name='markdownify', - description='Convert HTML to markdown.', - long_description=read(os.path.join(os.path.dirname(__file__), 'README.rst')), - version=pkgmeta['__version__'], - author=pkgmeta['__author__'], - author_email='m@tthewwithanm.com', - url='http://github.com/matthewwithanm/python-markdownify', - download_url='http://github.com/matthewwithanm/python-markdownify/tarball/master', - packages=find_packages(), - zip_safe=False, - include_package_data=True, - install_requires=[ - 'beautifulsoup4>=4.9,<5', - 'six>=1.15,<2', - ], - classifiers=[ - 'Environment :: Web Environment', - 'Framework :: Django', - 'Intended Audience :: Developers', - 'License :: OSI Approved :: MIT License', - 'Operating System :: OS Independent', - 'Programming Language :: Python :: 2.5', - 'Programming Language :: Python :: 2.6', - 'Programming Language :: Python :: 2.7', - 'Programming Language :: Python :: 3.6', - 'Programming Language :: Python :: 3.7', - 'Programming Language :: Python :: 3.8', - 'Topic :: Utilities' - ], - entry_points={ - 'console_scripts': [ - 'markdownify = markdownify.main:main' - ] - } -) diff --git a/tests/test_conversions.py b/tests/test_conversions.py index e2c172a..baa294b 100644 --- a/tests/test_conversions.py +++ b/tests/test_conversions.py @@ -271,11 +271,13 @@ def test_strong_em_symbol(): def test_sub(): assert md('foo') == 'foo' assert md('foo', sub_symbol='~') == '~foo~' + assert md('foo', sub_symbol='') == 'foo' def test_sup(): assert md('foo') == 'foo' assert md('foo', sup_symbol='^') == '^foo^' + assert md('foo', sup_symbol='') == 'foo' def test_lang(): diff --git a/tests/test_lists.py b/tests/test_lists.py index 0b23179..ecc1a65 100644 --- a/tests/test_lists.py +++ b/tests/test_lists.py @@ -44,6 +44,9 @@ def test_ol(): assert md('
  1. a
  2. b
') == '\n\n1. a\n2. b\n' assert md('
  1. a
  2. b
') == '\n\n3. a\n4. b\n' assert md('foo
  1. a
  2. b
bar') == 'foo\n\n3. a\n4. b\n\nbar' + assert md('
  1. a
  2. b
') == '\n\n1. a\n2. b\n' + assert md('
  1. a
  2. b
') == '\n\n1. a\n2. b\n' + assert md('
  1. a
  2. b
') == '\n\n1. a\n2. b\n' def test_nested_ols(): diff --git a/tests/test_tables.py b/tests/test_tables.py index 9120c29..594e5bf 100644 --- a/tests/test_tables.py +++ b/tests/test_tables.py @@ -215,7 +215,7 @@ table_with_colspan = """ - + @@ -226,6 +226,17 @@ table_with_colspan = """
Age
JillJill Smith 50
""" +table_with_undefined_colspan = """ + + + + + + + + +
NameAge
JillSmith
""" + def test_table(): assert md(table) == '\n\n| Firstname | Lastname | Age |\n| --- | --- | --- |\n| Jill | Smith | 50 |\n| Eve | Jackson | 94 |\n\n' @@ -240,3 +251,4 @@ def test_table(): assert md(table_body) == '\n\n| Firstname | Lastname | Age |\n| --- | --- | --- |\n| Jill | Smith | 50 |\n| Eve | Jackson | 94 |\n\n' assert md(table_with_caption) == 'TEXT\n\nCaption\n| Firstname | Lastname | Age |\n| --- | --- | --- |\n\n' assert md(table_with_colspan) == '\n\n| Name | | Age |\n| --- | --- | --- |\n| Jill | Smith | 50 |\n| Eve | Jackson | 94 |\n\n' + assert md(table_with_undefined_colspan) == '\n\n| Name | Age |\n| --- | --- |\n| Jill | Smith |\n\n' diff --git a/tox.ini b/tox.ini index 9eb8750..54ba143 100644 --- a/tox.ini +++ b/tox.ini @@ -4,7 +4,7 @@ envlist = py38 [testenv] passenv = PYTHONPATH deps = - pytest + pytest==8 flake8 restructuredtext_lint Pygments