Compare commits
13 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0c8ac578c9 | ||
|
|
e8d041c251 | ||
|
|
f729c3ba43 | ||
|
|
eddfdae4ca | ||
|
|
8f047753ae | ||
|
|
50b3b73a8f | ||
|
|
0310216877 | ||
|
|
194c646a20 | ||
|
|
9914474828 | ||
|
|
6263f0e5f0 | ||
|
|
17d8586843 | ||
|
|
59eb069700 | ||
|
|
e79971a7eb |
10
.github/workflows/python-app.yml
vendored
10
.github/workflows/python-app.yml
vendored
@@ -23,11 +23,7 @@ jobs:
|
|||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
run: |
|
run: |
|
||||||
python -m pip install --upgrade pip
|
python -m pip install --upgrade pip
|
||||||
pip install flake8==3.8.4 pytest
|
pip install tox
|
||||||
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
|
- name: Lint and test
|
||||||
- name: Lint with flake8
|
|
||||||
run: |
|
run: |
|
||||||
python setup.py lint
|
tox
|
||||||
- name: Test with pytest
|
|
||||||
run: |
|
|
||||||
python setup.py test
|
|
||||||
|
|||||||
1
.gitignore
vendored
1
.gitignore
vendored
@@ -9,3 +9,4 @@
|
|||||||
/venv
|
/venv
|
||||||
build/
|
build/
|
||||||
.vscode/settings.json
|
.vscode/settings.json
|
||||||
|
.tox/
|
||||||
|
|||||||
17
README.rst
17
README.rst
@@ -174,13 +174,16 @@ change:
|
|||||||
return ImageBlockConverter(**options).convert(html)
|
return ImageBlockConverter(**options).convert(html)
|
||||||
|
|
||||||
|
|
||||||
|
Command Line Interface
|
||||||
|
======================
|
||||||
|
|
||||||
|
Use ``markdownify example.html > example.md`` or pipe input from stdin
|
||||||
|
(``cat example.html | markdownify > example.md``).
|
||||||
|
Call ``markdownify -h`` to see all available options.
|
||||||
|
They are the same as listed above and take the same arguments.
|
||||||
|
|
||||||
|
|
||||||
Development
|
Development
|
||||||
===========
|
===========
|
||||||
|
|
||||||
To run tests:
|
To run tests and the linter run ``pip install tox`` once, then ``tox``.
|
||||||
|
|
||||||
``python setup.py test``
|
|
||||||
|
|
||||||
To lint:
|
|
||||||
|
|
||||||
``python setup.py lint``
|
|
||||||
|
|||||||
@@ -158,7 +158,7 @@ class MarkdownConverter(object):
|
|||||||
and el.parent.parent.name == 'pre')):
|
and el.parent.parent.name == 'pre')):
|
||||||
text = whitespace_re.sub(' ', text)
|
text = whitespace_re.sub(' ', text)
|
||||||
|
|
||||||
if el.parent.name != 'code':
|
if el.parent.name != 'code' and el.parent.name != 'pre':
|
||||||
text = self.escape(text)
|
text = self.escape(text)
|
||||||
|
|
||||||
# remove trailing whitespaces if any of the following condition is true:
|
# remove trailing whitespaces if any of the following condition is true:
|
||||||
|
|||||||
68
markdownify/main.py
Normal file
68
markdownify/main.py
Normal file
@@ -0,0 +1,68 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
|
||||||
|
import argparse
|
||||||
|
import sys
|
||||||
|
|
||||||
|
from markdownify import markdownify
|
||||||
|
|
||||||
|
|
||||||
|
def main(argv=sys.argv[1:]):
|
||||||
|
parser = argparse.ArgumentParser(
|
||||||
|
prog='markdownify',
|
||||||
|
description='Converts html to markdown.',
|
||||||
|
)
|
||||||
|
|
||||||
|
parser.add_argument('html', nargs='?', type=argparse.FileType('r'),
|
||||||
|
default=sys.stdin,
|
||||||
|
help="The html file to convert. Defaults to STDIN if not "
|
||||||
|
"provided.")
|
||||||
|
parser.add_argument('-s', '--strip', nargs='*',
|
||||||
|
help="A list of tags to strip. This option can't be used with "
|
||||||
|
"the --convert option.")
|
||||||
|
parser.add_argument('-c', '--convert', nargs='*',
|
||||||
|
help="A list of tags to convert. This option can't be used with "
|
||||||
|
"the --strip option.")
|
||||||
|
parser.add_argument('-a', '--autolinks', action='store_true',
|
||||||
|
help="A boolean indicating whether the 'automatic link' style "
|
||||||
|
"should be used when a 'a' tag's contents match its href.")
|
||||||
|
parser.add_argument('--default-title', action='store_false',
|
||||||
|
help="A boolean to enable setting the title of a link to its "
|
||||||
|
"href, if no title is given.")
|
||||||
|
parser.add_argument('--heading-style', default='UNDERLINED',
|
||||||
|
choices=('ATX', 'ATX_CLOSED', 'SETEXT', 'UNDERLINED'),
|
||||||
|
help="Defines how headings should be converted.")
|
||||||
|
parser.add_argument('-b', '--bullets', default='*+-',
|
||||||
|
help="A string of bullet styles to use; the bullet will "
|
||||||
|
"alternate based on nesting level.")
|
||||||
|
parser.add_argument('--strong-em-symbol', default='ASTERISK',
|
||||||
|
choices=('ASTERISK', 'UNDERSCORE'),
|
||||||
|
help="Use * or _ to convert strong and italics text"),
|
||||||
|
parser.add_argument('--sub-symbol', default='',
|
||||||
|
help="Define the chars that surround '<sub>'.")
|
||||||
|
parser.add_argument('--sup-symbol', default='',
|
||||||
|
help="Define the chars that surround '<sup>'.")
|
||||||
|
parser.add_argument('--code-language', default='',
|
||||||
|
help="Defines the language that should be assumed for all "
|
||||||
|
"'<pre>' sections.")
|
||||||
|
parser.add_argument('--no-escape-asterisks', dest='escape_asterisks',
|
||||||
|
action='store_false',
|
||||||
|
help="Do not escape '*' to '\\*' in text.")
|
||||||
|
parser.add_argument('--no-escape-underscores', dest='escape_underscores',
|
||||||
|
action='store_false',
|
||||||
|
help="Do not escape '_' to '\\_' in text.")
|
||||||
|
parser.add_argument('-i', '--keep-inline-images-in', nargs='*',
|
||||||
|
help="Images are converted to their alt-text when the images are "
|
||||||
|
"located inside headlines or table cells. If some inline images "
|
||||||
|
"should be converted to markdown images instead, this option can "
|
||||||
|
"be set to a list of parent tags that should be allowed to "
|
||||||
|
"contain inline images.")
|
||||||
|
parser.add_argument('-w', '--wrap', action='store_true',
|
||||||
|
help="Wrap all text paragraphs at --wrap-width characters.")
|
||||||
|
parser.add_argument('--wrap-width', type=int, default=80)
|
||||||
|
|
||||||
|
args = parser.parse_args(argv)
|
||||||
|
print(markdownify(**vars(args)))
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
||||||
65
setup.py
65
setup.py
@@ -2,7 +2,6 @@
|
|||||||
import codecs
|
import codecs
|
||||||
import os
|
import os
|
||||||
from setuptools import setup, find_packages
|
from setuptools import setup, find_packages
|
||||||
from setuptools.command.test import test as TestCommand, Command
|
|
||||||
|
|
||||||
|
|
||||||
read = lambda filepath: codecs.open(filepath, 'r', 'utf-8').read()
|
read = lambda filepath: codecs.open(filepath, 'r', 'utf-8').read()
|
||||||
@@ -10,52 +9,10 @@ read = lambda filepath: codecs.open(filepath, 'r', 'utf-8').read()
|
|||||||
pkgmeta = {
|
pkgmeta = {
|
||||||
'__title__': 'markdownify',
|
'__title__': 'markdownify',
|
||||||
'__author__': 'Matthew Tretter',
|
'__author__': 'Matthew Tretter',
|
||||||
'__version__': '0.11.2',
|
'__version__': '0.11.5',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
read = lambda filepath: codecs.open(filepath, 'r', 'utf-8').read()
|
||||||
class PyTest(TestCommand):
|
|
||||||
def finalize_options(self):
|
|
||||||
TestCommand.finalize_options(self)
|
|
||||||
self.test_args = ['tests', '-s']
|
|
||||||
self.test_suite = True
|
|
||||||
|
|
||||||
def run_tests(self):
|
|
||||||
import pytest
|
|
||||||
errno = pytest.main(self.test_args)
|
|
||||||
raise SystemExit(errno)
|
|
||||||
|
|
||||||
|
|
||||||
class LintCommand(Command):
|
|
||||||
"""
|
|
||||||
A copy of flake8's Flake8Command
|
|
||||||
|
|
||||||
"""
|
|
||||||
description = "Run flake8 on modules registered in setuptools"
|
|
||||||
user_options = []
|
|
||||||
|
|
||||||
def initialize_options(self):
|
|
||||||
pass
|
|
||||||
|
|
||||||
def finalize_options(self):
|
|
||||||
pass
|
|
||||||
|
|
||||||
def distribution_files(self):
|
|
||||||
if self.distribution.packages:
|
|
||||||
for package in self.distribution.packages:
|
|
||||||
yield package.replace(".", os.path.sep)
|
|
||||||
|
|
||||||
if self.distribution.py_modules:
|
|
||||||
for filename in self.distribution.py_modules:
|
|
||||||
yield "%s.py" % filename
|
|
||||||
|
|
||||||
def run(self):
|
|
||||||
from flake8.api.legacy import get_style_guide
|
|
||||||
flake8_style = get_style_guide(config_file='setup.cfg')
|
|
||||||
paths = self.distribution_files()
|
|
||||||
report = flake8_style.check_files(paths)
|
|
||||||
raise SystemExit(report.total_errors > 0)
|
|
||||||
|
|
||||||
|
|
||||||
setup(
|
setup(
|
||||||
name='markdownify',
|
name='markdownify',
|
||||||
@@ -69,14 +26,9 @@ setup(
|
|||||||
packages=find_packages(),
|
packages=find_packages(),
|
||||||
zip_safe=False,
|
zip_safe=False,
|
||||||
include_package_data=True,
|
include_package_data=True,
|
||||||
setup_requires=[
|
|
||||||
'flake8>=3.8,<5',
|
|
||||||
],
|
|
||||||
tests_require=[
|
|
||||||
'pytest>=6.2,<7',
|
|
||||||
],
|
|
||||||
install_requires=[
|
install_requires=[
|
||||||
'beautifulsoup4>=4.9,<5', 'six>=1.15,<2'
|
'beautifulsoup4>=4.9,<5',
|
||||||
|
'six>=1.15,<2',
|
||||||
],
|
],
|
||||||
classifiers=[
|
classifiers=[
|
||||||
'Environment :: Web Environment',
|
'Environment :: Web Environment',
|
||||||
@@ -92,8 +44,9 @@ setup(
|
|||||||
'Programming Language :: Python :: 3.8',
|
'Programming Language :: Python :: 3.8',
|
||||||
'Topic :: Utilities'
|
'Topic :: Utilities'
|
||||||
],
|
],
|
||||||
cmdclass={
|
entry_points={
|
||||||
'test': PyTest,
|
'console_scripts': [
|
||||||
'lint': LintCommand,
|
'markdownify = markdownify.main:main'
|
||||||
},
|
]
|
||||||
|
}
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -187,6 +187,7 @@ def test_p():
|
|||||||
def test_pre():
|
def test_pre():
|
||||||
assert md('<pre>test\n foo\nbar</pre>') == '\n```\ntest\n foo\nbar\n```\n'
|
assert md('<pre>test\n foo\nbar</pre>') == '\n```\ntest\n foo\nbar\n```\n'
|
||||||
assert md('<pre><code>test\n foo\nbar</code></pre>') == '\n```\ntest\n foo\nbar\n```\n'
|
assert md('<pre><code>test\n foo\nbar</code></pre>') == '\n```\ntest\n foo\nbar\n```\n'
|
||||||
|
assert md('<pre>this_should_not_escape</pre>') == '\n```\nthis_should_not_escape\n```\n'
|
||||||
|
|
||||||
|
|
||||||
def test_s():
|
def test_s():
|
||||||
|
|||||||
Reference in New Issue
Block a user