markdown_convert 1.2.33__py3-none-any.whl → 1.2.34__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,6 +4,8 @@ Module for transforming HTML content.
4
4
 
5
5
  import re
6
6
 
7
+ from bs4 import BeautifulSoup
8
+
7
9
 
8
10
  def create_html_document(html_content, css_content, csp):
9
11
  """
@@ -30,28 +32,31 @@ def create_html_document(html_content, css_content, csp):
30
32
  </html>"""
31
33
 
32
34
 
33
- def create_sections(html):
35
+ def create_sections(html_string):
34
36
  """
35
- Creates h2 sections, from the first h2 to the next h2, wrapping them in <section> tags
36
- using regular expressions.
37
+ Wraps each h2 and its following content in a <section> tag.
38
+ Avoids wrapping h2 tags that are inside <code> blocks.
39
+
37
40
  Args:
38
- html (str): HTML content.
41
+ html_string (str): The input HTML string.
39
42
  Returns:
40
- HTML content with sections wrapped in <section> tags.
43
+ str: The modified HTML string with h2 sections wrapped.
41
44
  """
42
- pattern = re.compile(r"(<h2.*?>.*?</h2>)(.*?)(?=(<h2.*?>|$))", re.DOTALL)
45
+ soup = BeautifulSoup(html_string, "html.parser")
43
46
 
44
- def wrap_section(match):
45
- return f"<section>\n{match.group(1)}\n{match.group(2)}\n</section>\n"
47
+ for second_level_header in soup.find_all("h2"):
48
+ new_section = soup.new_tag("section")
49
+ second_level_header.insert_before(new_section)
46
50
 
47
- # Split by code blocks to avoid processing text inside them
48
- parts = re.split(r"(<code>.*?</code>)", html, flags=re.DOTALL)
49
- for part_index, _part in enumerate(parts):
50
- # Only process parts that are NOT code blocks
51
- if not parts[part_index].startswith("<code>"):
52
- parts[part_index] = pattern.sub(wrap_section, parts[part_index])
51
+ current = second_level_header
52
+ while current is not None and (
53
+ current == second_level_header or current.name != "h2"
54
+ ):
55
+ next_sibling = current.next_sibling
56
+ new_section.append(current)
57
+ current = next_sibling
53
58
 
54
- return "".join(parts)
59
+ return str(soup)
55
60
 
56
61
 
57
62
  def render_mermaid_diagrams(html, *, nonce):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: markdown_convert
3
- Version: 1.2.33
3
+ Version: 1.2.34
4
4
  Summary: Convert Markdown files to PDF from your command line.
5
5
  Project-URL: homepage, https://github.com/Julynx/markdown_convert
6
6
  Author-email: Julio Cabria <juliocabria@tutanota.com>
@@ -11,6 +11,7 @@ Classifier: Operating System :: OS Independent
11
11
  Classifier: Programming Language :: Python :: 3
12
12
  Requires-Python: <3.15,>=3.9
13
13
  Requires-Dist: argsdict==1.0.0
14
+ Requires-Dist: beautifulsoup4>=4.14.3
14
15
  Requires-Dist: latex2mathml>=3.78.1
15
16
  Requires-Dist: markdown2<3,>=2.4.13
16
17
  Requires-Dist: playwright>=1.57.0
@@ -6,11 +6,11 @@ markdown_convert/modules/__init__.py,sha256=PFPgiQhMXgyfjD8BkfLC_X8AR1jz-dCxfif2
6
6
  markdown_convert/modules/constants.py,sha256=_h6N0fhG9K1hQPmp3eYu53TfQnAPe7RtmMj-2FCD7VU,495
7
7
  markdown_convert/modules/convert.py,sha256=R1xIKW6UVGP7a6VK5C6qLK278wBlHZV9X6Y9q73mz_k,9843
8
8
  markdown_convert/modules/resources.py,sha256=tnW8JmCrJNBRbzOcaOVG6GX5jPC8Kzj3dA7gX0B935A,2488
9
- markdown_convert/modules/transform.py,sha256=Vm6FeYT1n0-ytesd7vVQfSXitSNLt5cegApk4l6n5SQ,3131
9
+ markdown_convert/modules/transform.py,sha256=uQbTtiSKDTXRs49OuDazpD2nSya4fpghzMS4BZ9zm_8,3120
10
10
  markdown_convert/modules/utils.py,sha256=NX0WegM8e8MPKNNmweTujAWO8ZghdB8LSGDx20K2E44,655
11
11
  markdown_convert/modules/validate.py,sha256=XV_k7cHeifEKDaltF26tCmabs2-Me5msP3enI_eVwfA,1517
12
- markdown_convert-1.2.33.dist-info/METADATA,sha256=EaOM5WjkJafLTTI4x7nKclU8_t2zgenfW2Y32_qeC1g,3895
13
- markdown_convert-1.2.33.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
14
- markdown_convert-1.2.33.dist-info/entry_points.txt,sha256=RCmzC7C0sX-SpzIP2Cr34rhg3lMd7BRx-exaZPfK8bU,68
15
- markdown_convert-1.2.33.dist-info/licenses/LICENSE,sha256=gXf5dRMhNSbfLPYYTY_5hsZ1r7UU1OaKQEAQUhuIBkM,18092
16
- markdown_convert-1.2.33.dist-info/RECORD,,
12
+ markdown_convert-1.2.34.dist-info/METADATA,sha256=fRtx7t9rm4EIgCm7H0zEmAZF8iDjcbDr9NguGUUqEMA,3933
13
+ markdown_convert-1.2.34.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
14
+ markdown_convert-1.2.34.dist-info/entry_points.txt,sha256=RCmzC7C0sX-SpzIP2Cr34rhg3lMd7BRx-exaZPfK8bU,68
15
+ markdown_convert-1.2.34.dist-info/licenses/LICENSE,sha256=gXf5dRMhNSbfLPYYTY_5hsZ1r7UU1OaKQEAQUhuIBkM,18092
16
+ markdown_convert-1.2.34.dist-info/RECORD,,