md-preview 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,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Fabio Matricardi
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,163 @@
1
+ Metadata-Version: 2.4
2
+ Name: md-preview
3
+ Version: 1.0.0
4
+ Summary: Render Markdown files with beautiful Bootstrap styling in your browser
5
+ Author-email: Your Name <your.email@example.com>
6
+ Maintainer-email: Your Name <your.email@example.com>
7
+ License: MIT
8
+ Project-URL: Homepage, https://github.com/fabiomatricardi/markdown-preview-pypi-package
9
+ Project-URL: Documentation, https://github.com/fabiomatricardi/markdown-preview-pypi-package#readme
10
+ Project-URL: Repository, https://github.com/fabiomatricardi/markdown-preview-pypi-package
11
+ Project-URL: Changelog, https://github.com/fabiomatricardi/markdown-preview-pypi-package/releases
12
+ Keywords: markdown,preview,bootstrap,cli,documentation
13
+ Classifier: Development Status :: 5 - Production/Stable
14
+ Classifier: Environment :: Console
15
+ Classifier: Intended Audience :: Developers
16
+ Classifier: License :: OSI Approved :: MIT License
17
+ Classifier: Operating System :: OS Independent
18
+ Classifier: Programming Language :: Python :: 3
19
+ Classifier: Programming Language :: Python :: 3.8
20
+ Classifier: Programming Language :: Python :: 3.9
21
+ Classifier: Programming Language :: Python :: 3.10
22
+ Classifier: Programming Language :: Python :: 3.11
23
+ Classifier: Programming Language :: Python :: 3.12
24
+ Classifier: Topic :: Text Processing :: Markup
25
+ Classifier: Topic :: Utilities
26
+ Classifier: Typing :: Typed
27
+ Requires-Python: >=3.8
28
+ Description-Content-Type: text/markdown
29
+ License-File: LICENSE
30
+ Requires-Dist: markdown>=3.4
31
+ Provides-Extra: dev
32
+ Requires-Dist: build; extra == "dev"
33
+ Requires-Dist: twine; extra == "dev"
34
+ Requires-Dist: pytest; extra == "dev"
35
+ Dynamic: license-file
36
+
37
+ # 🌟 md-preview v2.0
38
+
39
+ **TRUE BOOTSTRAP RENDERING** - Headers, tables, lists, blockquotes, and code blocks all styled with authentic Bootstrap aesthetics. No more "GitHub CSS + random code theme" mismatch!
40
+
41
+ ![Bootstrap Preview](https://blog.ronin.cloud/content/images/size/w2000/2022/02/markdown.png)
42
+ *Left: Flatly theme • Right: Darkly theme (full UI consistency)*
43
+
44
+ ## ✨ What Changed in v2.0?
45
+ | Feature | v1.x | v2.0 |
46
+ |---------|------|------|
47
+ | **Headers** | GitHub style | ✅ Bootstrap typography |
48
+ | **Tables** | Basic borders | ✅ `.table-striped` + hover effects |
49
+ | **Blockquotes** | Plain italics | ✅ Bootstrap alerts with icons |
50
+ | **Lists** | Default bullets | ✅ Bootstrap spacing & semantics |
51
+ | **Code Blocks** | Only syntax colored | ✅ Full Bootstrap card styling + copy buttons |
52
+ | **Theme Scope** | Code blocks only | ✅ **ENTIRE PAGE** (true UI kit) |
53
+ | **Responsiveness** | Limited | ✅ Mobile-first Bootstrap grid |
54
+
55
+ ## 🎨 Available Bootstrap Themes
56
+ | Theme | CLI Flag | Type | Best For |
57
+ |-------|----------|------|----------|
58
+ | **Cosmo** | `default` | Light | Friendly documentation |
59
+ | **Flatly** | `flatly` | Light | Modern clean interfaces |
60
+ | **Litera** | `litera` | Light | Readable long-form content |
61
+ | **Darkly** | `darkly` | Dark | Dark mode lovers (vibrant) |
62
+ | **Cyborg** | `cyborg` | Dark | Futuristic/terminal aesthetic |
63
+ | **Superhero** | `superhero` | Dark | Bold presentations |
64
+
65
+ > 💡 **All themes include**:
66
+ > - Responsive tables with hover effects
67
+ > - Blockquotes styled as Bootstrap alerts
68
+ > - Consistent spacing & typography
69
+ > - Mobile-optimized layout
70
+ > - Syntax highlighting that matches theme mode
71
+
72
+ ## 🚀 Usage
73
+ ```bash
74
+ # Install updated package
75
+ pip install --upgrade .
76
+
77
+ # Preview with default Bootstrap theme (Cosmo)
78
+ md-preview README.md
79
+
80
+ # Use popular Flatly theme (clean light design)
81
+ md-preview report.md --style flatly
82
+
83
+ # Dark mode workflow
84
+ md-preview notes.md --style darkly
85
+
86
+ # See ALL elements styled consistently:
87
+ echo '# Header\n\n- List item\n\n| Table | Header |\n|-------|--------|\n| Cell | Data |\n\n> Blockquote\n\n```python\nprint("Code")\n```' > test.md
88
+ md-preview test.md --style cyborg
89
+ ```
90
+
91
+ ---
92
+
93
+ # 🌟 md-preview
94
+
95
+ Render Markdown files with beautiful, modern themes directly in your browser. Zero configuration, instant preview.
96
+
97
+ <img src='https://user-images.githubusercontent.com/11283502/116907735-a58d7280-ac4a-11eb-8dbd-b905648593f8.png'>
98
+ *Left: GitHub Light • Right: Dracula Dark (auto-switches with OS theme)*
99
+
100
+ ## ✨ Features
101
+ - 🎨 **5 gorgeous themes**: GitHub (default), Dracula, Catppuccin, Solarized, Atom
102
+ - 🌓 **Automatic dark mode** (respects OS preference)
103
+ - 💡 **Syntax highlighting** with copy buttons on code blocks
104
+ - 📱 **Fully responsive** design (mobile/desktop)
105
+ - 🔒 **No network required after first load** (CDN assets cached by browser)
106
+ - 🚀 **Blazing fast** - pure Python, no heavy dependencies
107
+ - 🌐 **Works everywhere**: Windows, macOS, Linux
108
+
109
+
110
+ > what if you have some more features to add?
111
+
112
+
113
+ ### Tables rendering
114
+
115
+ #### 🌓 Recommended highlight.js Themes (via `--style` flag):
116
+ | Style Arg | Theme | Vibe |
117
+ |-----------|-------|------|
118
+ | `github` (default) | `github.min.css` | Familiar, professional |
119
+ | `dracula` | `dracula.min.css` | Dark, vibrant, developer favorite |
120
+ | `catppuccin` | `catppuccin-macchiato.min.css` | Modern pastel dark theme |
121
+ | `solarized` | `solarized-dark.min.css` | Classic low-contrast |
122
+ | `atom` | `atom-one-dark.min.css` | Smooth dark UI |
123
+
124
+ > 💡 **Pro Insight**: `github-markdown-css` **already includes dark mode** via system preference detection. Pair with a dark `highlight.js` theme (e.g., `dracula`) for full dark-mode harmony.
125
+
126
+ ## 📦 Installation
127
+
128
+ ### Option 1: Install as package (recommended)
129
+ ```bash
130
+ pip install .
131
+ ```
132
+
133
+ ### Example of rendered Python code
134
+
135
+ ```python
136
+ #!/usr/bin/env python3
137
+ """
138
+ md-preview: Render Markdown files with beautiful themes in your browser
139
+ """
140
+ import argparse
141
+ import html
142
+ import pathlib
143
+ import sys
144
+ import tempfile
145
+ import webbrowser
146
+
147
+ try:
148
+ import markdown
149
+ except ImportError:
150
+ print("❌ 'markdown' library not found. Install with: pip install markdown", file=sys.stderr)
151
+ sys.exit(1)
152
+
153
+ # CORRECTED THEME MAPPINGS (verified CDN paths)
154
+ THEME_MAP = {
155
+ "github": "github.min",
156
+ "dracula": "dracula.min",
157
+ "catppuccin": "catppuccin.min", # FIXED: was catppuccin-macchiato (invalid CDN path)
158
+ "solarized": "solarized-dark.min",
159
+ "atom": "atom-one-dark.min",
160
+ }
161
+ DEFAULT_THEME = "github"
162
+ HIGHLIGHT_VERSION = "11.9.0" # For cache-busting
163
+ ```
@@ -0,0 +1,127 @@
1
+ # 🌟 md-preview v2.0
2
+
3
+ **TRUE BOOTSTRAP RENDERING** - Headers, tables, lists, blockquotes, and code blocks all styled with authentic Bootstrap aesthetics. No more "GitHub CSS + random code theme" mismatch!
4
+
5
+ ![Bootstrap Preview](https://blog.ronin.cloud/content/images/size/w2000/2022/02/markdown.png)
6
+ *Left: Flatly theme • Right: Darkly theme (full UI consistency)*
7
+
8
+ ## ✨ What Changed in v2.0?
9
+ | Feature | v1.x | v2.0 |
10
+ |---------|------|------|
11
+ | **Headers** | GitHub style | ✅ Bootstrap typography |
12
+ | **Tables** | Basic borders | ✅ `.table-striped` + hover effects |
13
+ | **Blockquotes** | Plain italics | ✅ Bootstrap alerts with icons |
14
+ | **Lists** | Default bullets | ✅ Bootstrap spacing & semantics |
15
+ | **Code Blocks** | Only syntax colored | ✅ Full Bootstrap card styling + copy buttons |
16
+ | **Theme Scope** | Code blocks only | ✅ **ENTIRE PAGE** (true UI kit) |
17
+ | **Responsiveness** | Limited | ✅ Mobile-first Bootstrap grid |
18
+
19
+ ## 🎨 Available Bootstrap Themes
20
+ | Theme | CLI Flag | Type | Best For |
21
+ |-------|----------|------|----------|
22
+ | **Cosmo** | `default` | Light | Friendly documentation |
23
+ | **Flatly** | `flatly` | Light | Modern clean interfaces |
24
+ | **Litera** | `litera` | Light | Readable long-form content |
25
+ | **Darkly** | `darkly` | Dark | Dark mode lovers (vibrant) |
26
+ | **Cyborg** | `cyborg` | Dark | Futuristic/terminal aesthetic |
27
+ | **Superhero** | `superhero` | Dark | Bold presentations |
28
+
29
+ > 💡 **All themes include**:
30
+ > - Responsive tables with hover effects
31
+ > - Blockquotes styled as Bootstrap alerts
32
+ > - Consistent spacing & typography
33
+ > - Mobile-optimized layout
34
+ > - Syntax highlighting that matches theme mode
35
+
36
+ ## 🚀 Usage
37
+ ```bash
38
+ # Install updated package
39
+ pip install --upgrade .
40
+
41
+ # Preview with default Bootstrap theme (Cosmo)
42
+ md-preview README.md
43
+
44
+ # Use popular Flatly theme (clean light design)
45
+ md-preview report.md --style flatly
46
+
47
+ # Dark mode workflow
48
+ md-preview notes.md --style darkly
49
+
50
+ # See ALL elements styled consistently:
51
+ echo '# Header\n\n- List item\n\n| Table | Header |\n|-------|--------|\n| Cell | Data |\n\n> Blockquote\n\n```python\nprint("Code")\n```' > test.md
52
+ md-preview test.md --style cyborg
53
+ ```
54
+
55
+ ---
56
+
57
+ # 🌟 md-preview
58
+
59
+ Render Markdown files with beautiful, modern themes directly in your browser. Zero configuration, instant preview.
60
+
61
+ <img src='https://user-images.githubusercontent.com/11283502/116907735-a58d7280-ac4a-11eb-8dbd-b905648593f8.png'>
62
+ *Left: GitHub Light • Right: Dracula Dark (auto-switches with OS theme)*
63
+
64
+ ## ✨ Features
65
+ - 🎨 **5 gorgeous themes**: GitHub (default), Dracula, Catppuccin, Solarized, Atom
66
+ - 🌓 **Automatic dark mode** (respects OS preference)
67
+ - 💡 **Syntax highlighting** with copy buttons on code blocks
68
+ - 📱 **Fully responsive** design (mobile/desktop)
69
+ - 🔒 **No network required after first load** (CDN assets cached by browser)
70
+ - 🚀 **Blazing fast** - pure Python, no heavy dependencies
71
+ - 🌐 **Works everywhere**: Windows, macOS, Linux
72
+
73
+
74
+ > what if you have some more features to add?
75
+
76
+
77
+ ### Tables rendering
78
+
79
+ #### 🌓 Recommended highlight.js Themes (via `--style` flag):
80
+ | Style Arg | Theme | Vibe |
81
+ |-----------|-------|------|
82
+ | `github` (default) | `github.min.css` | Familiar, professional |
83
+ | `dracula` | `dracula.min.css` | Dark, vibrant, developer favorite |
84
+ | `catppuccin` | `catppuccin-macchiato.min.css` | Modern pastel dark theme |
85
+ | `solarized` | `solarized-dark.min.css` | Classic low-contrast |
86
+ | `atom` | `atom-one-dark.min.css` | Smooth dark UI |
87
+
88
+ > 💡 **Pro Insight**: `github-markdown-css` **already includes dark mode** via system preference detection. Pair with a dark `highlight.js` theme (e.g., `dracula`) for full dark-mode harmony.
89
+
90
+ ## 📦 Installation
91
+
92
+ ### Option 1: Install as package (recommended)
93
+ ```bash
94
+ pip install .
95
+ ```
96
+
97
+ ### Example of rendered Python code
98
+
99
+ ```python
100
+ #!/usr/bin/env python3
101
+ """
102
+ md-preview: Render Markdown files with beautiful themes in your browser
103
+ """
104
+ import argparse
105
+ import html
106
+ import pathlib
107
+ import sys
108
+ import tempfile
109
+ import webbrowser
110
+
111
+ try:
112
+ import markdown
113
+ except ImportError:
114
+ print("❌ 'markdown' library not found. Install with: pip install markdown", file=sys.stderr)
115
+ sys.exit(1)
116
+
117
+ # CORRECTED THEME MAPPINGS (verified CDN paths)
118
+ THEME_MAP = {
119
+ "github": "github.min",
120
+ "dracula": "dracula.min",
121
+ "catppuccin": "catppuccin.min", # FIXED: was catppuccin-macchiato (invalid CDN path)
122
+ "solarized": "solarized-dark.min",
123
+ "atom": "atom-one-dark.min",
124
+ }
125
+ DEFAULT_THEME = "github"
126
+ HIGHLIGHT_VERSION = "11.9.0" # For cache-busting
127
+ ```
@@ -0,0 +1,302 @@
1
+ #!/usr/bin/env python3
2
+ """
3
+ md-preview: Render Markdown with TRUE Bootstrap styling (all elements)
4
+ """
5
+ import argparse
6
+ import html
7
+ import pathlib
8
+ import sys
9
+ import tempfile
10
+ import webbrowser
11
+ from string import Template # CRITICAL: Avoids all brace conflicts
12
+
13
+ try:
14
+ import markdown
15
+ except ImportError:
16
+ print("❌ 'markdown' library not found. Install with: pip install markdown", file=sys.stderr)
17
+ sys.exit(1)
18
+
19
+ # BOOTSTRAP THEMES (Bootswatch) + MATCHING SYNTAX HIGHLIGHTING
20
+ BOOTSTRAP_THEMES = {
21
+ "default": { # Cosmo: Friendly blue
22
+ "css": "https://cdn.jsdelivr.net/npm/bootswatch@5.3.2/dist/cosmo/bootstrap.min.css",
23
+ "hljs": "github"
24
+ },
25
+ "darkly": { # Dark theme with vibrant accents
26
+ "css": "https://cdn.jsdelivr.net/npm/bootswatch@5.3.2/dist/darkly/bootstrap.min.css",
27
+ "hljs": "github-dark"
28
+ },
29
+ "flatly": { # Clean flat design (popular)
30
+ "css": "https://cdn.jsdelivr.net/npm/bootswatch@5.3.2/dist/flatly/bootstrap.min.css",
31
+ "hljs": "github"
32
+ },
33
+ "cyborg": { # Futuristic dark
34
+ "css": "https://cdn.jsdelivr.net/npm/bootswatch@5.3.2/dist/cyborg/bootstrap.min.css",
35
+ "hljs": "dracula"
36
+ },
37
+ "superhero": { # Bold dark theme
38
+ "css": "https://cdn.jsdelivr.net/npm/bootswatch@5.3.2/dist/superhero/bootstrap.min.css",
39
+ "hljs": "github-dark"
40
+ },
41
+ "litera": { # Clean light theme
42
+ "css": "https://cdn.jsdelivr.net/npm/bootswatch@5.3.2/dist/litera/bootstrap.min.css",
43
+ "hljs": "github"
44
+ }
45
+ }
46
+ DEFAULT_THEME = "default"
47
+ HLJS_VERSION = "11.9.0"
48
+
49
+ # ✅ SAFE TEMPLATE: Uses $placeholders (no brace conflicts!)
50
+ # CSS/JS can use normal {} braces freely
51
+ HTML_TEMPLATE = Template("""<!DOCTYPE html>
52
+ <html lang="en">
53
+ <head>
54
+ <meta charset="UTF-8">
55
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
56
+ <title>$safe_title • Bootstrap Markdown Preview</title>
57
+ <link rel="stylesheet" href="$bootstrap_css">
58
+ <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/$hljs_version/styles/$hljs_theme.min.css">
59
+ <style>
60
+ body {
61
+ padding-top: 2rem;
62
+ padding-bottom: 2rem;
63
+ background-color: var(--bs-body-bg);
64
+ color: var(--bs-body-color);
65
+ }
66
+ .preview-card {
67
+ border-radius: 0.6rem;
68
+ box-shadow: 0 0.5rem 1rem rgba(0,0,0,0.15);
69
+ transition: transform 0.3s;
70
+ }
71
+ .preview-card:hover {
72
+ transform: translateY(-2px);
73
+ }
74
+ /* RESPONSIVE IMAGES - FIXED OVERFLOW */
75
+ .card-body img {
76
+ max-width: 100%;
77
+ height: auto;
78
+ border-radius: 0.25rem;
79
+ box-shadow: 0 0.125rem 0.25rem rgba(0,0,0,0.075);
80
+ }
81
+ /* Preserve inline flow for small/icons */
82
+ .card-body p img {
83
+ display: inline;
84
+ margin: 0;
85
+ box-shadow: none;
86
+ border-radius: 0;
87
+ }
88
+ /* Code blocks */
89
+ pre {
90
+ border-radius: 0.4rem !important;
91
+ padding: 1.25rem !important;
92
+ background-color: var(--bs-tertiary-bg) !important;
93
+ border: 1px solid var(--bs-border-color) !important;
94
+ position: relative;
95
+ }
96
+ code {
97
+ background-color: var(--bs-tertiary-bg);
98
+ border-radius: 0.25rem;
99
+ padding: 0.15em 0.3em;
100
+ }
101
+ .table th {
102
+ font-weight: 600;
103
+ }
104
+ /* Copy button */
105
+ .copy-btn {
106
+ position: absolute;
107
+ top: 0.5rem;
108
+ right: 0.5rem;
109
+ padding: 0.25rem 0.5rem;
110
+ font-size: 0.85rem;
111
+ background: var(--bs-secondary-bg);
112
+ border: 1px solid var(--bs-border-color);
113
+ border-radius: 0.3rem;
114
+ opacity: 0.8;
115
+ transition: all 0.2s;
116
+ z-index: 10;
117
+ }
118
+ .copy-btn:hover {
119
+ opacity: 1;
120
+ background: var(--bs-tertiary-bg);
121
+ }
122
+ .copy-btn:active {
123
+ transform: scale(0.95);
124
+ }
125
+ /* Blockquote styling */
126
+ blockquote {
127
+ border-left: 3px solid var(--bs-primary);
128
+ padding-left: 1rem;
129
+ margin-left: 0;
130
+ font-style: italic;
131
+ color: var(--bs-secondary-color);
132
+ }
133
+ </style>
134
+ </head>
135
+ <body>
136
+ <div class="container">
137
+ <div class="row justify-content-center">
138
+ <div class="col-lg-10 col-xl-9">
139
+ <div class="card preview-card border-0">
140
+ <div class="card-body p-4 p-md-5">
141
+ $html_content
142
+ </div>
143
+ </div>
144
+ <div class="text-center text-muted mt-3">
145
+ <small>Rendered with Bootstrap • Theme: <strong>$theme_name</strong></small>
146
+ </div>
147
+ </div>
148
+ </div>
149
+ </div>
150
+
151
+ <script>
152
+ document.addEventListener('DOMContentLoaded', () => {
153
+ // Style tables
154
+ document.querySelectorAll('table').forEach(table => {
155
+ table.classList.add('table', 'table-striped', 'table-hover', 'align-middle');
156
+ table.querySelectorAll('thead tr').forEach(tr => {
157
+ tr.classList.add('table-dark');
158
+ });
159
+ });
160
+
161
+ // Style blockquotes with Unicode quote
162
+ document.querySelectorAll('blockquote').forEach(blockquote => {
163
+ blockquote.classList.add('alert', 'alert-primary', 'mb-4', 'p-3');
164
+ blockquote.innerHTML = '❝ ' + blockquote.innerHTML;
165
+ });
166
+
167
+ // Copy buttons
168
+ document.querySelectorAll('pre code').forEach((block) => {
169
+ const btn = document.createElement('button');
170
+ btn.innerHTML = '📋 Copy';
171
+ btn.className = 'copy-btn btn btn-sm';
172
+ btn.onclick = (e) => {
173
+ e.stopPropagation();
174
+ navigator.clipboard.writeText(block.textContent).then(() => {
175
+ const original = btn.innerHTML;
176
+ btn.innerHTML = '✅ Copied!';
177
+ setTimeout(() => { btn.innerHTML = original; }, 1500);
178
+ });
179
+ };
180
+ block.parentNode.appendChild(btn);
181
+ });
182
+
183
+ if (typeof hljs !== 'undefined') {
184
+ hljs.highlightAll();
185
+ }
186
+ });
187
+ </script>
188
+
189
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/$hljs_version/highlight.min.js"></script>
190
+ </body>
191
+ </html>""")
192
+
193
+
194
+ def render_markdown(md_text: str) -> str:
195
+ """Convert Markdown to HTML with Bootstrap-friendly extensions"""
196
+ return markdown.markdown(
197
+ md_text,
198
+ extensions=[
199
+ "extra", # Tables, fenced code, etc.
200
+ "nl2br", # Line breaks
201
+ "sane_lists", # Better list handling
202
+ "toc" # Optional: adds #anchors for headings
203
+ ],
204
+ output_format="html5"
205
+ )
206
+
207
+
208
+ def main():
209
+ parser = argparse.ArgumentParser(
210
+ description="✨ Render Markdown with TRUE Bootstrap styling (headers, tables, lists, code, images)",
211
+ epilog="Examples:\n"
212
+ " md-preview report.md\n"
213
+ " md-preview notes.md --style darkly\n"
214
+ " md-preview docs.md --style flatly\n\n"
215
+ "Themes affect ENTIRE PAGE (not just code):\n"
216
+ " default, flatly, litera → Light themes\n"
217
+ " darkly, cyborg, superhero → Dark themes",
218
+ formatter_class=argparse.RawDescriptionHelpFormatter
219
+ )
220
+ parser.add_argument("file", help="Path to Markdown file (.md)")
221
+ parser.add_argument(
222
+ "--style",
223
+ choices=list(BOOTSTRAP_THEMES.keys()),
224
+ default=DEFAULT_THEME,
225
+ metavar="THEME",
226
+ help=f"Bootstrap theme for ENTIRE PAGE (default: {DEFAULT_THEME}). "
227
+ f"Options: {', '.join(BOOTSTRAP_THEMES.keys())}"
228
+ )
229
+ parser.add_argument(
230
+ "--no-browser",
231
+ action="store_true",
232
+ help="Generate HTML but skip opening browser"
233
+ )
234
+
235
+ args = parser.parse_args()
236
+
237
+ # Validate file
238
+ md_path = pathlib.Path(args.file).resolve()
239
+ if not md_path.exists():
240
+ print(f"❌ Error: File not found: {md_path}", file=sys.stderr)
241
+ sys.exit(1)
242
+
243
+ # Read content
244
+ try:
245
+ md_content = md_path.read_text(encoding="utf-8")
246
+ except Exception as e:
247
+ print(f"❌ Error reading file: {e}", file=sys.stderr)
248
+ sys.exit(1)
249
+
250
+ # Convert Markdown
251
+ try:
252
+ html_body = render_markdown(md_content)
253
+ except Exception as e:
254
+ print(f"❌ Conversion failed: {e}", file=sys.stderr)
255
+ sys.exit(1)
256
+
257
+ # Get theme config
258
+ theme_config = BOOTSTRAP_THEMES.get(args.style, BOOTSTRAP_THEMES[DEFAULT_THEME])
259
+ title = md_path.stem.replace("_", " ").replace("-", " ").title()
260
+
261
+ # ✅ SAFE SUBSTITUTION: No brace conflicts possible
262
+ full_html = HTML_TEMPLATE.substitute(
263
+ safe_title=html.escape(title),
264
+ bootstrap_css=theme_config["css"],
265
+ hljs_theme=theme_config["hljs"],
266
+ hljs_version=HLJS_VERSION,
267
+ html_content=html_body,
268
+ theme_name=args.style.capitalize()
269
+ )
270
+
271
+ # Save to temp file
272
+ try:
273
+ with tempfile.NamedTemporaryFile(
274
+ mode="w",
275
+ suffix=".html",
276
+ delete=False,
277
+ encoding="utf-8",
278
+ prefix=f"md_preview_{md_path.stem}_"
279
+ ) as tmp:
280
+ tmp.write(full_html)
281
+ tmp_path = pathlib.Path(tmp.name)
282
+ except Exception as e:
283
+ print(f"❌ File write failed: {e}", file=sys.stderr)
284
+ sys.exit(1)
285
+
286
+ # Open browser
287
+ if not args.no_browser:
288
+ try:
289
+ webbrowser.open(tmp_path.as_uri())
290
+ theme_type = "🌙 Dark" if args.style in ["darkly", "cyborg", "superhero"] else "☀️ Light"
291
+ print(f"✅ Previewing '{md_path.name}' with {theme_type} Bootstrap theme: '{args.style}'")
292
+ print(f"🖼️ Images now scale responsively within content area!")
293
+ except Exception as e:
294
+ print(f"⚠️ Browser failed (file saved): {e}", file=sys.stderr)
295
+ print(f"📁 Open manually: {tmp_path}")
296
+ else:
297
+ print(f"✅ HTML saved: {tmp_path}")
298
+ print(f"🌐 Open: file://{tmp_path}")
299
+
300
+
301
+ if __name__ == "__main__":
302
+ main()
@@ -0,0 +1,163 @@
1
+ Metadata-Version: 2.4
2
+ Name: md-preview
3
+ Version: 1.0.0
4
+ Summary: Render Markdown files with beautiful Bootstrap styling in your browser
5
+ Author-email: Your Name <your.email@example.com>
6
+ Maintainer-email: Your Name <your.email@example.com>
7
+ License: MIT
8
+ Project-URL: Homepage, https://github.com/fabiomatricardi/markdown-preview-pypi-package
9
+ Project-URL: Documentation, https://github.com/fabiomatricardi/markdown-preview-pypi-package#readme
10
+ Project-URL: Repository, https://github.com/fabiomatricardi/markdown-preview-pypi-package
11
+ Project-URL: Changelog, https://github.com/fabiomatricardi/markdown-preview-pypi-package/releases
12
+ Keywords: markdown,preview,bootstrap,cli,documentation
13
+ Classifier: Development Status :: 5 - Production/Stable
14
+ Classifier: Environment :: Console
15
+ Classifier: Intended Audience :: Developers
16
+ Classifier: License :: OSI Approved :: MIT License
17
+ Classifier: Operating System :: OS Independent
18
+ Classifier: Programming Language :: Python :: 3
19
+ Classifier: Programming Language :: Python :: 3.8
20
+ Classifier: Programming Language :: Python :: 3.9
21
+ Classifier: Programming Language :: Python :: 3.10
22
+ Classifier: Programming Language :: Python :: 3.11
23
+ Classifier: Programming Language :: Python :: 3.12
24
+ Classifier: Topic :: Text Processing :: Markup
25
+ Classifier: Topic :: Utilities
26
+ Classifier: Typing :: Typed
27
+ Requires-Python: >=3.8
28
+ Description-Content-Type: text/markdown
29
+ License-File: LICENSE
30
+ Requires-Dist: markdown>=3.4
31
+ Provides-Extra: dev
32
+ Requires-Dist: build; extra == "dev"
33
+ Requires-Dist: twine; extra == "dev"
34
+ Requires-Dist: pytest; extra == "dev"
35
+ Dynamic: license-file
36
+
37
+ # 🌟 md-preview v2.0
38
+
39
+ **TRUE BOOTSTRAP RENDERING** - Headers, tables, lists, blockquotes, and code blocks all styled with authentic Bootstrap aesthetics. No more "GitHub CSS + random code theme" mismatch!
40
+
41
+ ![Bootstrap Preview](https://blog.ronin.cloud/content/images/size/w2000/2022/02/markdown.png)
42
+ *Left: Flatly theme • Right: Darkly theme (full UI consistency)*
43
+
44
+ ## ✨ What Changed in v2.0?
45
+ | Feature | v1.x | v2.0 |
46
+ |---------|------|------|
47
+ | **Headers** | GitHub style | ✅ Bootstrap typography |
48
+ | **Tables** | Basic borders | ✅ `.table-striped` + hover effects |
49
+ | **Blockquotes** | Plain italics | ✅ Bootstrap alerts with icons |
50
+ | **Lists** | Default bullets | ✅ Bootstrap spacing & semantics |
51
+ | **Code Blocks** | Only syntax colored | ✅ Full Bootstrap card styling + copy buttons |
52
+ | **Theme Scope** | Code blocks only | ✅ **ENTIRE PAGE** (true UI kit) |
53
+ | **Responsiveness** | Limited | ✅ Mobile-first Bootstrap grid |
54
+
55
+ ## 🎨 Available Bootstrap Themes
56
+ | Theme | CLI Flag | Type | Best For |
57
+ |-------|----------|------|----------|
58
+ | **Cosmo** | `default` | Light | Friendly documentation |
59
+ | **Flatly** | `flatly` | Light | Modern clean interfaces |
60
+ | **Litera** | `litera` | Light | Readable long-form content |
61
+ | **Darkly** | `darkly` | Dark | Dark mode lovers (vibrant) |
62
+ | **Cyborg** | `cyborg` | Dark | Futuristic/terminal aesthetic |
63
+ | **Superhero** | `superhero` | Dark | Bold presentations |
64
+
65
+ > 💡 **All themes include**:
66
+ > - Responsive tables with hover effects
67
+ > - Blockquotes styled as Bootstrap alerts
68
+ > - Consistent spacing & typography
69
+ > - Mobile-optimized layout
70
+ > - Syntax highlighting that matches theme mode
71
+
72
+ ## 🚀 Usage
73
+ ```bash
74
+ # Install updated package
75
+ pip install --upgrade .
76
+
77
+ # Preview with default Bootstrap theme (Cosmo)
78
+ md-preview README.md
79
+
80
+ # Use popular Flatly theme (clean light design)
81
+ md-preview report.md --style flatly
82
+
83
+ # Dark mode workflow
84
+ md-preview notes.md --style darkly
85
+
86
+ # See ALL elements styled consistently:
87
+ echo '# Header\n\n- List item\n\n| Table | Header |\n|-------|--------|\n| Cell | Data |\n\n> Blockquote\n\n```python\nprint("Code")\n```' > test.md
88
+ md-preview test.md --style cyborg
89
+ ```
90
+
91
+ ---
92
+
93
+ # 🌟 md-preview
94
+
95
+ Render Markdown files with beautiful, modern themes directly in your browser. Zero configuration, instant preview.
96
+
97
+ <img src='https://user-images.githubusercontent.com/11283502/116907735-a58d7280-ac4a-11eb-8dbd-b905648593f8.png'>
98
+ *Left: GitHub Light • Right: Dracula Dark (auto-switches with OS theme)*
99
+
100
+ ## ✨ Features
101
+ - 🎨 **5 gorgeous themes**: GitHub (default), Dracula, Catppuccin, Solarized, Atom
102
+ - 🌓 **Automatic dark mode** (respects OS preference)
103
+ - 💡 **Syntax highlighting** with copy buttons on code blocks
104
+ - 📱 **Fully responsive** design (mobile/desktop)
105
+ - 🔒 **No network required after first load** (CDN assets cached by browser)
106
+ - 🚀 **Blazing fast** - pure Python, no heavy dependencies
107
+ - 🌐 **Works everywhere**: Windows, macOS, Linux
108
+
109
+
110
+ > what if you have some more features to add?
111
+
112
+
113
+ ### Tables rendering
114
+
115
+ #### 🌓 Recommended highlight.js Themes (via `--style` flag):
116
+ | Style Arg | Theme | Vibe |
117
+ |-----------|-------|------|
118
+ | `github` (default) | `github.min.css` | Familiar, professional |
119
+ | `dracula` | `dracula.min.css` | Dark, vibrant, developer favorite |
120
+ | `catppuccin` | `catppuccin-macchiato.min.css` | Modern pastel dark theme |
121
+ | `solarized` | `solarized-dark.min.css` | Classic low-contrast |
122
+ | `atom` | `atom-one-dark.min.css` | Smooth dark UI |
123
+
124
+ > 💡 **Pro Insight**: `github-markdown-css` **already includes dark mode** via system preference detection. Pair with a dark `highlight.js` theme (e.g., `dracula`) for full dark-mode harmony.
125
+
126
+ ## 📦 Installation
127
+
128
+ ### Option 1: Install as package (recommended)
129
+ ```bash
130
+ pip install .
131
+ ```
132
+
133
+ ### Example of rendered Python code
134
+
135
+ ```python
136
+ #!/usr/bin/env python3
137
+ """
138
+ md-preview: Render Markdown files with beautiful themes in your browser
139
+ """
140
+ import argparse
141
+ import html
142
+ import pathlib
143
+ import sys
144
+ import tempfile
145
+ import webbrowser
146
+
147
+ try:
148
+ import markdown
149
+ except ImportError:
150
+ print("❌ 'markdown' library not found. Install with: pip install markdown", file=sys.stderr)
151
+ sys.exit(1)
152
+
153
+ # CORRECTED THEME MAPPINGS (verified CDN paths)
154
+ THEME_MAP = {
155
+ "github": "github.min",
156
+ "dracula": "dracula.min",
157
+ "catppuccin": "catppuccin.min", # FIXED: was catppuccin-macchiato (invalid CDN path)
158
+ "solarized": "solarized-dark.min",
159
+ "atom": "atom-one-dark.min",
160
+ }
161
+ DEFAULT_THEME = "github"
162
+ HIGHLIGHT_VERSION = "11.9.0" # For cache-busting
163
+ ```
@@ -0,0 +1,10 @@
1
+ LICENSE
2
+ README.md
3
+ pyproject.toml
4
+ md_preview/__main__.py
5
+ md_preview.egg-info/PKG-INFO
6
+ md_preview.egg-info/SOURCES.txt
7
+ md_preview.egg-info/dependency_links.txt
8
+ md_preview.egg-info/entry_points.txt
9
+ md_preview.egg-info/requires.txt
10
+ md_preview.egg-info/top_level.txt
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ md-preview = md_preview.__main__:main
@@ -0,0 +1,6 @@
1
+ markdown>=3.4
2
+
3
+ [dev]
4
+ build
5
+ twine
6
+ pytest
@@ -0,0 +1 @@
1
+ md_preview
@@ -0,0 +1,59 @@
1
+ [build-system]
2
+ requires = ["setuptools>=61.0", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "md-preview"
7
+ version = "1.0.0" # 🔑 SEMVER: MAJOR.MINOR.PATCH
8
+ description = "Render Markdown files with beautiful Bootstrap styling in your browser"
9
+ readme = "README.md"
10
+ requires-python = ">=3.8"
11
+ license = {text = "MIT"}
12
+ authors = [
13
+ {name = "Your Name", email = "your.email@example.com"}
14
+ ]
15
+ maintainers = [
16
+ {name = "Your Name", email = "your.email@example.com"}
17
+ ]
18
+ keywords = ["markdown", "preview", "bootstrap", "cli", "documentation"]
19
+ classifiers = [
20
+ "Development Status :: 5 - Production/Stable",
21
+ "Environment :: Console",
22
+ "Intended Audience :: Developers",
23
+ "License :: OSI Approved :: MIT License",
24
+ "Operating System :: OS Independent",
25
+ "Programming Language :: Python :: 3",
26
+ "Programming Language :: Python :: 3.8",
27
+ "Programming Language :: Python :: 3.9",
28
+ "Programming Language :: Python :: 3.10",
29
+ "Programming Language :: Python :: 3.11",
30
+ "Programming Language :: Python :: 3.12",
31
+ "Topic :: Text Processing :: Markup",
32
+ "Topic :: Utilities",
33
+ "Typing :: Typed"
34
+ ]
35
+ dependencies = [
36
+ "markdown>=3.4",
37
+ ]
38
+
39
+ [project.optional-dependencies]
40
+ dev = [
41
+ "build",
42
+ "twine",
43
+ "pytest",
44
+ ]
45
+
46
+ [project.urls]
47
+ Homepage = "https://github.com/fabiomatricardi/markdown-preview-pypi-package"
48
+ Documentation = "https://github.com/fabiomatricardi/markdown-preview-pypi-package#readme"
49
+ Repository = "https://github.com/fabiomatricardi/markdown-preview-pypi-package"
50
+ Changelog = "https://github.com/fabiomatricardi/markdown-preview-pypi-package/releases"
51
+
52
+ [project.scripts]
53
+ md-preview = "md_preview.__main__:main"
54
+
55
+ [tool.setuptools]
56
+ packages = ["md_preview"]
57
+
58
+ [tool.setuptools.package-data]
59
+ md_preview = ["py.typed"] # For type checkers (optional)
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+