md2html-tailwind4 1.0.0__tar.gz

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.
@@ -0,0 +1,67 @@
1
+ # This workflow will upload a Python Package to PyPI when a release is created
2
+ # For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python#publishing-to-package-registries
3
+
4
+ # This workflow uses actions that are not certified by GitHub.
5
+ # They are provided by a third-party and are governed by
6
+ # separate terms of service, privacy policy, and support
7
+ # documentation.
8
+
9
+ name: Upload Python Package
10
+
11
+ on:
12
+ release:
13
+ types: [published]
14
+ workflow_dispatch:
15
+
16
+ permissions:
17
+ contents: read
18
+
19
+ jobs:
20
+ release-build:
21
+ runs-on: ubuntu-latest
22
+
23
+ steps:
24
+ - uses: actions/checkout@v4
25
+
26
+ - uses: actions/setup-python@v5
27
+ with:
28
+ python-version: "3.13"
29
+
30
+ - name: Install uv
31
+ uses: astral-sh/setup-uv@v5
32
+
33
+ - name: Build release distributions
34
+ run: uv build
35
+
36
+ - name: Upload distributions
37
+ uses: actions/upload-artifact@v4
38
+ with:
39
+ name: release-dists
40
+ path: dist/
41
+
42
+ pypi-publish:
43
+ runs-on: ubuntu-latest
44
+ needs:
45
+ - release-build
46
+ permissions:
47
+ # IMPORTANT: this permission is mandatory for trusted publishing
48
+ id-token: write
49
+
50
+ # Dedicated environments with protections for publishing are strongly recommended.
51
+ # For more information, see: https://docs.github.com/en/actions/deployment/targeting-different-environments/using-environments-for-deployment#deployment-protection-rules
52
+ environment:
53
+ name: pypi
54
+ # OPTIONAL: uncomment and update to include your PyPI project URL in the deployment status:
55
+ url: https://pypi.org/p/md2html-tailwind4
56
+
57
+ steps:
58
+ - name: Retrieve release distributions
59
+ uses: actions/download-artifact@v4
60
+ with:
61
+ name: release-dists
62
+ path: dist/
63
+
64
+ - name: Publish release distributions to PyPI
65
+ uses: pypa/gh-action-pypi-publish@release/v1
66
+ with:
67
+ packages-dir: dist/
@@ -0,0 +1,208 @@
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[codz]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ # Distribution / packaging
10
+ .Python
11
+ build/
12
+ develop-eggs/
13
+ dist/
14
+ downloads/
15
+ eggs/
16
+ .eggs/
17
+ lib/
18
+ lib64/
19
+ parts/
20
+ sdist/
21
+ var/
22
+ wheels/
23
+ share/python-wheels/
24
+ *.egg-info/
25
+ .installed.cfg
26
+ *.egg
27
+ MANIFEST
28
+
29
+ # PyInstaller
30
+ # Usually these files are written by a python script from a template
31
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
32
+ *.manifest
33
+ *.spec
34
+
35
+ # Installer logs
36
+ pip-log.txt
37
+ pip-delete-this-directory.txt
38
+
39
+ # Unit test / coverage reports
40
+ htmlcov/
41
+ .tox/
42
+ .nox/
43
+ .coverage
44
+ .coverage.*
45
+ .cache
46
+ nosetests.xml
47
+ coverage.xml
48
+ *.cover
49
+ *.py.cover
50
+ .hypothesis/
51
+ .pytest_cache/
52
+ cover/
53
+
54
+ # Translations
55
+ *.mo
56
+ *.pot
57
+
58
+ # Django stuff:
59
+ *.log
60
+ local_settings.py
61
+ db.sqlite3
62
+ db.sqlite3-journal
63
+
64
+ # Flask stuff:
65
+ instance/
66
+ .webassets-cache
67
+
68
+ # Scrapy stuff:
69
+ .scrapy
70
+
71
+ # Sphinx documentation
72
+ docs/_build/
73
+
74
+ # PyBuilder
75
+ .pybuilder/
76
+ target/
77
+
78
+ # Jupyter Notebook
79
+ .ipynb_checkpoints
80
+
81
+ # IPython
82
+ profile_default/
83
+ ipython_config.py
84
+
85
+ # pyenv
86
+ # For a library or package, you might want to ignore these files since the code is
87
+ # intended to run in multiple environments; otherwise, check them in:
88
+ # .python-version
89
+
90
+ # pipenv
91
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
93
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
94
+ # install all needed dependencies.
95
+ #Pipfile.lock
96
+
97
+ # UV
98
+ # Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
99
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
100
+ # commonly ignored for libraries.
101
+ #uv.lock
102
+
103
+ # poetry
104
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
105
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
106
+ # commonly ignored for libraries.
107
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
108
+ #poetry.lock
109
+ #poetry.toml
110
+
111
+ # pdm
112
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
113
+ # pdm recommends including project-wide configuration in pdm.toml, but excluding .pdm-python.
114
+ # https://pdm-project.org/en/latest/usage/project/#working-with-version-control
115
+ #pdm.lock
116
+ #pdm.toml
117
+ .pdm-python
118
+ .pdm-build/
119
+
120
+ # pixi
121
+ # Similar to Pipfile.lock, it is generally recommended to include pixi.lock in version control.
122
+ #pixi.lock
123
+ # Pixi creates a virtual environment in the .pixi directory, just like venv module creates one
124
+ # in the .venv directory. It is recommended not to include this directory in version control.
125
+ .pixi
126
+
127
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
128
+ __pypackages__/
129
+
130
+ # Celery stuff
131
+ celerybeat-schedule
132
+ celerybeat.pid
133
+
134
+ # SageMath parsed files
135
+ *.sage.py
136
+
137
+ # Environments
138
+ .env
139
+ .envrc
140
+ .venv
141
+ env/
142
+ venv/
143
+ ENV/
144
+ env.bak/
145
+ venv.bak/
146
+
147
+ # Spyder project settings
148
+ .spyderproject
149
+ .spyproject
150
+
151
+ # Rope project settings
152
+ .ropeproject
153
+
154
+ # mkdocs documentation
155
+ /site
156
+
157
+ # mypy
158
+ .mypy_cache/
159
+ .dmypy.json
160
+ dmypy.json
161
+
162
+ # Pyre type checker
163
+ .pyre/
164
+
165
+ # pytype static type analyzer
166
+ .pytype/
167
+
168
+ # Cython debug symbols
169
+ cython_debug/
170
+
171
+ # PyCharm
172
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
173
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
174
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
175
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
176
+ #.idea/
177
+
178
+ # Abstra
179
+ # Abstra is an AI-powered process automation framework.
180
+ # Ignore directories containing user credentials, local state, and settings.
181
+ # Learn more at https://abstra.io/docs
182
+ .abstra/
183
+
184
+ # Visual Studio Code
185
+ # Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore
186
+ # that can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
187
+ # and can be added to the global gitignore or merged into this file. However, if you prefer,
188
+ # you could uncomment the following to ignore the entire vscode folder
189
+ # .vscode/
190
+
191
+ # Ruff stuff:
192
+ .ruff_cache/
193
+
194
+ # PyPI configuration file
195
+ .pypirc
196
+
197
+ # Cursor
198
+ # Cursor is an AI-powered code editor. `.cursorignore` specifies files/directories to
199
+ # exclude from AI features like autocomplete and code analysis. Recommended for sensitive data
200
+ # refer to https://docs.cursor.com/context/ignore-files
201
+ .cursorignore
202
+ .cursorindexingignore
203
+
204
+ # Marimo
205
+ marimo/_static/
206
+ marimo/_lsp/
207
+ __marimo__/
208
+ markdown2html_tailwind.py
@@ -0,0 +1 @@
1
+ 3.11
@@ -0,0 +1,21 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [1.0.0] - 2026-04-15
9
+
10
+ ### Added
11
+
12
+ - Initial release of `md2html-tailwind4`
13
+ - `Converter` class with `convert_md_to_html()` method
14
+ - Tailwind CSS 4 class annotations for all standard HTML elements (h1–h6, p, ul, ol, li, blockquote, img, pre, code, strong, em, a, hr)
15
+ - Responsive table styling with overflow scrolling
16
+ - Audio table support: 3-column tables with media URLs are converted to interactive audio player widgets
17
+ - Django template delimiter escaping (`{{ }}`, `{% %}`, `{# #}`) inside code blocks
18
+ - External links automatically get `target="_blank"` and `rel="noopener noreferrer"`
19
+ - Dark mode support via Tailwind `dark:` variants
20
+ - CLI entry point: `md2html input.md output.html`
21
+ - `src/` layout for clean PyPI packaging with `hatchling` build backend
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 White Neuron
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,89 @@
1
+ Metadata-Version: 2.4
2
+ Name: md2html-tailwind4
3
+ Version: 1.0.0
4
+ Summary: A Python package that converts Markdown to HTML using Tailwind CSS 4 for styling.
5
+ Author-email: "White Neuron Co., Ltd." <contact@whiteneuron.com>
6
+ License: MIT License
7
+
8
+ Copyright (c) 2026 White Neuron
9
+
10
+ Permission is hereby granted, free of charge, to any person obtaining a copy
11
+ of this software and associated documentation files (the "Software"), to deal
12
+ in the Software without restriction, including without limitation the rights
13
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14
+ copies of the Software, and to permit persons to whom the Software is
15
+ furnished to do so, subject to the following conditions:
16
+
17
+ The above copyright notice and this permission notice shall be included in all
18
+ copies or substantial portions of the Software.
19
+
20
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26
+ SOFTWARE.
27
+ License-File: LICENSE
28
+ Keywords: converter,html,markdown,tailwind,tailwindcss
29
+ Classifier: Development Status :: 5 - Production/Stable
30
+ Classifier: Intended Audience :: Developers
31
+ Classifier: License :: OSI Approved :: MIT License
32
+ Classifier: Programming Language :: Python :: 3
33
+ Classifier: Programming Language :: Python :: 3.11
34
+ Classifier: Programming Language :: Python :: 3.12
35
+ Classifier: Programming Language :: Python :: 3.13
36
+ Classifier: Topic :: Text Processing :: Markup :: HTML
37
+ Classifier: Topic :: Text Processing :: Markup :: Markdown
38
+ Requires-Python: >=3.11
39
+ Requires-Dist: beautifulsoup4>=4.14.3
40
+ Requires-Dist: markdown>=3.10.2
41
+ Description-Content-Type: text/markdown
42
+
43
+ # md2html-tailwind4
44
+
45
+ A Python package that converts Markdown to clean, styled HTML using **Tailwind CSS 4** classes.
46
+
47
+ Designed for projects that render HTML inside a Tailwind-powered frontend (Django, FastAPI, static sites, etc.). No build step required — just pass in Markdown, get back ready-to-render HTML.
48
+
49
+ ## Features
50
+
51
+ - Converts Markdown to HTML with full Tailwind CSS 4 class annotations
52
+ - Responsive tables with overflow scrolling
53
+ - Audio table support (3-column tables with media URLs become interactive audio players)
54
+ - Automatically escapes Django template delimiters (`{{ }}`, `{% %}`) inside code blocks
55
+ - External links get `target="_blank"` and `rel="noopener noreferrer"` automatically
56
+ - Dark mode support via Tailwind's `dark:` variants
57
+ - CLI tool included
58
+
59
+ ## Installation
60
+
61
+ ```bash
62
+ pip install md2html-tailwind4
63
+ ```
64
+
65
+ ## Usage
66
+
67
+ ### Python API
68
+
69
+ ```python
70
+ from md2html_tailwind4 import Converter
71
+
72
+ converter = Converter()
73
+ html = converter.convert_md_to_html("# Hello\n\nThis is **Markdown**.")
74
+ print(html)
75
+ ```
76
+
77
+ ### Command Line
78
+
79
+ ```bash
80
+ md2html input.md output.html
81
+ ```
82
+
83
+ ## Requirements
84
+
85
+ - Python >= 3.11
86
+
87
+ ## License
88
+
89
+ MIT — White Neuron Co., Ltd.
@@ -0,0 +1,47 @@
1
+ # md2html-tailwind4
2
+
3
+ A Python package that converts Markdown to clean, styled HTML using **Tailwind CSS 4** classes.
4
+
5
+ Designed for projects that render HTML inside a Tailwind-powered frontend (Django, FastAPI, static sites, etc.). No build step required — just pass in Markdown, get back ready-to-render HTML.
6
+
7
+ ## Features
8
+
9
+ - Converts Markdown to HTML with full Tailwind CSS 4 class annotations
10
+ - Responsive tables with overflow scrolling
11
+ - Audio table support (3-column tables with media URLs become interactive audio players)
12
+ - Automatically escapes Django template delimiters (`{{ }}`, `{% %}`) inside code blocks
13
+ - External links get `target="_blank"` and `rel="noopener noreferrer"` automatically
14
+ - Dark mode support via Tailwind's `dark:` variants
15
+ - CLI tool included
16
+
17
+ ## Installation
18
+
19
+ ```bash
20
+ pip install md2html-tailwind4
21
+ ```
22
+
23
+ ## Usage
24
+
25
+ ### Python API
26
+
27
+ ```python
28
+ from md2html_tailwind4 import Converter
29
+
30
+ converter = Converter()
31
+ html = converter.convert_md_to_html("# Hello\n\nThis is **Markdown**.")
32
+ print(html)
33
+ ```
34
+
35
+ ### Command Line
36
+
37
+ ```bash
38
+ md2html input.md output.html
39
+ ```
40
+
41
+ ## Requirements
42
+
43
+ - Python >= 3.11
44
+
45
+ ## License
46
+
47
+ MIT — White Neuron Co., Ltd.
@@ -0,0 +1,36 @@
1
+ [build-system]
2
+ requires = ["hatchling"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "md2html-tailwind4"
7
+ version = "1.0.0"
8
+ description = "A Python package that converts Markdown to HTML using Tailwind CSS 4 for styling."
9
+ authors = [
10
+ { name = "White Neuron Co., Ltd.", email = "contact@whiteneuron.com" },
11
+ ]
12
+ license = { file = "LICENSE" }
13
+ readme = "README.md"
14
+ requires-python = ">=3.11"
15
+ keywords = ["markdown", "html", "tailwind", "tailwindcss", "converter"]
16
+ classifiers = [
17
+ "Development Status :: 5 - Production/Stable",
18
+ "Intended Audience :: Developers",
19
+ "License :: OSI Approved :: MIT License",
20
+ "Programming Language :: Python :: 3",
21
+ "Programming Language :: Python :: 3.11",
22
+ "Programming Language :: Python :: 3.12",
23
+ "Programming Language :: Python :: 3.13",
24
+ "Topic :: Text Processing :: Markup :: HTML",
25
+ "Topic :: Text Processing :: Markup :: Markdown",
26
+ ]
27
+ dependencies = [
28
+ "beautifulsoup4>=4.14.3",
29
+ "markdown>=3.10.2",
30
+ ]
31
+
32
+ [project.scripts]
33
+ md2html = "md2html_tailwind4.cli:main"
34
+
35
+ [tool.hatch.build.targets.wheel]
36
+ packages = ["src/md2html_tailwind4"]
@@ -0,0 +1,3 @@
1
+ from .converter import Converter
2
+
3
+ __all__ = ["Converter"]
@@ -0,0 +1,26 @@
1
+ import argparse
2
+
3
+ from .converter import Converter
4
+
5
+
6
+ def main():
7
+ parser = argparse.ArgumentParser(
8
+ prog='md2html',
9
+ description='Convert Markdown to HTML with Tailwind CSS 4 classes.',
10
+ )
11
+ parser.add_argument('input', help='Path to the input Markdown file')
12
+ parser.add_argument('output', help='Path to the output HTML file')
13
+ args = parser.parse_args()
14
+
15
+ with open(args.input, 'r', encoding='utf-8') as f:
16
+ markdown_content = f.read()
17
+
18
+ converter = Converter()
19
+ html_content = converter.convert_md_to_html(markdown_content)
20
+
21
+ with open(args.output, 'w', encoding='utf-8') as f:
22
+ f.write(html_content)
23
+
24
+
25
+ if __name__ == '__main__':
26
+ main()
@@ -0,0 +1,208 @@
1
+ import markdown
2
+ import re
3
+ from bs4 import BeautifulSoup
4
+
5
+
6
+ class Converter:
7
+ def __init__(self):
8
+ pass
9
+
10
+ def convert_md_to_html(self, markdown_content):
11
+ # Convert Markdown to HTML with richer extensions for broader content support.
12
+ html_content = markdown.markdown(
13
+ markdown_content,
14
+ extensions=['tables', 'attr_list', 'fenced_code', 'sane_lists', 'nl2br'],
15
+ )
16
+
17
+ # Parse the HTML content and convert tables to custom divs
18
+ soup = BeautifulSoup(html_content, 'html.parser')
19
+
20
+ # Add Tailwind classes to various elements
21
+ self.add_tailwind_classes(soup)
22
+
23
+ # Convert tables to custom divs
24
+ self.convert_tables(soup)
25
+
26
+ # Escape Django template delimiters in code examples so they render literally.
27
+ self.escape_django_template_syntax_in_code_blocks(soup)
28
+
29
+ # Create the full HTML content with JavaScript for play/pause toggle
30
+ full_html_content = self.create_full_html(soup)
31
+
32
+ return full_html_content
33
+
34
+ def add_tailwind_classes(self, soup):
35
+ for h1 in soup.find_all('h1'):
36
+ h1['class'] = 'text-2xl sm:text-3xl lg:text-4xl font-bold tracking-tight mb-4 sm:mb-5 text-neutral-900 dark:text-neutral-100'
37
+
38
+ for h2 in soup.find_all('h2'):
39
+ h2['class'] = 'text-xl sm:text-2xl lg:text-3xl font-bold tracking-tight mt-8 mb-3 text-neutral-900 dark:text-neutral-100'
40
+
41
+ for h3 in soup.find_all('h3'):
42
+ h3['class'] = 'text-lg sm:text-xl lg:text-2xl font-semibold mt-6 mb-3 text-neutral-900 dark:text-neutral-100'
43
+
44
+ for h4 in soup.find_all('h4'):
45
+ h4['class'] = 'text-base sm:text-lg font-semibold mt-5 mb-2 text-neutral-800 dark:text-neutral-200'
46
+
47
+ for h5 in soup.find_all('h5'):
48
+ h5['class'] = 'text-base font-semibold mt-4 mb-2 text-neutral-800 dark:text-neutral-200'
49
+
50
+ for h6 in soup.find_all('h6'):
51
+ h6['class'] = 'text-sm font-semibold uppercase tracking-wide mt-4 mb-2 text-neutral-700 dark:text-neutral-300'
52
+
53
+ for p in soup.find_all('p'):
54
+ p['class'] = 'mb-4 text-base leading-7 text-pretty text-justify text-neutral-800 dark:text-neutral-200'
55
+
56
+ for ul in soup.find_all('ul'):
57
+ ul['class'] = 'list-disc list-outside pl-6 mb-4 space-y-1 text-base leading-7 text-justify text-neutral-800 dark:text-neutral-200'
58
+
59
+ for ol in soup.find_all('ol'):
60
+ ol['class'] = 'list-decimal list-outside pl-6 mb-4 space-y-1 text-base leading-7 text-justify text-neutral-800 dark:text-neutral-200'
61
+
62
+ for li in soup.find_all('li'):
63
+ li['class'] = 'leading-7'
64
+
65
+ for blockquote in soup.find_all('blockquote'):
66
+ blockquote['class'] = 'mb-5 p-4 sm:p-5 rounded-r-xl border-l-4 bg-neutral-100 text-neutral-700 border-neutral-400 italic text-base leading-7 quote dark:bg-neutral-900/60 dark:text-neutral-300 dark:border-neutral-600'
67
+
68
+ for img in soup.find_all('img'):
69
+ img['class'] = 'mx-auto my-5 w-full max-w-4xl h-auto rounded-xl border border-neutral-200 shadow-sm dark:border-neutral-700 dark:shadow-neutral-950/30'
70
+
71
+ for pre in soup.find_all('pre'):
72
+ pre['class'] = 'my-5 overflow-x-auto rounded-xl border border-neutral-200 bg-neutral-950 p-4 text-sm leading-6 text-neutral-100 dark:border-neutral-700 dark:bg-neutral-950 dark:text-neutral-100'
73
+
74
+ for code in soup.find_all('code'):
75
+ if code.parent and code.parent.name == 'pre':
76
+ code['class'] = 'bg-transparent p-0 text-inherit font-mono'
77
+ else:
78
+ code['class'] = 'px-1.5 py-0.5 rounded-md bg-neutral-100 text-[0.9em] font-mono text-neutral-900 dark:bg-neutral-800 dark:text-neutral-100'
79
+
80
+ for strong in soup.find_all('strong'):
81
+ strong['class'] = 'font-semibold text-neutral-900 dark:text-neutral-100'
82
+
83
+ for em in soup.find_all('em'):
84
+ em['class'] = 'italic text-neutral-700 dark:text-neutral-300'
85
+
86
+ for a in soup.find_all('a'):
87
+ a['class'] = 'text-sky-700 underline decoration-sky-300 underline-offset-2 hover:text-sky-900 transition-colors dark:text-sky-300 dark:decoration-sky-600 dark:hover:text-sky-200'
88
+ if a.get('href', '').startswith(('http://', 'https://')):
89
+ a['target'] = '_blank'
90
+ a['rel'] = 'noopener noreferrer'
91
+
92
+ for hr in soup.find_all('hr'):
93
+ hr['class'] = 'my-8 border-neutral-300 dark:border-neutral-700'
94
+
95
+ def convert_tables(self, soup):
96
+ for table in soup.find_all('table'):
97
+ rows = table.find_all('tr')
98
+ if len(rows) == 0:
99
+ continue
100
+
101
+ # Check if the first row is a header
102
+ first_row_cells = rows[0].find_all(['th', 'td'])
103
+ has_headers = len(first_row_cells) == 3 and all(th.name == 'th' for th in first_row_cells)
104
+
105
+ # Only convert dedicated audio tables; keep all other tables semantic/responsive.
106
+ if not has_headers or not self._is_audio_table(rows):
107
+ self._style_as_responsive_table(soup, table)
108
+ continue
109
+
110
+ start_index = 1 if has_headers else 0
111
+ divs = []
112
+
113
+ for row in rows[start_index:]:
114
+ cells = row.find_all(['td', 'th'])
115
+ if len(cells) >= 2: # Ensure there are at least two cells per row
116
+ div = soup.new_tag('div', **{'class': 'my-3 rounded-xl border border-neutral-200 bg-white p-3 sm:p-4 shadow-sm flex flex-col sm:flex-row sm:items-center sm:justify-center gap-2 sm:gap-3 dark:border-neutral-700 dark:bg-neutral-900 dark:shadow-neutral-950/30'})
117
+ span1 = soup.new_tag('span', **{'class': 'font-semibold rounded-lg bg-neutral-800 px-3 py-2 text-white text-sm sm:text-base dark:bg-neutral-700'})
118
+ span1.string = cells[0].get_text()
119
+ span2 = soup.new_tag('span', **{'class': 'font-semibold rounded-lg bg-neutral-700 px-3 py-2 text-white text-sm sm:text-base break-words dark:bg-neutral-600'})
120
+ span2_content = cells[1].get_text()
121
+ span2.append(soup.new_string(span2_content))
122
+ if len(cells) == 3 and cells[2].get_text().strip():
123
+ audio_button = soup.new_tag('button', **{'class': 'audio-button ml-2', 'data-state': 'play'})
124
+ audio_button.string = '▶️'
125
+ audio_url = cells[2].get_text().strip()
126
+ audio_id = span2_content.lower().replace(' ', '_').replace('[', '').replace(']', '')
127
+ audio = soup.new_tag('audio', **{'src': audio_url, 'class': 'hidden', 'controls': ''})
128
+ audio_button['onclick'] = f"togglePlayPause('{audio_id}', this);"
129
+ audio['id'] = audio_id
130
+ span2.append(audio_button)
131
+ span2.append(audio)
132
+ div.append(span1)
133
+ div.append(span2)
134
+ divs.append(div)
135
+ if divs:
136
+ table.replace_with(*divs)
137
+ else:
138
+ table.decompose()
139
+
140
+ @staticmethod
141
+ def _is_audio_table(rows):
142
+ # Audio-table mode is only valid when the 3rd column consistently contains media URLs.
143
+ media_suffixes = ('.mp3', '.wav', '.ogg', '.m4a', '.aac', '.webm')
144
+ data_rows = rows[1:] if len(rows) > 1 else []
145
+ if not data_rows:
146
+ return False
147
+
148
+ third_values = []
149
+ for row in data_rows:
150
+ cells = row.find_all(['td', 'th'])
151
+ if len(cells) < 3:
152
+ return False
153
+ third_values.append(cells[2].get_text().strip().lower())
154
+
155
+ if not all(third_values):
156
+ return False
157
+
158
+ return all(value.startswith(('http://', 'https://', '/')) or value.endswith(media_suffixes) for value in third_values)
159
+
160
+ def _style_as_responsive_table(self, soup, table):
161
+ table['class'] = 'min-w-full border-collapse text-sm sm:text-base'
162
+ table['style'] = 'color: var(--color-base-content); border-color: var(--color-base-300);'
163
+
164
+ thead = table.find('thead')
165
+ if thead:
166
+ thead['class'] = ''
167
+ thead['style'] = 'background-color: var(--color-base-300); color: var(--color-base-content);'
168
+ for th in table.find_all('th'):
169
+ th['class'] = 'border px-3 py-2 text-left font-semibold whitespace-nowrap'
170
+ th['style'] = 'border-color: var(--color-base-300); color: var(--color-base-content);'
171
+
172
+ for td in table.find_all('td'):
173
+ td['class'] = 'border px-3 py-2 align-top'
174
+ td['style'] = 'border-color: var(--color-base-300); color: var(--color-base-content);'
175
+
176
+ wrapper = soup.new_tag(
177
+ 'div',
178
+ **{
179
+ 'class': 'my-5 overflow-x-auto rounded-xl border shadow-sm',
180
+ 'style': 'border-color: var(--color-base-300); background-color: var(--color-base-100); color: var(--color-base-content);',
181
+ },
182
+ )
183
+ table.wrap(wrapper)
184
+
185
+ def create_full_html(self, soup):
186
+ return str(soup)
187
+
188
+ def escape_django_template_syntax_in_code_blocks(self, soup):
189
+ for tag in soup.find_all(['code', 'pre']):
190
+ # Keep code samples readable while preventing Django template parsing.
191
+ if tag.string is not None:
192
+ tag.string.replace_with(self._escape_django_delimiters(str(tag.string)))
193
+ continue
194
+
195
+ for text_node in tag.find_all(string=True):
196
+ text_node.replace_with(self._escape_django_delimiters(str(text_node)))
197
+
198
+ @staticmethod
199
+ def _escape_django_delimiters(text):
200
+ token_map = {
201
+ '{{': '{% templatetag openvariable %}',
202
+ '}}': '{% templatetag closevariable %}',
203
+ '{%': '{% templatetag openblock %}',
204
+ '%}': '{% templatetag closeblock %}',
205
+ '{#': '{% templatetag opencomment %}',
206
+ '#}': '{% templatetag closecomment %}',
207
+ }
208
+ return re.sub(r'\{\{|\}\}|\{%|%\}|\{#|#\}', lambda m: token_map[m.group(0)], text)
@@ -0,0 +1,57 @@
1
+ version = 1
2
+ requires-python = ">=3.11"
3
+
4
+ [[package]]
5
+ name = "beautifulsoup4"
6
+ version = "4.14.3"
7
+ source = { registry = "https://pypi.org/simple" }
8
+ dependencies = [
9
+ { name = "soupsieve" },
10
+ { name = "typing-extensions" },
11
+ ]
12
+ sdist = { url = "https://files.pythonhosted.org/packages/c3/b0/1c6a16426d389813b48d95e26898aff79abbde42ad353958ad95cc8c9b21/beautifulsoup4-4.14.3.tar.gz", hash = "sha256:6292b1c5186d356bba669ef9f7f051757099565ad9ada5dd630bd9de5fa7fb86", size = 627737 }
13
+ wheels = [
14
+ { url = "https://files.pythonhosted.org/packages/1a/39/47f9197bdd44df24d67ac8893641e16f386c984a0619ef2ee4c51fbbc019/beautifulsoup4-4.14.3-py3-none-any.whl", hash = "sha256:0918bfe44902e6ad8d57732ba310582e98da931428d231a5ecb9e7c703a735bb", size = 107721 },
15
+ ]
16
+
17
+ [[package]]
18
+ name = "markdown"
19
+ version = "3.10.2"
20
+ source = { registry = "https://pypi.org/simple" }
21
+ sdist = { url = "https://files.pythonhosted.org/packages/2b/f4/69fa6ed85ae003c2378ffa8f6d2e3234662abd02c10d216c0ba96081a238/markdown-3.10.2.tar.gz", hash = "sha256:994d51325d25ad8aa7ce4ebaec003febcce822c3f8c911e3b17c52f7f589f950", size = 368805 }
22
+ wheels = [
23
+ { url = "https://files.pythonhosted.org/packages/de/1f/77fa3081e4f66ca3576c896ae5d31c3002ac6607f9747d2e3aa49227e464/markdown-3.10.2-py3-none-any.whl", hash = "sha256:e91464b71ae3ee7afd3017d9f358ef0baf158fd9a298db92f1d4761133824c36", size = 108180 },
24
+ ]
25
+
26
+ [[package]]
27
+ name = "md2html-tailwind4"
28
+ version = "0.1.0"
29
+ source = { virtual = "." }
30
+ dependencies = [
31
+ { name = "beautifulsoup4" },
32
+ { name = "markdown" },
33
+ ]
34
+
35
+ [package.metadata]
36
+ requires-dist = [
37
+ { name = "beautifulsoup4", specifier = ">=4.14.3" },
38
+ { name = "markdown", specifier = ">=3.10.2" },
39
+ ]
40
+
41
+ [[package]]
42
+ name = "soupsieve"
43
+ version = "2.8.3"
44
+ source = { registry = "https://pypi.org/simple" }
45
+ sdist = { url = "https://files.pythonhosted.org/packages/7b/ae/2d9c981590ed9999a0d91755b47fc74f74de286b0f5cee14c9269041e6c4/soupsieve-2.8.3.tar.gz", hash = "sha256:3267f1eeea4251fb42728b6dfb746edc9acaffc4a45b27e19450b676586e8349", size = 118627 }
46
+ wheels = [
47
+ { url = "https://files.pythonhosted.org/packages/46/2c/1462b1d0a634697ae9e55b3cecdcb64788e8b7d63f54d923fcd0bb140aed/soupsieve-2.8.3-py3-none-any.whl", hash = "sha256:ed64f2ba4eebeab06cc4962affce381647455978ffc1e36bb79a545b91f45a95", size = 37016 },
48
+ ]
49
+
50
+ [[package]]
51
+ name = "typing-extensions"
52
+ version = "4.15.0"
53
+ source = { registry = "https://pypi.org/simple" }
54
+ sdist = { url = "https://files.pythonhosted.org/packages/72/94/1a15dd82efb362ac84269196e94cf00f187f7ed21c242792a923cdb1c61f/typing_extensions-4.15.0.tar.gz", hash = "sha256:0cea48d173cc12fa28ecabc3b837ea3cf6f38c6d1136f85cbaaf598984861466", size = 109391 }
55
+ wheels = [
56
+ { url = "https://files.pythonhosted.org/packages/18/67/36e9267722cc04a6b9f15c7f3441c2363321a3ea07da7ae0c0707beb2a9c/typing_extensions-4.15.0-py3-none-any.whl", hash = "sha256:f0fa19c6845758ab08074a0cfa8b7aecb71c999ca73d62883bc25cc018c4e548", size = 44614 },
57
+ ]