Compare commits
24 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8c9b029756 | ||
|
|
25d68b4265 | ||
|
|
5561106991 | ||
|
|
1b3136ad04 | ||
|
|
987a2a9cae | ||
|
|
a4461161bc | ||
|
|
ae50065872 | ||
|
|
19e2c3db0d | ||
|
|
ba51bbee12 | ||
|
|
9f3d497053 | ||
|
|
d2fc689b66 | ||
|
|
ab78385b56 | ||
|
|
9ebf726e78 | ||
|
|
3f8403aa7a | ||
|
|
5b6e76f984 | ||
|
|
04711027e6 | ||
|
|
ca98892953 | ||
|
|
0dc281e6ea | ||
|
|
4e6e20e756 | ||
|
|
9358522c73 | ||
|
|
28d7a22da3 | ||
|
|
8b882ca3c9 | ||
|
|
1078610066 | ||
|
|
d23dbc77e4 |
33
.github/workflows/python-app.yml
vendored
Normal file
33
.github/workflows/python-app.yml
vendored
Normal file
@@ -0,0 +1,33 @@
|
||||
# This workflow will install Python dependencies, run tests and lint with a single version of Python
|
||||
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions
|
||||
|
||||
name: Python application
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ develop ]
|
||||
pull_request:
|
||||
branches: [ develop ]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: Set up Python 3.6
|
||||
uses: actions/setup-python@v2
|
||||
with:
|
||||
python-version: 3.6
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
python -m pip install --upgrade pip
|
||||
pip install flake8==2.5.4 pytest
|
||||
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
|
||||
- name: Lint with flake8
|
||||
run: |
|
||||
python setup.py lint
|
||||
- name: Test with pytest
|
||||
run: |
|
||||
python setup.py test
|
||||
31
.github/workflows/python-publish.yml
vendored
Normal file
31
.github/workflows/python-publish.yml
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
# This workflow will upload a Python Package using Twine when a release is created
|
||||
# For more information see: https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries
|
||||
|
||||
name: Upload Python Package
|
||||
|
||||
on:
|
||||
release:
|
||||
types: [created]
|
||||
|
||||
jobs:
|
||||
deploy:
|
||||
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: Set up Python
|
||||
uses: actions/setup-python@v2
|
||||
with:
|
||||
python-version: '3.x'
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
python -m pip install --upgrade pip
|
||||
pip install setuptools wheel twine
|
||||
- name: Build and publish
|
||||
env:
|
||||
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
|
||||
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
|
||||
run: |
|
||||
python setup.py sdist bdist_wheel
|
||||
twine upload dist/*
|
||||
1
.gitignore
vendored
1
.gitignore
vendored
@@ -7,3 +7,4 @@
|
||||
/dist
|
||||
/MANIFEST
|
||||
/venv
|
||||
build/
|
||||
|
||||
18
README.rst
18
README.rst
@@ -1,3 +1,21 @@
|
||||
|build| |version| |license| |downloads|
|
||||
|
||||
.. |build| image:: https://img.shields.io/github/workflow/status/matthewwithanm/python-markdownify/Python%20application/develop
|
||||
:alt: GitHub Workflow Status
|
||||
:target: https://github.com/matthewwithanm/python-markdownify/actions?query=workflow%3A%22Python+application%22
|
||||
|
||||
.. |version| image:: https://img.shields.io/pypi/v/markdownify
|
||||
:alt: Pypi version
|
||||
:target: https://pypi.org/project/markdownify/
|
||||
|
||||
.. |license| image:: https://img.shields.io/pypi/l/markdownify
|
||||
:alt: License
|
||||
:target: https://github.com/matthewwithanm/python-markdownify/blob/develop/LICENSE
|
||||
|
||||
.. |downloads| image:: https://pepy.tech/badge/markdownify
|
||||
:alt: Pypi Downloads
|
||||
:target: https://pepy.tech/project/markdownify
|
||||
|
||||
Installation
|
||||
============
|
||||
|
||||
|
||||
@@ -6,8 +6,6 @@ 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 ]+')
|
||||
FRAGMENT_ID = '__MARKDOWNIFY_WRAPPER__'
|
||||
wrapped = '<div id="%s">%%s</div>' % FRAGMENT_ID
|
||||
|
||||
|
||||
# Heading styles
|
||||
@@ -62,12 +60,8 @@ class MarkdownConverter(object):
|
||||
' convert, but not both.')
|
||||
|
||||
def convert(self, html):
|
||||
# We want to take advantage of the html5 parsing, but we don't actually
|
||||
# want a full document. Therefore, we'll mark our fragment with an id,
|
||||
# create the document, and extract the element with the id.
|
||||
html = wrapped % html
|
||||
soup = BeautifulSoup(html, 'html.parser')
|
||||
return self.process_tag(soup.find(id=FRAGMENT_ID), children_only=True)
|
||||
return self.process_tag(soup, children_only=True)
|
||||
|
||||
def process_tag(self, node, children_only=False):
|
||||
text = ''
|
||||
@@ -181,7 +175,11 @@ class MarkdownConverter(object):
|
||||
def convert_li(self, el, text):
|
||||
parent = el.parent
|
||||
if parent is not None and parent.name == 'ol':
|
||||
bullet = '%s.' % (parent.index(el) + 1)
|
||||
if parent.get("start"):
|
||||
start = int(parent.get("start"))
|
||||
else:
|
||||
start = 1
|
||||
bullet = '%s.' % (start + parent.index(el))
|
||||
else:
|
||||
depth = -1
|
||||
while el:
|
||||
|
||||
2
setup.py
2
setup.py
@@ -10,7 +10,7 @@ read = lambda filepath: codecs.open(filepath, 'r', 'utf-8').read()
|
||||
pkgmeta = {
|
||||
'__title__': 'markdownify',
|
||||
'__author__': 'Matthew Tretter',
|
||||
'__version__': '0.5.0',
|
||||
'__version__': '0.5.3',
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -123,6 +123,7 @@ def test_i():
|
||||
|
||||
def test_ol():
|
||||
assert md('<ol><li>a</li><li>b</li></ol>') == '\n1. a\n2. b\n\n'
|
||||
assert md('<ol start="3"><li>a</li><li>b</li></ol>') == '\n3. a\n4. b\n\n'
|
||||
|
||||
|
||||
def test_p():
|
||||
@@ -156,3 +157,7 @@ def test_bullets():
|
||||
def test_img():
|
||||
assert md('<img src="/path/to/img.jpg" alt="Alt text" title="Optional title" />') == ''
|
||||
assert md('<img src="/path/to/img.jpg" alt="Alt text" />') == ''
|
||||
|
||||
|
||||
def test_div():
|
||||
assert md('Hello</div> World') == 'Hello World'
|
||||
|
||||
Reference in New Issue
Block a user