Skip to content

Commit eb0330b

Browse files
committed
Merge branch 'develop'
2 parents 28793ac + ddda696 commit eb0330b

File tree

4 files changed

+27
-5
lines changed

4 files changed

+27
-5
lines changed

README.rst

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,14 @@ Convert some HTML to Markdown:
3232
from markdownify import markdownify as md
3333
md('<b>Yay</b> <a href="http://github.com">GitHub</a>') # > '**Yay** [GitHub](http://github.com)'
3434
35-
Specify tags to exclude (blacklist):
35+
Specify tags to exclude:
3636

3737
.. code:: python
3838
3939
from markdownify import markdownify as md
4040
md('<b>Yay</b> <a href="http://github.com">GitHub</a>', strip=['a']) # > '**Yay** GitHub'
4141
42-
\...or specify the tags you want to include (whitelist):
42+
\...or specify the tags you want to include:
4343

4444
.. code:: python
4545
@@ -53,11 +53,11 @@ Options
5353
Markdownify supports the following options:
5454

5555
strip
56-
A list of tags to strip (blacklist). This option can't be used with the
56+
A list of tags to strip. This option can't be used with the
5757
``convert`` option.
5858

5959
convert
60-
A list of tags to convert (whitelist). This option can't be used with the
60+
A list of tags to convert. This option can't be used with the
6161
``strip`` option.
6262

6363
autolinks
@@ -110,6 +110,18 @@ Options may be specified as kwargs to the ``markdownify`` function, or as a
110110
nested ``Options`` class in ``MarkdownConverter`` subclasses.
111111

112112

113+
Converting BeautifulSoup objects
114+
================================
115+
116+
.. code:: python
117+
118+
from markdownify import MarkdownConverter
119+
120+
# Create shorthand method for conversion
121+
def md(soup, **options):
122+
return ImageBlockConverter(**options).convert_soup(soup)
123+
124+
113125
Creating Custom Converters
114126
==========================
115127

markdownify/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@ def __init__(self, **options):
9696

9797
def convert(self, html):
9898
soup = BeautifulSoup(html, 'html.parser')
99+
return self.convert_soup(soup)
100+
101+
def convert_soup(self, soup):
99102
return self.process_tag(soup, convert_as_inline=False, children_only=True)
100103

101104
def process_tag(self, node, convert_as_inline, children_only=False):

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
pkgmeta = {
1111
'__title__': 'markdownify',
1212
'__author__': 'Matthew Tretter',
13-
'__version__': '0.10.2',
13+
'__version__': '0.10.3',
1414
}
1515

1616

tests/test_custom_converter.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from markdownify import MarkdownConverter
2+
from bs4 import BeautifulSoup
23

34

45
class ImageBlockConverter(MarkdownConverter):
@@ -16,3 +17,9 @@ def md(html, **options):
1617

1718
assert md('<img src="/path/to/img.jpg" alt="Alt text" title="Optional title" />') == '![Alt text](/path/to/img.jpg "Optional title")\n\n'
1819
assert md('<img src="/path/to/img.jpg" alt="Alt text" />') == '![Alt text](/path/to/img.jpg)\n\n'
20+
21+
22+
def test_soup():
23+
html = '<b>test</b>'
24+
soup = BeautifulSoup(html, 'html.parser')
25+
assert MarkdownConverter().convert_soup(soup) == '**test**'

0 commit comments

Comments
 (0)