Repository: matthewwithanm/python-markdownify

Issue:
Add a blank line between table captions and table content
Currently, table `<caption>` elements are placed directly adjacent to the table content:

```python
import markdownify

html = """\
<table>
 <caption>Table caption</caption>
 <thead><tr><th>Header 1</th><th>Header 2</th></tr></thead>
 <tbody><tr><td>Body 1</td><td>Body 2</td></tr></tbody>
</table>
d
"""

print(markdownify.markdownify(html))
# Table caption
# | Header 1 | Header 2 |
# | --- | --- |
# | Body 1 | Body 2 |
```

However, Pandoc requires a blank line before the table content to avoid ambiguity:

```
$ pandoc --wrap=none test.md --to html
<p>Table caption | Header 1 | Header 2 | | — | — | | Body 1 | Body 2 |</p>
```

To resolve this, `<caption>` elements could include an additional newline after them.

Discussion:

Patch:
diff --git a/markdownify/__init__.py b/markdownify/__init__.py
index 3272ce5..cadd2bd 100644
--- a/markdownify/__init__.py
+++ b/markdownify/__init__.py
@@ -442,7 +442,7 @@ class MarkdownConverter(object):
         return '\n\n' + text + '\n'
 
     def convert_caption(self, el, text, convert_as_inline):
-        return text + '\n'
+        return text + '\n\n'
 
     def convert_figcaption(self, el, text, convert_as_inline):
         return '\n\n' + text + '\n\n'


Test patch:
diff --git a/tests/test_tables.py b/tests/test_tables.py
index fc6eee6..dcf9ad7 100644
--- a/tests/test_tables.py
+++ b/tests/test_tables.py
@@ -249,6 +249,6 @@ def test_table():
     assert md(table_missing_text) == '\n\n|  | Lastname | Age |\n| --- | --- | --- |\n| Jill |  | 50 |\n| Eve | Jackson | 94 |\n\n'
     assert md(table_missing_head) == '\n\n| Firstname | Lastname | Age |\n| --- | --- | --- |\n| Jill | Smith | 50 |\n| Eve | Jackson | 94 |\n\n'
     assert md(table_body) == '\n\n| Firstname | Lastname | Age |\n| --- | --- | --- |\n| Jill | Smith | 50 |\n| Eve | Jackson | 94 |\n\n'
-    assert md(table_with_caption) == 'TEXT\n\nCaption\n| Firstname | Lastname | Age |\n| --- | --- | --- |\n\n'
+    assert md(table_with_caption) == 'TEXT\n\nCaption\n\n| Firstname | Lastname | Age |\n| --- | --- | --- |\n\n'
     assert md(table_with_colspan) == '\n\n| Name | | Age |\n| --- | --- | --- |\n| Jill | Smith | 50 |\n| Eve | Jackson | 94 |\n\n'
     assert md(table_with_undefined_colspan) == '\n\n| Name | Age |\n| --- | --- |\n| Jill | Smith |\n\n'