nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: matthewwithanm/python-markdownify
Pull request #43 (2021-05-10 21:46:28)

Fix missing whitespaces in <li> node
Fixed bug introduced in PR #23 .

```
<ul>
  <li>foo <a href="#">bar</a></li>
  <li>foo <b>bar</b> <i>space</i>.</li>
</ul>
```

is incorrectly converted to:
```
* foo[bar](#)
     ^
* foo**bar***space*.
     ^      ^
```

while it should be:
```
* foo [bar](#)
     ^
* foo **bar** *space*.
     ^       ^
```


Patch:
diff --git a/markdownify/__init__.py b/markdownify/__init__.py
index da04ebf..6230fb8 100644
--- a/markdownify/__init__.py
+++ b/markdownify/__init__.py
@@ -85,9 +85,17 @@ class MarkdownConverter(object):
             convert_children_as_inline = True
 
         # Remove whitespace-only textnodes in lists
-        if node.name in ['ol', 'ul', 'li']:
+        def is_list_node(el):
+            return el and el.name in ['ol', 'ul', 'li']
+
+        if is_list_node(node):
             for el in node.children:
-                if isinstance(el, NavigableString) and six.text_type(el).strip() == '':
+                # Only extract (remove) whitespace-only text node if any of the conditions is true:
+                # - el is the first element in its parent
+                # - el is the last element in its parent
+                # - el is adjacent to an list node
+                can_extract = not el.previous_sibling or not el.next_sibling or is_list_node(el.previous_sibling) or is_list_node(el.next_sibling)
+                if isinstance(el, NavigableString) and six.text_type(el).strip() == '' and can_extract:
                     el.extract()
 
         # Convert the children first
@@ -108,7 +116,10 @@ class MarkdownConverter(object):
 
     def process_text(self, el):
         text = six.text_type(el)
-        if el.parent.name == 'li':
+        # remove trailing whitespaces if any of the following condition is true:
+        # - current text node is the last node in li
+        # - current text node is followed by an embedded list
+        if el.parent.name == 'li' and (not el.next_sibling or el.next_sibling.name in ['ul', 'ol']):
             return escape(all_whitespace_re.sub(' ', text or '')).rstrip()
         return escape(whitespace_re.sub(' ', text or ''))
 


Test patch:
diff --git a/tests/test_conversions.py b/tests/test_conversions.py
index caac0fd..6663204 100644
--- a/tests/test_conversions.py
+++ b/tests/test_conversions.py
@@ -308,6 +308,10 @@ def test_bullets():
     assert md(nested_uls, bullets='-') == '\n- 1\n\t- a\n\t\t- I\n\t\t- II\n\t\t- III\n\t- b\n\t- c\n- 2\n- 3\n'
 
 
+def test_li_text():
+    assert md('<ul><li>foo <a href="#">bar</a></li><li>foo bar  </li><li>foo <b>bar</b>   <i>space</i>.</ul>') == '* foo [bar](#)\n* foo bar\n* foo **bar** *space*.\n'
+
+
 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)'
Repository: matthewwithanm/python-markdownify
Pull request #53 (2021-09-04 09:39:58)

Fixed issue #52 - added stripping of text to list


Patch:
diff --git a/markdownify/__init__.py b/markdownify/__init__.py
index 3d67a49..4d36bd6 100644
--- a/markdownify/__init__.py
+++ b/markdownify/__init__.py
@@ -314,7 +314,7 @@ class MarkdownConverter(object):
                 el = el.parent
             bullets = self.options['bullets']
             bullet = bullets[depth % len(bullets)]
-        return '%s %s\n' % (bullet, text or '')
+        return '%s %s\n' % (bullet, (text or '').strip())
 
     def convert_p(self, el, text, convert_as_inline):
         if convert_as_inline:


Test patch:
diff --git a/tests/test_lists.py b/tests/test_lists.py
index 08c82c7..5a04430 100644
--- a/tests/test_lists.py
+++ b/tests/test_lists.py
@@ -51,6 +51,14 @@ def test_nested_ols():
 
 def test_ul():
     assert md('<ul><li>a</li><li>b</li></ul>') == '* a\n* b\n'
+    assert md("""<ul>
+     <li>
+             a
+     </li>
+     <li> b </li>
+     <li>   c
+     </li>
+ </ul>""") == '* a\n* b\n* c\n'
 
 
 def test_inline_ul():
Repository: matthewwithanm/python-markdownify
Pull request #54 (2021-11-01 20:24:08)

Added language for multiline code
I've modified the code to add a parameter that enables Syntax Highlighting for multiline code and pre blocks.
This can be useful to force syntax highlighting for the whole markdown instead of having the generic markdown code block.
Example:
``` python
# Python code
md('<pre>test\n    foo\nbar</pre>',language='python') == '\n```python\ntest\n    foo\nbar\n```\n'
```
I've also added a new test to check if everything is working correctly.


Patch:
diff --git a/.gitignore b/.gitignore
index 8817941..100084d 100644
--- a/.gitignore
+++ b/.gitignore
@@ -8,3 +8,4 @@
 /MANIFEST
 /venv
 build/
+.vscode/settings.json
diff --git a/markdownify/__init__.py b/markdownify/__init__.py
index 4d36bd6..82e7fbd 100644
--- a/markdownify/__init__.py
+++ b/markdownify/__init__.py
@@ -76,6 +76,7 @@ class MarkdownConverter(object):
         strong_em_symbol = ASTERISK
         sub_symbol = ''
         sup_symbol = ''
+        language = None
 
     class Options(DefaultOptions):
         pass
@@ -324,7 +325,10 @@ class MarkdownConverter(object):
     def convert_pre(self, el, text, convert_as_inline):
         if not text:
             return ''
-        return '\n```\n%s\n```\n' % text
+        if not self.options['language']:
+            return '\n```\n%s\n```\n' % text
+        else:
+            return f'\n```{self.options["language"]}\n%s\n```\n' % text
 
     convert_s = convert_del
 


Test patch:
diff --git a/tests/test_conversions.py b/tests/test_conversions.py
index 0a5fba8..9b0d0f1 100644
--- a/tests/test_conversions.py
+++ b/tests/test_conversions.py
@@ -210,3 +210,7 @@ def test_sub():
 def test_sup():
     assert md('<sup>foo</sup>') == 'foo'
     assert md('<sup>foo</sup>', sup_symbol='^') == '^foo^'
+
+def test_lang():
+    assert md('<pre>test\n    foo\nbar</pre>',language='python') == '\n```python\ntest\n    foo\nbar\n```\n'
+    assert md('<pre><code>test\n    foo\nbar</code></pre>',language='javascript') == '\n```javascript\ntest\n    foo\nbar\n```\n'
Repository: brazilian-utils/brutils-python
Pull request #48 (2023-03-25 15:25:40)

refactor: improve imports usability for cnpj


Patch:
diff --git a/README.md b/README.md
index 84149a0..f64b346 100644
--- a/README.md
+++ b/README.md
@@ -30,10 +30,9 @@ pip install brutils
 ```
 # numbers only, formatted as strings
 
->>> from brutils import is_valid_cpf
+>>> from brutils import is_valid_cpf, is_valid_cnpj
 >>> is_valid_cpf('00011122233')
 False
->>> from brutils.cnpj import is_valid_cnpj
 >>> is_valid_cnpj('00111222000133')
 False
 ```
diff --git a/README_PT_BR.md b/README_PT_BR.md
index 8e4099a..a3e2d18 100644
--- a/README_PT_BR.md
+++ b/README_PT_BR.md
@@ -32,10 +32,9 @@ pip install brutils
 ```
 # somente numeros, em formato string
 
->>> from brutils import is_valid_cpf
+>>> from brutils import is_valid_cpf, is_valid_cnpj
 >>> is_valid_cpf('00011122233')
 False
->>> from brutils.cnpj import is_valid_cnpj
 >>> is_valid_cnpj('00111222000133')
 False
 ```
diff --git a/brutils/__init__.py b/brutils/__init__.py
index 00ddc61..8fa0305 100644
--- a/brutils/__init__.py
+++ b/brutils/__init__.py
@@ -1,1 +1,2 @@
 from brutils.cpf import is_valid as is_valid_cpf
+from brutils.cnpj import is_valid as is_valid_cnpj
diff --git a/brutils/cnpj.py b/brutils/cnpj.py
index 69f80df..7e25db9 100644
--- a/brutils/cnpj.py
+++ b/brutils/cnpj.py
@@ -72,7 +72,7 @@ def validate(cnpj):  # type: (str) -> bool
     )
 
 
-def is_valid_cnpj(cnpj):  # type: (str) -> bool
+def is_valid(cnpj):  # type: (str) -> bool
     """
     Returns whether or not the verifying checksum digits of the
     given `cnpj` match it's base number. Input should be a digit


Test patch:
diff --git a/tests/test_cnpj.py b/tests/test_cnpj.py
index d6874fc..ac7b757 100644
--- a/tests/test_cnpj.py
+++ b/tests/test_cnpj.py
@@ -15,7 +15,7 @@ from brutils.cnpj import (
     checksum,
     validate,
     generate,
-    is_valid_cnpj,
+    is_valid,
 )
 from unittest import TestCase, main
 
@@ -50,10 +50,10 @@ class CNPJ(TestCase):
         assert not validate("52599927000100")
         assert not validate("00000000000")
 
-    def test_is_valid_cnpj(self):
-        assert is_valid_cnpj("34665388000161")
-        assert not is_valid_cnpj("52599927000100")
-        assert not is_valid_cnpj("00000000000")
+    def test_is_valid(self):
+        assert is_valid("34665388000161")
+        assert not is_valid("52599927000100")
+        assert not is_valid("00000000000")
 
     def test_generate(self):
         for i in range(1000):