Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
99875683ac | ||
|
|
dbd9f3f3d2 | ||
|
|
0fdeb1ff6e | ||
|
|
eaeb0603eb | ||
|
|
6a2f3a4b42 |
@@ -101,7 +101,7 @@ nested ``Options`` class in ``MarkdownConverter`` subclasses.
|
|||||||
|
|
||||||
|
|
||||||
Creating Custom Converters
|
Creating Custom Converters
|
||||||
=========================
|
==========================
|
||||||
|
|
||||||
If you have a special usecase that calls for a special conversion, you can
|
If you have a special usecase that calls for a special conversion, you can
|
||||||
always inherit from ``MarkdownConverter`` and override the method you want to
|
always inherit from ``MarkdownConverter`` and override the method you want to
|
||||||
|
|||||||
@@ -96,11 +96,14 @@ class MarkdownConverter(object):
|
|||||||
|
|
||||||
def process_tag(self, node, convert_as_inline, children_only=False):
|
def process_tag(self, node, convert_as_inline, children_only=False):
|
||||||
text = ''
|
text = ''
|
||||||
# markdown headings can't include block elements (elements w/newlines)
|
|
||||||
|
# markdown headings or cells can't include
|
||||||
|
# block elements (elements w/newlines)
|
||||||
isHeading = html_heading_re.match(node.name) is not None
|
isHeading = html_heading_re.match(node.name) is not None
|
||||||
|
isCell = node.name in ['td', 'th']
|
||||||
convert_children_as_inline = convert_as_inline
|
convert_children_as_inline = convert_as_inline
|
||||||
|
|
||||||
if not children_only and isHeading:
|
if not children_only and (isHeading or isCell):
|
||||||
convert_children_as_inline = True
|
convert_children_as_inline = True
|
||||||
|
|
||||||
# Remove whitespace-only textnodes in purely nested nodes
|
# Remove whitespace-only textnodes in purely nested nodes
|
||||||
@@ -200,8 +203,6 @@ class MarkdownConverter(object):
|
|||||||
prefix, suffix, text = chomp(text)
|
prefix, suffix, text = chomp(text)
|
||||||
if not text:
|
if not text:
|
||||||
return ''
|
return ''
|
||||||
if convert_as_inline:
|
|
||||||
return text
|
|
||||||
href = el.get('href')
|
href = el.get('href')
|
||||||
title = el.get('title')
|
title = el.get('title')
|
||||||
# For the replacement see #29: text nodes underscores are escaped
|
# For the replacement see #29: text nodes underscores are escaped
|
||||||
|
|||||||
2
setup.py
2
setup.py
@@ -10,7 +10,7 @@ read = lambda filepath: codecs.open(filepath, 'r', 'utf-8').read()
|
|||||||
pkgmeta = {
|
pkgmeta = {
|
||||||
'__title__': 'markdownify',
|
'__title__': 'markdownify',
|
||||||
'__author__': 'Matthew Tretter',
|
'__author__': 'Matthew Tretter',
|
||||||
'__version__': '0.9.1',
|
'__version__': '0.9.3',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -39,6 +39,25 @@ table_with_html_content = """<table>
|
|||||||
</table>"""
|
</table>"""
|
||||||
|
|
||||||
|
|
||||||
|
table_with_paragraphs = """<table>
|
||||||
|
<tr>
|
||||||
|
<th>Firstname</th>
|
||||||
|
<th><p>Lastname</p></th>
|
||||||
|
<th>Age</th>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td><p>Jill</p></td>
|
||||||
|
<td><p>Smith</p></td>
|
||||||
|
<td><p>50</p></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>Eve</td>
|
||||||
|
<td>Jackson</td>
|
||||||
|
<td>94</td>
|
||||||
|
</tr>
|
||||||
|
</table>"""
|
||||||
|
|
||||||
|
|
||||||
table_with_header_column = """<table>
|
table_with_header_column = """<table>
|
||||||
<tr>
|
<tr>
|
||||||
<th>Firstname</th>
|
<th>Firstname</th>
|
||||||
@@ -124,6 +143,7 @@ table_missing_head = """<table>
|
|||||||
def test_table():
|
def test_table():
|
||||||
assert md(table) == '\n\n| Firstname | Lastname | Age |\n| --- | --- | --- |\n| Jill | Smith | 50 |\n| Eve | Jackson | 94 |\n\n'
|
assert md(table) == '\n\n| Firstname | Lastname | Age |\n| --- | --- | --- |\n| Jill | Smith | 50 |\n| Eve | Jackson | 94 |\n\n'
|
||||||
assert md(table_with_html_content) == '\n\n| Firstname | Lastname | Age |\n| --- | --- | --- |\n| **Jill** | *Smith* | [50](#) |\n| Eve | Jackson | 94 |\n\n'
|
assert md(table_with_html_content) == '\n\n| Firstname | Lastname | Age |\n| --- | --- | --- |\n| **Jill** | *Smith* | [50](#) |\n| Eve | Jackson | 94 |\n\n'
|
||||||
|
assert md(table_with_paragraphs) == '\n\n| Firstname | Lastname | Age |\n| --- | --- | --- |\n| Jill | Smith | 50 |\n| Eve | Jackson | 94 |\n\n'
|
||||||
assert md(table_with_header_column) == '\n\n| Firstname | Lastname | Age |\n| --- | --- | --- |\n| Jill | Smith | 50 |\n| Eve | Jackson | 94 |\n\n'
|
assert md(table_with_header_column) == '\n\n| Firstname | Lastname | Age |\n| --- | --- | --- |\n| Jill | Smith | 50 |\n| Eve | Jackson | 94 |\n\n'
|
||||||
assert md(table_head_body) == '\n\n| Firstname | Lastname | Age |\n| --- | --- | --- |\n| Jill | Smith | 50 |\n| Eve | Jackson | 94 |\n\n'
|
assert md(table_head_body) == '\n\n| Firstname | Lastname | Age |\n| --- | --- | --- |\n| Jill | Smith | 50 |\n| Eve | Jackson | 94 |\n\n'
|
||||||
assert md(table_missing_text) == '\n\n| | Lastname | Age |\n| --- | --- | --- |\n| Jill | | 50 |\n| Eve | Jackson | 94 |\n\n'
|
assert md(table_missing_text) == '\n\n| | Lastname | Age |\n| --- | --- | --- |\n| Jill | | 50 |\n| Eve | Jackson | 94 |\n\n'
|
||||||
|
|||||||
Reference in New Issue
Block a user