nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: matthewwithanm/python-markdownify
Pull request #104 (2024-01-15 14:11:29)

improve text normalization/escaping for preformatted/code contexts
This fixes the following:

* #97
* #101
* #102

The fix uses Beautiful Soup's  `find_parent()` method to see if any containing element up the parent/ancestor tree matches the specified pattern.


Patch:
diff --git a/markdownify/__init__.py b/markdownify/__init__.py
index e15ecd4..bf765ec 100644
--- a/markdownify/__init__.py
+++ b/markdownify/__init__.py
@@ -152,13 +152,12 @@ class MarkdownConverter(object):
     def process_text(self, el):
         text = six.text_type(el) or ''
 
-        # dont remove any whitespace when handling pre or code in pre
-        if not (el.parent.name == 'pre'
-                or (el.parent.name == 'code'
-                    and el.parent.parent.name == 'pre')):
+        # normalize whitespace if we're not inside a preformatted element
+        if not el.find_parent('pre'):
             text = whitespace_re.sub(' ', text)
 
-        if el.parent.name != 'code' and el.parent.name != 'pre':
+        # escape special characters if we're not inside a preformatted or code element
+        if not el.find_parent(['pre', 'code', 'kbd', 'samp']):
             text = self.escape(text)
 
         # remove trailing whitespaces if any of the following condition is true:


Test patch:
diff --git a/tests/test_conversions.py b/tests/test_conversions.py
index da78649..1ecaf3c 100644
--- a/tests/test_conversions.py
+++ b/tests/test_conversions.py
@@ -70,7 +70,12 @@ def test_br():
 
 def test_code():
     inline_tests('code', '`')
-    assert md('<code>this_should_not_escape</code>') == '`this_should_not_escape`'
+    assert md('<code>*this_should_not_escape*</code>') == '`*this_should_not_escape*`'
+    assert md('<kbd>*this_should_not_escape*</kbd>') == '`*this_should_not_escape*`'
+    assert md('<samp>*this_should_not_escape*</samp>') == '`*this_should_not_escape*`'
+    assert md('<code><span>*this_should_not_escape*</span></code>') == '`*this_should_not_escape*`'
+    assert md('<code>this  should\t\tnormalize</code>') == '`this should normalize`'
+    assert md('<code><span>this  should\t\tnormalize</span></code>') == '`this should normalize`'
 
 
 def test_del():
@@ -187,7 +192,10 @@ def test_p():
 def test_pre():
     assert md('<pre>test\n    foo\nbar</pre>') == '\n```\ntest\n    foo\nbar\n```\n'
     assert md('<pre><code>test\n    foo\nbar</code></pre>') == '\n```\ntest\n    foo\nbar\n```\n'
-    assert md('<pre>this_should_not_escape</pre>') == '\n```\nthis_should_not_escape\n```\n'
+    assert md('<pre>*this_should_not_escape*</pre>') == '\n```\n*this_should_not_escape*\n```\n'
+    assert md('<pre><span>*this_should_not_escape*</span></pre>') == '\n```\n*this_should_not_escape*\n```\n'
+    assert md('<pre>\t\tthis  should\t\tnot  normalize</pre>') == '\n```\n\t\tthis  should\t\tnot  normalize\n```\n'
+    assert md('<pre><span>\t\tthis  should\t\tnot  normalize</span></pre>') == '\n```\n\t\tthis  should\t\tnot  normalize\n```\n'
 
 
 def test_s():
Repository: matthewwithanm/python-markdownify
Pull request #111 (2024-02-18 22:50:39)

Add no css example to readme
Adresses #100 in the readme


Patch:
diff --git a/README.rst b/README.rst
index 06f319b..21a5972 100644
--- a/README.rst
+++ b/README.rst
@@ -173,6 +173,22 @@ change:
     def md(html, **options):
         return ImageBlockConverter(**options).convert(html)
 
+.. code:: python
+
+    from markdownify import MarkdownConverter
+
+    class NoCssConverter(MarkdownConverter):
+        """
+        Create a custom MarkdownConverter that removes the CSS code by ignoring the `style` tag
+        """
+        def convert_style(self, el, text, convert_as_inline):
+            return ''
+
+    # Create shorthand method for conversion
+    def md(html, **options):
+        return NoCssConverter(**options).convert(html)
+
+
 
 Command Line Interface
 ======================
diff --git a/markdownify/__init__.py b/markdownify/__init__.py
index bf765ec..151a222 100644
--- a/markdownify/__init__.py
+++ b/markdownify/__init__.py
@@ -350,6 +350,12 @@ class MarkdownConverter(object):
 
         return '\n```%s\n%s\n```\n' % (code_language, text)
 
+    def convert_script(self, el, text, convert_as_inline):
+        return ''
+
+    def convert_style(self, el, text, convert_as_inline):
+        return ''
+
     convert_s = convert_del
 
     convert_strong = convert_b


Test patch:
diff --git a/tests/test_conversions.py b/tests/test_conversions.py
index 1ecaf3c..5c6ec06 100644
--- a/tests/test_conversions.py
+++ b/tests/test_conversions.py
@@ -198,6 +198,14 @@ def test_pre():
     assert md('<pre><span>\t\tthis  should\t\tnot  normalize</span></pre>') == '\n```\n\t\tthis  should\t\tnot  normalize\n```\n'
 
 
+def test_script():
+    assert md('foo <script>var foo=42;</script> bar') == 'foo  bar'
+
+
+def test_style():
+    assert md('foo <style>h1 { font-size: larger }</style> bar') == 'foo  bar'
+
+
 def test_s():
     inline_tests('s', '~~')
Repository: matthewwithanm/python-markdownify
Pull request #112 (2024-02-19 20:26:26)

ignore script and style content (such as css and javascript)

chrispy-snps: @AlexVonB, @matthewwithanm - this looks good to me. `pytest` is clean (and tests this change).

Patch:
diff --git a/markdownify/__init__.py b/markdownify/__init__.py
index bf765ec..151a222 100644
--- a/markdownify/__init__.py
+++ b/markdownify/__init__.py
@@ -350,6 +350,12 @@ class MarkdownConverter(object):
 
         return '\n```%s\n%s\n```\n' % (code_language, text)
 
+    def convert_script(self, el, text, convert_as_inline):
+        return ''
+
+    def convert_style(self, el, text, convert_as_inline):
+        return ''
+
     convert_s = convert_del
 
     convert_strong = convert_b


Test patch:
diff --git a/tests/test_conversions.py b/tests/test_conversions.py
index 1ecaf3c..5c6ec06 100644
--- a/tests/test_conversions.py
+++ b/tests/test_conversions.py
@@ -198,6 +198,14 @@ def test_pre():
     assert md('<pre><span>\t\tthis  should\t\tnot  normalize</span></pre>') == '\n```\n\t\tthis  should\t\tnot  normalize\n```\n'
 
 
+def test_script():
+    assert md('foo <script>var foo=42;</script> bar') == 'foo  bar'
+
+
+def test_style():
+    assert md('foo <style>h1 { font-size: larger }</style> bar') == 'foo  bar'
+
+
 def test_s():
     inline_tests('s', '~~')
Repository: matthewwithanm/python-markdownify
Pull request #136 (2024-07-12 17:10:48)

for convert_* functions, allow for tags with special characters in their name (like "subtag-name")
html tags may contain symbols like `:` and `-` which are not suitable for the python function names
simple name converter allows usage of the methods for tags like `tag:subtag-name`

chrispy-snps: @Fess-AKA-DeadMonk - thanks for submitting this pull request!

I have two suggestions:

1. Include `[` and `]` in the translation set (as `BeautifulSoup` objects have a `name` value of `[document]`).

2. Move the creation of the translation dictionary to be a global value so it is only computed once:

   ```
   tag_name_translation = ''.maketrans(':-[]', '____')
   ```
chrispy-snps: @Fess-AKA-DeadMonk - if you are able to make the changes suggested above, we can review and approve this pull request. Thanks!

Patch:
diff --git a/markdownify/__init__.py b/markdownify/__init__.py
index 2360210..8e90a61 100644
--- a/markdownify/__init__.py
+++ b/markdownify/__init__.py
@@ -172,7 +172,8 @@ class MarkdownConverter(object):
                 text = text_strip + newlines + next_text_strip
 
         if not children_only:
-            convert_fn = getattr(self, 'convert_%s' % node.name, None)
+            fn_name = 'convert_%s' % node.name.translate(''.maketrans(':-', '__'))
+            convert_fn = getattr(self, fn_name, None)
             if convert_fn and self.should_convert_tag(node.name):
                 text = convert_fn(node, text, convert_as_inline)
 


Test patch:
diff --git a/tests/test_custom_converter.py b/tests/test_custom_converter.py
index a3e33ac..adc83f7 100644
--- a/tests/test_custom_converter.py
+++ b/tests/test_custom_converter.py
@@ -2,22 +2,29 @@ from markdownify import MarkdownConverter
 from bs4 import BeautifulSoup
 
 
-class ImageBlockConverter(MarkdownConverter):
+class UnitTestConverter(MarkdownConverter):
     """
-    Create a custom MarkdownConverter that adds two newlines after an image
+    Create a custom MarkdownConverter for unit tests
     """
     def convert_img(self, el, text, convert_as_inline):
+        """Add two newlines after an image"""
         return super().convert_img(el, text, convert_as_inline) + '\n\n'
 
+    def convert_custom_tag(self, el, text, convert_as_inline):
+        """Ensure conversion function is found for tags with special characters in name"""
+        return "FUNCTION USED: %s" % text
 
-def test_img():
+
+def test_custom_conversion_functions():
     # Create shorthand method for conversion
     def md(html, **options):
-        return ImageBlockConverter(**options).convert(html)
+        return UnitTestConverter(**options).convert(html)
 
     assert md('<img src="/path/to/img.jpg" alt="Alt text" title="Optional title" />') == '![Alt text](/path/to/img.jpg "Optional title")\n\n'
     assert md('<img src="/path/to/img.jpg" alt="Alt text" />') == '![Alt text](/path/to/img.jpg)\n\n'
 
+    assert md("<custom-tag>text</custom-tag>") == "FUNCTION USED: text"
+
 
 def test_soup():
     html = '<b>test</b>'
Repository: matthewwithanm/python-markdownify
Pull request #183 (2025-02-01 14:03:12)

when computing <ol><li> numbering, ignore non-<li> previous siblings
Currently, numbering for `<li>` items inside `<ol>` count *all* previous siblings when computing the number:

```python
import markdownify

html = """
<ol>
  <!--comment-->
  <li>a</li>
  <div/>
  <li>b</li>
</ol>
"""

print(markdownify.MarkdownConverter().convert(html))
# 2. a
# 4. b
```

This pull request updates the code to consider only preceding `<li>` elements:

```python
print(markdownify.MarkdownConverter().convert(html))
# 1. a
# 2. b
```

A unit test is added to check this case.


Patch:
diff --git a/markdownify/__init__.py b/markdownify/__init__.py
index 7d14fe7..93a889f 100644
--- a/markdownify/__init__.py
+++ b/markdownify/__init__.py
@@ -135,14 +135,13 @@ class MarkdownConverter(object):
     def process_tag(self, node, convert_as_inline):
         text = ''
 
-        # markdown headings or cells can't include
-        # block elements (elements w/newlines)
-        isHeading = html_heading_re.match(node.name) is not None
-        isCell = node.name in ['td', 'th']
-        convert_children_as_inline = convert_as_inline
-
-        if isHeading or isCell:
-            convert_children_as_inline = True
+        # For Markdown headings and table cells, convert children as inline
+        # (so that block element children do not produce newlines).
+        convert_children_as_inline = (
+            convert_as_inline  # propagated from parent
+            or html_heading_re.match(node.name) is not None  # headings
+            or node.name in ['td', 'th']  # table cells
+        )
 
         # Remove whitespace-only textnodes just before, after or
         # inside block-level elements.
@@ -444,7 +443,7 @@ class MarkdownConverter(object):
                 start = int(parent.get("start"))
             else:
                 start = 1
-            bullet = '%s.' % (start + parent.index(el))
+            bullet = '%s.' % (start + len(el.find_previous_siblings('li')))
         else:
             depth = -1
             while el:


Test patch:
diff --git a/tests/test_lists.py b/tests/test_lists.py
index 6b320ca..e9480ab 100644
--- a/tests/test_lists.py
+++ b/tests/test_lists.py
@@ -42,6 +42,7 @@ nested_ols = """
 
 def test_ol():
     assert md('<ol><li>a</li><li>b</li></ol>') == '\n\n1. a\n2. b\n'
+    assert md('<ol><!--comment--><li>a</li><span/><li>b</li></ol>') == '\n\n1. a\n2. b\n'
     assert md('<ol start="3"><li>a</li><li>b</li></ol>') == '\n\n3. a\n4. b\n'
     assert md('foo<ol start="3"><li>a</li><li>b</li></ol>bar') == 'foo\n\n3. a\n4. b\n\nbar'
     assert md('<ol start="-1"><li>a</li><li>b</li></ol>') == '\n\n1. a\n2. b\n'
Repository: matthewwithanm/python-markdownify
Pull request #189 (2025-02-08 04:58:23)

Support `video` tag with `poster` attribute
Hi,
This PR adds support for the `<video>` tag by converting the `poster` attribute into a Markdown image.
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/video

Thanks.

## Summary (Copilot generated :octocat:)

This pull request adds support for converting HTML video elements to Markdown format in the `markdownify` library. The changes include a new conversion method and corresponding tests.

### New feature: Video element conversion

* [`markdownify/__init__.py`](diffhunk://#diff-a790e50462779b502322f094b8ac42dd0cc2501d827c5d00df702cfbe95d1c2dR466-R478): Added a `convert_video` method to handle the conversion of HTML video elements to Markdown. This method checks for the presence of `src` and `poster` attributes and formats the output accordingly.

### Testing the new feature

* [`tests/test_conversions.py`](diffhunk://#diff-9367b36e95d87e540dc5f108066635f93ae0c52f54856a3e3b720b4fc72060a7R245-R250): Added a `test_video` function to verify the correct conversion of video elements with different attributes to Markdown.


Patch:
diff --git a/markdownify/__init__.py b/markdownify/__init__.py
index 5d21506..3763a49 100644
--- a/markdownify/__init__.py
+++ b/markdownify/__init__.py
@@ -538,6 +538,24 @@ class MarkdownConverter(object):
 
         return '![%s](%s%s)' % (alt, src, title_part)
 
+    def convert_video(self, el, text, parent_tags):
+        if ('_inline' in parent_tags
+                and el.parent.name not in self.options['keep_inline_images_in']):
+            return text
+        src = el.attrs.get('src', None) or ''
+        if not src:
+            sources = el.find_all('source', attrs={'src': True})
+            if sources:
+                src = sources[0].attrs.get('src', None) or ''
+        poster = el.attrs.get('poster', None) or ''
+        if src and poster:
+            return '[![%s](%s)](%s)' % (text, poster, src)
+        if src:
+            return '[%s](%s)' % (text, src)
+        if poster:
+            return '![%s](%s)' % (text, poster)
+        return text
+
     def convert_list(self, el, text, parent_tags):
 
         # Converting a list to inline is undefined.


Test patch:
diff --git a/tests/test_conversions.py b/tests/test_conversions.py
index e851ac2..b406a9f 100644
--- a/tests/test_conversions.py
+++ b/tests/test_conversions.py
@@ -243,6 +243,14 @@ def test_img():
     assert md('<img src="/path/to/img.jpg" alt="Alt text" />') == '![Alt text](/path/to/img.jpg)'
 
 
+def test_video():
+    assert md('<video src="/path/to/video.mp4" poster="/path/to/img.jpg">text</video>') == '[![text](/path/to/img.jpg)](/path/to/video.mp4)'
+    assert md('<video src="/path/to/video.mp4">text</video>') == '[text](/path/to/video.mp4)'
+    assert md('<video><source src="/path/to/video.mp4"/>text</video>') == '[text](/path/to/video.mp4)'
+    assert md('<video poster="/path/to/img.jpg">text</video>') == '![text](/path/to/img.jpg)'
+    assert md('<video>text</video>') == 'text'
+
+
 def test_kbd():
     inline_tests('kbd', '`')
Repository: matthewwithanm/python-markdownify
Pull request #217 (2025-04-27 12:07:56)

Add conversion support for <q> tags
From this issue: https://github.com/matthewwithanm/python-markdownify/issues/216

https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/q

HTML that looks like this:

```html
Here is <q>A Quote</q> from someone.
```

should be rendered as:

```
Here is “A Quote“ from someone.
```

Technically, the quotes rendered from `<q>` are dependent on the browser lang attribute 

https://developer.mozilla.org/en-US/docs/Web/CSS/quotes#specifications

```html
<ul>
  <li lang="fr">
    <q>Ceci est une citation française.</q>
  </li>
  <li lang="de">
    <q>Dies ist ein deutsches Zitat</q>
  </li>
  <li lang="en">
    <q>This is an English quote.</q>
  </li>
</ul>
```

```
- «Ceci est une citation française.»
- „Dies ist ein deutsches Zitat“
- “This is an English quote.”
```

But this PR uses simple straight quotes


chrispy-snps: Thank you @colinrobinsonuib! Can you please also add a unit test in tests/test_conversions.py?

Patch:
diff --git a/markdownify/__init__.py b/markdownify/__init__.py
index 780761c..a43f3a7 100644
--- a/markdownify/__init__.py
+++ b/markdownify/__init__.py
@@ -650,6 +650,9 @@ class MarkdownConverter(object):
 
         return '\n\n```%s\n%s\n```\n\n' % (code_language, text)
 
+    def convert_q(self, el, text, parent_tags):
+        return '"' + text + '"'
+
     def convert_script(self, el, text, parent_tags):
         return ''
 


Test patch:
diff --git a/tests/test_conversions.py b/tests/test_conversions.py
index 27951ee..6145411 100644
--- a/tests/test_conversions.py
+++ b/tests/test_conversions.py
@@ -305,6 +305,11 @@ def test_pre():
     assert md("<p>foo</p>\n<pre>bar</pre>\n</p>baz</p>", sub_symbol="^") == "\n\nfoo\n\n```\nbar\n```\n\nbaz"
 
 
+def test_q():
+    assert md('foo <q>quote</q> bar') == 'foo "quote" bar'
+    assert md('foo <q cite="https://example.com">quote</q> bar') == 'foo "quote" bar'
+
+
 def test_script():
     assert md('foo <script>var foo=42;</script> bar') == 'foo  bar'
Repository: matthewwithanm/python-markdownify
Pull request #22 (2020-08-11 09:43:32)

Support the start attribute for ordered lists


Patch:
diff --git a/markdownify/__init__.py b/markdownify/__init__.py
index 56854e8..33d5b8f 100644
--- a/markdownify/__init__.py
+++ b/markdownify/__init__.py
@@ -181,7 +181,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:


Test patch:
diff --git a/tests/test_conversions.py b/tests/test_conversions.py
index b8487e5..9e7be24 100644
--- a/tests/test_conversions.py
+++ b/tests/test_conversions.py
@@ -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():
Repository: matthewwithanm/python-markdownify
Pull request #24 (2020-08-31 11:17:13)

Fix parsing corrupt html
Remove the wrapping fixes parsing of not opened tags like my test.

I wondered why the html was wrapped. I debugged it and saw no difference. Even all tests pass


Patch:
diff --git a/markdownify/__init__.py b/markdownify/__init__.py
index 33d5b8f..2d5daf1 100644
--- a/markdownify/__init__.py
+++ b/markdownify/__init__.py
@@ -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 = ''


Test patch:
diff --git a/tests/test_conversions.py b/tests/test_conversions.py
index 9e7be24..12ce36b 100644
--- a/tests/test_conversions.py
+++ b/tests/test_conversions.py
@@ -157,3 +157,7 @@ def test_bullets():
 def test_img():
     assert md('<img src="/path/to/img.jpg" alt="Alt text" title="Optional title" />') == '![Alt text](/path/to/img.jpg "Optional title")'
     assert md('<img src="/path/to/img.jpg" alt="Alt text" />') == '![Alt text](/path/to/img.jpg)'
+
+
+def test_div():
+    assert md('Hello</div> World') == 'Hello World'
Repository: matthewwithanm/python-markdownify
Pull request #27 (2020-11-25 20:29:10)

Add methods for code, samp, kbd tags
Add methods and tests for inline tags `<code>` (also `<samp>` and `<kbd>` using the same base method).


Patch:
diff --git a/markdownify/__init__.py b/markdownify/__init__.py
index 2d5daf1..44d729d 100644
--- a/markdownify/__init__.py
+++ b/markdownify/__init__.py
@@ -143,6 +143,18 @@ class MarkdownConverter(object):
             return ''
         return '%s*%s*%s' % (prefix, text, suffix)
 
+    def convert_code(self, el, text):
+        prefix, suffix, text = chomp(text)
+        if not text:
+            return ''
+        return '%s`%s`%s' % (prefix, text, suffix)
+
+    def convert_samp(self, el, text):
+        return self.convert_code(el, text)
+
+    def convert_kbd(self, el, text):
+        return self.convert_code(el, text)
+
     def convert_hn(self, n, el, text):
         style = self.options['heading_style']
         text = text.rstrip()


Test patch:
diff --git a/tests/test_advanced.py b/tests/test_advanced.py
index 4c480d7..7b62836 100644
--- a/tests/test_advanced.py
+++ b/tests/test_advanced.py
@@ -4,3 +4,10 @@ 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_code_with_tricky_content():
+    assert md('<code>></code>') == "`>`"
+    assert md('<code>/home/</code><b>username</b>') == "`/home/`**username**"
+    assert md('First line <code>blah blah<br />blah blah</code> second line') \
+        == "First line `blah blah  \nblah blah` second line"
diff --git a/tests/test_conversions.py b/tests/test_conversions.py
index 12ce36b..5b7db1f 100644
--- a/tests/test_conversions.py
+++ b/tests/test_conversions.py
@@ -94,6 +94,27 @@ def test_em_spaces():
     assert md('foo <em></em> bar') == 'foo  bar'
 
 
+def code_samp_kbd_tests(tag):
+    # Basically re-use test_em() and test_em_spaces(),
+    assert md(f'<{tag}>Hello</{tag}>') == '`Hello`'
+    assert md(f'foo <{tag}>Hello</{tag}> bar') == 'foo `Hello` bar'
+    assert md(f'foo<{tag}> Hello</{tag}> bar') == 'foo `Hello` bar'
+    assert md(f'foo <{tag}>Hello </{tag}>bar') == 'foo `Hello` bar'
+    assert md(f'foo <{tag}></{tag}> bar') in ['foo  bar', 'foo bar']  # Either is OK
+
+
+def test_code():
+    code_samp_kbd_tests('code')
+
+
+def test_samp():
+    code_samp_kbd_tests('samp')
+
+
+def test_kbd():
+    code_samp_kbd_tests('kbd')
+
+
 def test_h1():
     assert md('<h1>Hello</h1>') == 'Hello\n=====\n\n'
Repository: matthewwithanm/python-markdownify
Pull request #40 (2021-04-29 20:42:29)

Add conversion for hr element


Patch:
diff --git a/markdownify/__init__.py b/markdownify/__init__.py
index 0b2a620..eeaaf74 100644
--- a/markdownify/__init__.py
+++ b/markdownify/__init__.py
@@ -269,6 +269,9 @@ class MarkdownConverter(object):
                 continue
         return '\n'.join(text_data)
 
+    def convert_hr(self, el, text, convert_as_inline):
+        return '\n\n---\n\n'
+
 
 def markdownify(html, **options):
     return MarkdownConverter(**options).convert(html)


Test patch:
diff --git a/tests/test_conversions.py b/tests/test_conversions.py
index 6dcf9a6..9d25940 100644
--- a/tests/test_conversions.py
+++ b/tests/test_conversions.py
@@ -229,7 +229,9 @@ def test_hn_nested_img():
 
 
 def test_hr():
-    assert md('<hr>hr</hr>') == 'hr'
+    assert md('Hello<hr>World') == 'Hello\n\n---\n\nWorld'
+    assert md('Hello<hr />World') == 'Hello\n\n---\n\nWorld'
+    assert md('<p>Hello</p>\n<hr>\n<p>World</p>') == 'Hello\n\n\n\n\n---\n\n\nWorld\n\n'
 
 
 def test_head():