Compare commits
24 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ec185e2e9c | ||
|
|
a59e4b9f48 | ||
|
|
fd293a9714 | ||
|
|
99365de669 | ||
|
|
079d1721aa | ||
|
|
ed406d3206 | ||
|
|
f320cf87ff | ||
|
|
a4d134df97 | ||
|
|
457454c713 | ||
|
|
321e9eb5f6 | ||
|
|
bf24df3e2e | ||
|
|
15329588b1 | ||
|
|
77d1e99bd5 | ||
|
|
34ad8485fa | ||
|
|
f0ce934bf8 | ||
|
|
97c78ef55b | ||
|
|
99cd237f27 | ||
|
|
b7e1ab889d | ||
|
|
29e86aec55 | ||
|
|
453b604096 | ||
|
|
2bde8d3e8e | ||
|
|
4f8937810b | ||
|
|
8c9b029756 | ||
|
|
ae50065872 |
6
.github/workflows/python-app.yml
vendored
6
.github/workflows/python-app.yml
vendored
@@ -16,14 +16,14 @@ jobs:
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: Set up Python 3.6
|
||||
- name: Set up Python 3.8
|
||||
uses: actions/setup-python@v2
|
||||
with:
|
||||
python-version: 3.6
|
||||
python-version: 3.8
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
python -m pip install --upgrade pip
|
||||
pip install flake8==2.5.4 pytest
|
||||
pip install flake8==3.8.4 pytest
|
||||
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
|
||||
- name: Lint with flake8
|
||||
run: |
|
||||
|
||||
2
.github/workflows/python-publish.yml
vendored
2
.github/workflows/python-publish.yml
vendored
@@ -17,7 +17,7 @@ jobs:
|
||||
- name: Set up Python
|
||||
uses: actions/setup-python@v2
|
||||
with:
|
||||
python-version: '3.x'
|
||||
python-version: '3.8'
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
python -m pip install --upgrade pip
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
from bs4 import BeautifulSoup, NavigableString
|
||||
from bs4 import BeautifulSoup, NavigableString, Comment
|
||||
import re
|
||||
import six
|
||||
|
||||
|
||||
convert_heading_re = re.compile(r'convert_h(\d+)')
|
||||
line_beginning_re = re.compile(r'^', re.MULTILINE)
|
||||
whitespace_re = re.compile(r'[\r\n\s\t ]+')
|
||||
whitespace_re = re.compile(r'[\t ]+')
|
||||
html_heading_re = re.compile(r'h[1-6]')
|
||||
|
||||
|
||||
@@ -75,7 +75,9 @@ class MarkdownConverter(object):
|
||||
|
||||
# Convert the children first
|
||||
for el in node.children:
|
||||
if isinstance(el, NavigableString):
|
||||
if isinstance(el, Comment):
|
||||
continue
|
||||
elif isinstance(el, NavigableString):
|
||||
text += self.process_text(six.text_type(el))
|
||||
else:
|
||||
text += self.process_tag(el, convert_children_as_inline)
|
||||
@@ -131,7 +133,8 @@ class MarkdownConverter(object):
|
||||
return text
|
||||
href = el.get('href')
|
||||
title = el.get('title')
|
||||
if self.options['autolinks'] and text == href and not title:
|
||||
# For the replacement see #29: text nodes underscores are escaped
|
||||
if self.options['autolinks'] and text.replace(r'\_', '_') == href and not title:
|
||||
# Shortcut syntax
|
||||
return '<%s>' % href
|
||||
title_part = ' "%s"' % title.replace('"', r'\"') if title else ''
|
||||
@@ -145,7 +148,7 @@ class MarkdownConverter(object):
|
||||
if convert_as_inline:
|
||||
return text
|
||||
|
||||
return '\n' + line_beginning_re.sub('> ', text) if text else ''
|
||||
return '\n' + (line_beginning_re.sub('> ', text) + '\n\n') if text else ''
|
||||
|
||||
def convert_br(self, el, text, convert_as_inline):
|
||||
if convert_as_inline:
|
||||
|
||||
13
setup.py
13
setup.py
@@ -10,7 +10,7 @@ read = lambda filepath: codecs.open(filepath, 'r', 'utf-8').read()
|
||||
pkgmeta = {
|
||||
'__title__': 'markdownify',
|
||||
'__author__': 'Matthew Tretter',
|
||||
'__version__': '0.6.0',
|
||||
'__version__': '0.6.5',
|
||||
}
|
||||
|
||||
|
||||
@@ -50,7 +50,7 @@ class LintCommand(Command):
|
||||
yield "%s.py" % filename
|
||||
|
||||
def run(self):
|
||||
from flake8.engine import get_style_guide
|
||||
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)
|
||||
@@ -70,13 +70,13 @@ setup(
|
||||
zip_safe=False,
|
||||
include_package_data=True,
|
||||
setup_requires=[
|
||||
'flake8',
|
||||
'flake8>=3.8,<4',
|
||||
],
|
||||
tests_require=[
|
||||
'pytest',
|
||||
'pytest>=6.2,<7',
|
||||
],
|
||||
install_requires=[
|
||||
'beautifulsoup4', 'six'
|
||||
'beautifulsoup4>=4.9,<5', 'six>=1.15,<2'
|
||||
],
|
||||
classifiers=[
|
||||
'Environment :: Web Environment',
|
||||
@@ -87,6 +87,9 @@ setup(
|
||||
'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'
|
||||
],
|
||||
cmdclass={
|
||||
|
||||
@@ -4,3 +4,13 @@ from markdownify import markdownify as md
|
||||
def test_nested():
|
||||
text = md('<p>This is an <a href="http://example.com/">example link</a>.</p>')
|
||||
assert text == 'This is an [example link](http://example.com/).\n\n'
|
||||
|
||||
|
||||
def test_ignore_comments():
|
||||
text = md("<!-- This is a comment -->")
|
||||
assert text == ""
|
||||
|
||||
|
||||
def test_ignore_comments_with_other_tags():
|
||||
text = md("<!-- This is a comment --><a href='http://example.com/'>example link</a>")
|
||||
assert text == "[example link](http://example.com/)"
|
||||
|
||||
@@ -10,4 +10,4 @@ def test_soup():
|
||||
|
||||
|
||||
def test_whitespace():
|
||||
assert md(' a b \n\n c ') == ' a b c '
|
||||
assert md(' a b \t\t c ') == ' a b c '
|
||||
|
||||
@@ -34,7 +34,11 @@ def test_chomp():
|
||||
|
||||
|
||||
def test_a():
|
||||
assert md('<a href="http://google.com">Google</a>') == '[Google](http://google.com)'
|
||||
assert md('<a href="https://google.com">Google</a>') == '[Google](https://google.com)'
|
||||
assert md('<a href="https://google.com">https://google.com</a>', autolinks=False) == '[https://google.com](https://google.com)'
|
||||
assert md('<a href="https://google.com">https://google.com</a>') == '<https://google.com>'
|
||||
assert md('<a href="https://community.kde.org/Get_Involved">https://community.kde.org/Get_Involved</a>') == '<https://community.kde.org/Get_Involved>'
|
||||
assert md('<a href="https://community.kde.org/Get_Involved">https://community.kde.org/Get_Involved</a>', autolinks=False) == '[https://community.kde.org/Get\\_Involved](https://community.kde.org/Get_Involved)'
|
||||
|
||||
|
||||
def test_a_spaces():
|
||||
@@ -71,12 +75,16 @@ def test_b_spaces():
|
||||
|
||||
|
||||
def test_blockquote():
|
||||
assert md('<blockquote>Hello</blockquote>').strip() == '> Hello'
|
||||
assert md('<blockquote>Hello</blockquote>') == '\n> Hello\n\n'
|
||||
|
||||
|
||||
def test_blockquote_with_paragraph():
|
||||
assert md('<blockquote>Hello</blockquote><p>handsome</p>') == '\n> Hello\n\nhandsome\n\n'
|
||||
|
||||
|
||||
def test_nested_blockquote():
|
||||
text = md('<blockquote>And she was like <blockquote>Hello</blockquote></blockquote>').strip()
|
||||
assert text == '> And she was like \n> > Hello'
|
||||
text = md('<blockquote>And she was like <blockquote>Hello</blockquote></blockquote>')
|
||||
assert text == '\n> And she was like \n> > Hello\n> \n> \n\n'
|
||||
|
||||
|
||||
def test_br():
|
||||
@@ -107,6 +115,11 @@ def test_hn():
|
||||
assert md('<h6>Hello</h6>') == '###### Hello\n\n'
|
||||
|
||||
|
||||
def test_hn_chained():
|
||||
assert md('<h1>First</h1>\n<h2>Second</h2>\n<h3>Third</h3>', heading_style=ATX) == '# First\n\n\n## Second\n\n\n### Third\n\n'
|
||||
assert md('X<h1>First</h1>', heading_style=ATX) == 'X# First\n\n'
|
||||
|
||||
|
||||
def test_hn_nested_tag_heading_style():
|
||||
assert md('<h1>A <p>P</p> C </h1>', heading_style=ATX_CLOSED) == '# A P C #\n\n'
|
||||
assert md('<h1>A <p>P</p> C </h1>', heading_style=ATX) == '# A P C\n\n'
|
||||
|
||||
@@ -2,7 +2,7 @@ from markdownify import markdownify as md
|
||||
|
||||
|
||||
def test_underscore():
|
||||
assert md('_hey_dude_') == '\_hey\_dude\_'
|
||||
assert md('_hey_dude_') == r'\_hey\_dude\_'
|
||||
|
||||
|
||||
def test_xml_entities():
|
||||
|
||||
Reference in New Issue
Block a user