Skip to content

Commit 194c646

Browse files
committed
Merge branch 'develop'
2 parents 2c53333 + 9914474 commit 194c646

File tree

9 files changed

+99
-72
lines changed

9 files changed

+99
-72
lines changed

.github/workflows/python-app.yml

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,7 @@ jobs:
2323
- name: Install dependencies
2424
run: |
2525
python -m pip install --upgrade pip
26-
pip install flake8==3.8.4 pytest
27-
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
28-
- name: Lint with flake8
26+
pip install tox
27+
- name: Lint and test
2928
run: |
30-
python setup.py lint
31-
- name: Test with pytest
32-
run: |
33-
python setup.py test
29+
tox

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@
99
/venv
1010
build/
1111
.vscode/settings.json
12+
.tox/

README.rst

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -174,13 +174,16 @@ change:
174174
return ImageBlockConverter(**options).convert(html)
175175
176176
177-
Development
178-
===========
177+
Command Line Interface
178+
=====================
179179

180-
To run tests:
180+
Use ``markdownify example.html > example.md`` or pipe input from stdin
181+
(``cat example.html | markdownify > example.md``).
182+
Call ``markdownify -h`` to see all available options.
183+
They are the same as listed above and take the same arguments.
181184

182-
``python setup.py test``
183185

184-
To lint:
186+
Development
187+
===========
185188

186-
``python setup.py lint``
189+
To run tests and the linter run ``pip install tox`` once, then ``tox``.

markdownify/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ def process_text(self, el):
158158
and el.parent.parent.name == 'pre')):
159159
text = whitespace_re.sub(' ', text)
160160

161-
if el.parent.name != 'code':
161+
if el.parent.name != 'code' and el.parent.name != 'pre':
162162
text = self.escape(text)
163163

164164
# remove trailing whitespaces if any of the following condition is true:

markdownify/main.py

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#!/usr/bin/env python
2+
3+
import argparse
4+
import sys
5+
6+
from markdownify import markdownify
7+
8+
9+
def main(argv=sys.argv[1:]):
10+
parser = argparse.ArgumentParser(
11+
prog='markdownify',
12+
description='Converts html to markdown.',
13+
)
14+
15+
parser.add_argument('html', nargs='?', type=argparse.FileType('r'),
16+
default=sys.stdin,
17+
help="The html file to convert. Defaults to STDIN if not "
18+
"provided.")
19+
parser.add_argument('-s', '--strip', nargs='*',
20+
help="A list of tags to strip. This option can't be used with "
21+
"the --convert option.")
22+
parser.add_argument('-c', '--convert', nargs='*',
23+
help="A list of tags to convert. This option can't be used with "
24+
"the --strip option.")
25+
parser.add_argument('-a', '--autolinks', action='store_true',
26+
help="A boolean indicating whether the 'automatic link' style "
27+
"should be used when a 'a' tag's contents match its href.")
28+
parser.add_argument('--default-title', action='store_false',
29+
help="A boolean to enable setting the title of a link to its "
30+
"href, if no title is given.")
31+
parser.add_argument('--heading-style',
32+
choices=('ATX', 'ATX_CLOSED', 'SETEXT', 'UNDERLINED'),
33+
help="Defines how headings should be converted.")
34+
parser.add_argument('-b', '--bullets', default='*+-',
35+
help="A string of bullet styles to use; the bullet will "
36+
"alternate based on nesting level.")
37+
parser.add_argument('--sub-symbol', default='',
38+
help="Define the chars that surround '<sub>'.")
39+
parser.add_argument('--sup-symbol', default='',
40+
help="Define the chars that surround '<sup>'.")
41+
parser.add_argument('--code-language', default='',
42+
help="Defines the language that should be assumed for all "
43+
"'<pre>' sections.")
44+
parser.add_argument('--no-escape-asterisks', dest='escape_asterisks',
45+
action='store_false',
46+
help="Do not escape '*' to '\\*' in text.")
47+
parser.add_argument('--no-escape-underscores', dest='escape_underscores',
48+
action='store_false',
49+
help="Do not escape '_' to '\\_' in text.")
50+
parser.add_argument('-i', '--keep-inline-images-in', nargs='*',
51+
help="Images are converted to their alt-text when the images are "
52+
"located inside headlines or table cells. If some inline images "
53+
"should be converted to markdown images instead, this option can "
54+
"be set to a list of parent tags that should be allowed to "
55+
"contain inline images.")
56+
parser.add_argument('-w', '--wrap', action='store_true',
57+
help="Wrap all text paragraphs at --wrap-width characters.")
58+
parser.add_argument('--wrap-width', type=int, default=80)
59+
60+
args = parser.parse_args(argv)
61+
print(markdownify(**vars(args)))
62+
63+
64+
if __name__ == '__main__':
65+
main()

setup.cfg

Lines changed: 0 additions & 2 deletions
This file was deleted.

setup.py

Lines changed: 9 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -2,60 +2,17 @@
22
import codecs
33
import os
44
from setuptools import setup, find_packages
5-
from setuptools.command.test import test as TestCommand, Command
65

76

87
read = lambda filepath: codecs.open(filepath, 'r', 'utf-8').read()
98

109
pkgmeta = {
1110
'__title__': 'markdownify',
1211
'__author__': 'Matthew Tretter',
13-
'__version__': '0.11.2',
12+
'__version__': '0.11.3',
1413
}
1514

16-
17-
class PyTest(TestCommand):
18-
def finalize_options(self):
19-
TestCommand.finalize_options(self)
20-
self.test_args = ['tests', '-s']
21-
self.test_suite = True
22-
23-
def run_tests(self):
24-
import pytest
25-
errno = pytest.main(self.test_args)
26-
raise SystemExit(errno)
27-
28-
29-
class LintCommand(Command):
30-
"""
31-
A copy of flake8's Flake8Command
32-
33-
"""
34-
description = "Run flake8 on modules registered in setuptools"
35-
user_options = []
36-
37-
def initialize_options(self):
38-
pass
39-
40-
def finalize_options(self):
41-
pass
42-
43-
def distribution_files(self):
44-
if self.distribution.packages:
45-
for package in self.distribution.packages:
46-
yield package.replace(".", os.path.sep)
47-
48-
if self.distribution.py_modules:
49-
for filename in self.distribution.py_modules:
50-
yield "%s.py" % filename
51-
52-
def run(self):
53-
from flake8.api.legacy import get_style_guide
54-
flake8_style = get_style_guide(config_file='setup.cfg')
55-
paths = self.distribution_files()
56-
report = flake8_style.check_files(paths)
57-
raise SystemExit(report.total_errors > 0)
58-
15+
read = lambda filepath: codecs.open(filepath, 'r', 'utf-8').read()
5916

6017
setup(
6118
name='markdownify',
@@ -69,14 +26,9 @@ def run(self):
6926
packages=find_packages(),
7027
zip_safe=False,
7128
include_package_data=True,
72-
setup_requires=[
73-
'flake8>=3.8,<5',
74-
],
75-
tests_require=[
76-
'pytest>=6.2,<7',
77-
],
7829
install_requires=[
79-
'beautifulsoup4>=4.9,<5', 'six>=1.15,<2'
30+
'beautifulsoup4>=4.9,<5',
31+
'six>=1.15,<2',
8032
],
8133
classifiers=[
8234
'Environment :: Web Environment',
@@ -92,8 +44,9 @@ def run(self):
9244
'Programming Language :: Python :: 3.8',
9345
'Topic :: Utilities'
9446
],
95-
cmdclass={
96-
'test': PyTest,
97-
'lint': LintCommand,
98-
},
47+
entry_points={
48+
'console_scripts': [
49+
'markdownify = markdownify.main:main'
50+
]
51+
}
9952
)

tests/test_conversions.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ def test_p():
187187
def test_pre():
188188
assert md('<pre>test\n foo\nbar</pre>') == '\n```\ntest\n foo\nbar\n```\n'
189189
assert md('<pre><code>test\n foo\nbar</code></pre>') == '\n```\ntest\n foo\nbar\n```\n'
190+
assert md('<pre>this_should_not_escape</pre>') == '\n```\nthis_should_not_escape\n```\n'
190191

191192

192193
def test_s():

tox.ini

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[tox]
2+
envlist = py38
3+
4+
[testenv]
5+
deps =
6+
flake8
7+
pytest
8+
commands =
9+
flake8 --ignore=E501,W503 markdownify tests
10+
pytest

0 commit comments

Comments
 (0)