tkhtmlview-gfm 0.1.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,23 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Lesley Smith
4
+ Copyright (c) 2020 Palash Bauri
5
+ Copyright (c) 2018 paolo-gurisatti
6
+
7
+ Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ of this software and associated documentation files (the "Software"), to deal
9
+ in the Software without restriction, including without limitation the rights
10
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ copies of the Software, and to permit persons to whom the Software is
12
+ furnished to do so, subject to the following conditions:
13
+
14
+ The above copyright notice and this permission notice shall be included in all
15
+ copies or substantial portions of the Software.
16
+
17
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ SOFTWARE.
@@ -0,0 +1 @@
1
+ include LICENSE
@@ -0,0 +1,164 @@
1
+ Metadata-Version: 2.4
2
+ Name: tkhtmlview-gfm
3
+ Version: 0.1.0
4
+ Summary: Display HTML with Tkinter + GitHub Flavored Markdown support
5
+ Author-email: Palash Bauri <palashbauri1@gmail.com>, Lesley Smith <lesley_nicole@outlook.com>
6
+ License: MIT License
7
+
8
+ Copyright (c) 2026 Lesley Smith
9
+ Copyright (c) 2020 Palash Bauri
10
+ Copyright (c) 2018 paolo-gurisatti
11
+
12
+ Permission is hereby granted, free of charge, to any person obtaining a copy
13
+ of this software and associated documentation files (the "Software"), to deal
14
+ in the Software without restriction, including without limitation the rights
15
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
16
+ copies of the Software, and to permit persons to whom the Software is
17
+ furnished to do so, subject to the following conditions:
18
+
19
+ The above copyright notice and this permission notice shall be included in all
20
+ copies or substantial portions of the Software.
21
+
22
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
25
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28
+ SOFTWARE.
29
+
30
+ Project-URL: Homepage, https://github.com/LesleySmithDigital/tkhtmlview-gfm
31
+ Project-URL: Repository, https://github.com/LesleySmithDigital/tkhtmlview-gfm
32
+ Project-URL: Issues, https://github.com/LesleySmithDigital/tkhtmlview-gfm/issues
33
+ Project-URL: Upstream Project, https://github.com/rdbende/tkhtmlview
34
+ Project-URL: Release, https://github.com/LesleySmithDigital/tkhtmlview-gfm/releases/tag/v0.1.0
35
+ Keywords: tkinter,html,markdown,gfm,gui
36
+ Classifier: Development Status :: 4 - Beta
37
+ Classifier: Intended Audience :: Developers
38
+ Classifier: Operating System :: OS Independent
39
+ Classifier: Programming Language :: Python :: 3.11
40
+ Classifier: Programming Language :: Python :: 3.12
41
+ Classifier: Programming Language :: Python :: 3.13
42
+ Classifier: Programming Language :: Python :: 3.14
43
+ Classifier: Topic :: Software Development :: Libraries
44
+ Classifier: Topic :: Text Processing :: Markup :: HTML
45
+ Classifier: Topic :: Text Processing :: Markup :: Markdown
46
+ Requires-Python: <4,>=3.11
47
+ Description-Content-Type: text/markdown
48
+ License-File: LICENSE
49
+ Requires-Dist: requests<3,>=2.32.4
50
+ Requires-Dist: Pillow<14,>=11
51
+ Dynamic: license-file
52
+
53
+ <p align="center"><img src="assets/tkquill.png" width="25%" alt="quill"></p>
54
+
55
+ <h1 align="center">tkhtmlview-gfm</h1>
56
+
57
+ <p align="center">Display HTML with Tkinter, + GitHub Flavored Markdown support.</p>
58
+
59
+ <p align="center">Forked from
60
+ <a href="https://github.com/rdbende/tkhtmlview">tkhtmlview
61
+ </a> by Palash Bauri.
62
+ </p>
63
+
64
+ [![MIT License](https://img.shields.io/badge/License-MIT-green.svg)](https://github.com/LesleySmithDigital/LICENSE)
65
+
66
+
67
+ ## What's New
68
+
69
+ Adds rendering support for GFM features not available in upstream:
70
+
71
+ | Feature | HTML | Status |
72
+ |---------|------|--------|
73
+ | Strikethrough | `<del>` / `<s>` | ✓ |
74
+ | Blockquote | `<blockquote>` | ✓ |
75
+ | Horizontal rule | `<hr>` | ✓ |
76
+ | Task lists | `<input type="checkbox">` | ✓ (visual only) |
77
+ | Tables | `<table>` | ✓ |
78
+ | Text alignment | `align="center"` / `text-align` | ✓ |
79
+
80
+
81
+ <p align="center">
82
+ <img src="assets/gfm_test.png" width="50%" alt="new features">
83
+ </p>
84
+
85
+ ## Installation
86
+
87
+ ```bash
88
+ pip install tkhtmlview-gfm
89
+ ```
90
+
91
+ ## Usage
92
+
93
+ ```python
94
+ import tkinter as tk
95
+ from tkhtmlview import HTMLScrolledText
96
+
97
+ root = tk.Tk()
98
+ w = HTMLScrolledText(root)
99
+ w.pack(fill="both", expand=True)
100
+ root.update_idletasks() # ← forces the widget to compute its real size
101
+ w.set_html("""
102
+ <p>Normal <del>struck</del> text</p>
103
+ <blockquote><p>Quoted</p></blockquote>
104
+ <hr>
105
+ <ul><li>☐ Task</li><li>☑ Done</li></ul>
106
+ <h1 align="center">Centered</h1>
107
+ """)
108
+
109
+ root.mainloop()
110
+ ```
111
+
112
+ ### Handle Live Resize
113
+
114
+ Bind <Configure> to re-render (debounced so it doesn't fire 50 times per drag):
115
+
116
+ **Example:**
117
+ ```python
118
+ _configure_job = None
119
+
120
+ def on_configure(event):
121
+ global _configure_job
122
+ if _configure_job is not None:
123
+ preview.after_cancel(_configure_job)
124
+ _configure_job = preview.after(200, render_preview)
125
+
126
+ preview.bind("<Configure>", on_configure)
127
+
128
+ # Now when you drag the window edge, the HR (and any other width-dependent rendering) updates ~200 ms after you stop dragging.
129
+ ```
130
+
131
+ TL;DR: **root.update_idletasks()** before **set_html** fixes the initial render. The <Configure> binding handles resize. The fallback in the parser is a safety net, which gives you a reasonable line.
132
+
133
+ ## Known Limitations
134
+
135
+ - Task list checkboxes are visual only (not interactive)
136
+ - " hr " is rendered as a row of ─ characters (not a true line)
137
+ - text-align: justify falls back to left (Tkinter limitation)
138
+ - No CSS margin/padding/border support
139
+
140
+ ## Development
141
+
142
+ ```
143
+ git clone https://github.com/LesleySmithDigital/tkhtmlview-gfm.git
144
+ cd tkhtmlview-gfm
145
+ pip install -e .
146
+ pytest tests/test_gfm.py
147
+ ```
148
+
149
+ ## Testing
150
+
151
+ ```bash
152
+ pip install pytest
153
+ pytest tests/test_gfm.py
154
+ ```
155
+
156
+ ## License
157
+ MIT
158
+
159
+ ## Credits
160
+ Based on [tkhtmlview](https://github.com/rdbende/tkhtmlview) by Palash Bauri(MIT License).
161
+
162
+ ## Author
163
+
164
+ - [@LesleySmithDigital](https://www.github.com/LesleySmithDigital)
@@ -0,0 +1,112 @@
1
+ <p align="center"><img src="assets/tkquill.png" width="25%" alt="quill"></p>
2
+
3
+ <h1 align="center">tkhtmlview-gfm</h1>
4
+
5
+ <p align="center">Display HTML with Tkinter, + GitHub Flavored Markdown support.</p>
6
+
7
+ <p align="center">Forked from
8
+ <a href="https://github.com/rdbende/tkhtmlview">tkhtmlview
9
+ </a> by Palash Bauri.
10
+ </p>
11
+
12
+ [![MIT License](https://img.shields.io/badge/License-MIT-green.svg)](https://github.com/LesleySmithDigital/LICENSE)
13
+
14
+
15
+ ## What's New
16
+
17
+ Adds rendering support for GFM features not available in upstream:
18
+
19
+ | Feature | HTML | Status |
20
+ |---------|------|--------|
21
+ | Strikethrough | `<del>` / `<s>` | ✓ |
22
+ | Blockquote | `<blockquote>` | ✓ |
23
+ | Horizontal rule | `<hr>` | ✓ |
24
+ | Task lists | `<input type="checkbox">` | ✓ (visual only) |
25
+ | Tables | `<table>` | ✓ |
26
+ | Text alignment | `align="center"` / `text-align` | ✓ |
27
+
28
+
29
+ <p align="center">
30
+ <img src="assets/gfm_test.png" width="50%" alt="new features">
31
+ </p>
32
+
33
+ ## Installation
34
+
35
+ ```bash
36
+ pip install tkhtmlview-gfm
37
+ ```
38
+
39
+ ## Usage
40
+
41
+ ```python
42
+ import tkinter as tk
43
+ from tkhtmlview import HTMLScrolledText
44
+
45
+ root = tk.Tk()
46
+ w = HTMLScrolledText(root)
47
+ w.pack(fill="both", expand=True)
48
+ root.update_idletasks() # ← forces the widget to compute its real size
49
+ w.set_html("""
50
+ <p>Normal <del>struck</del> text</p>
51
+ <blockquote><p>Quoted</p></blockquote>
52
+ <hr>
53
+ <ul><li>☐ Task</li><li>☑ Done</li></ul>
54
+ <h1 align="center">Centered</h1>
55
+ """)
56
+
57
+ root.mainloop()
58
+ ```
59
+
60
+ ### Handle Live Resize
61
+
62
+ Bind <Configure> to re-render (debounced so it doesn't fire 50 times per drag):
63
+
64
+ **Example:**
65
+ ```python
66
+ _configure_job = None
67
+
68
+ def on_configure(event):
69
+ global _configure_job
70
+ if _configure_job is not None:
71
+ preview.after_cancel(_configure_job)
72
+ _configure_job = preview.after(200, render_preview)
73
+
74
+ preview.bind("<Configure>", on_configure)
75
+
76
+ # Now when you drag the window edge, the HR (and any other width-dependent rendering) updates ~200 ms after you stop dragging.
77
+ ```
78
+
79
+ TL;DR: **root.update_idletasks()** before **set_html** fixes the initial render. The <Configure> binding handles resize. The fallback in the parser is a safety net, which gives you a reasonable line.
80
+
81
+ ## Known Limitations
82
+
83
+ - Task list checkboxes are visual only (not interactive)
84
+ - " hr " is rendered as a row of ─ characters (not a true line)
85
+ - text-align: justify falls back to left (Tkinter limitation)
86
+ - No CSS margin/padding/border support
87
+
88
+ ## Development
89
+
90
+ ```
91
+ git clone https://github.com/LesleySmithDigital/tkhtmlview-gfm.git
92
+ cd tkhtmlview-gfm
93
+ pip install -e .
94
+ pytest tests/test_gfm.py
95
+ ```
96
+
97
+ ## Testing
98
+
99
+ ```bash
100
+ pip install pytest
101
+ pytest tests/test_gfm.py
102
+ ```
103
+
104
+ ## License
105
+ MIT
106
+
107
+ ## Credits
108
+ Based on [tkhtmlview](https://github.com/rdbende/tkhtmlview) by Palash Bauri(MIT License).
109
+
110
+ ## Author
111
+
112
+ - [@LesleySmithDigital](https://www.github.com/LesleySmithDigital)
@@ -0,0 +1,44 @@
1
+ [build-system]
2
+ requires = ["setuptools>=77"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "tkhtmlview-gfm"
7
+ version = "0.1.0"
8
+ description = "Display HTML with Tkinter + GitHub Flavored Markdown support"
9
+ readme = "README.md"
10
+ license = { file = "LICENSE" }
11
+ requires-python = ">=3.11,<4"
12
+ authors = [
13
+ { name = "Palash Bauri", email = "palashbauri1@gmail.com" },
14
+ { name = "Lesley Smith", email = "lesley_nicole@outlook.com" },
15
+ ]
16
+ keywords = ["tkinter", "html", "markdown", "gfm", "gui"]
17
+ classifiers = [
18
+ "Development Status :: 4 - Beta",
19
+ "Intended Audience :: Developers",
20
+ "Operating System :: OS Independent",
21
+ "Programming Language :: Python :: 3.11",
22
+ "Programming Language :: Python :: 3.12",
23
+ "Programming Language :: Python :: 3.13",
24
+ "Programming Language :: Python :: 3.14",
25
+ "Topic :: Software Development :: Libraries",
26
+ "Topic :: Text Processing :: Markup :: HTML",
27
+ "Topic :: Text Processing :: Markup :: Markdown",
28
+ ]
29
+ dependencies = [
30
+ "requests>=2.32.4,<3",
31
+ "Pillow>=11,<14",
32
+ ]
33
+ [project.urls]
34
+ Homepage = "https://github.com/LesleySmithDigital/tkhtmlview-gfm"
35
+ Repository = "https://github.com/LesleySmithDigital/tkhtmlview-gfm"
36
+ Issues = "https://github.com/LesleySmithDigital/tkhtmlview-gfm/issues"
37
+ "Upstream Project" = "https://github.com/rdbende/tkhtmlview"
38
+ Release = "https://github.com/LesleySmithDigital/tkhtmlview-gfm/releases/tag/v0.1.0"
39
+
40
+ [tool.setuptools.packages.find]
41
+ include = ["tkhtmlview*"]
42
+
43
+ [tool.pytest.ini_options]
44
+ testpaths = ["tests"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,31 @@
1
+ # test.py
2
+ import tkinter as tk
3
+ from tkhtmlview import HTMLScrolledText
4
+
5
+ root = tk.Tk()
6
+ root.title("GFM Test")
7
+ w = HTMLScrolledText(root)
8
+ w.pack(fill="both", expand=True)
9
+ root.update_idletasks()
10
+ w.set_html("""
11
+ <p>Normal <del>struck</del> text</p>
12
+
13
+ <s>strikethrough</s>
14
+
15
+ <blockquote>
16
+ <p>Quoted line 1</p>
17
+ <p>Quoted line 2</p>
18
+ </blockquote>
19
+
20
+ <hr>
21
+
22
+ <ul><li>☐ Task</li><li>☑ Done</li></ul>
23
+
24
+ <h1 align="center">Centered</h1>
25
+
26
+ <h2 style="text-align: center">CSS centered</h2>
27
+
28
+ <table><tr><th>H1</th><th>H2</th></tr><tr><td>a</td><td>b</td></tr></table>
29
+ """)
30
+
31
+ root.mainloop()
@@ -0,0 +1,45 @@
1
+ # test_gfm.py
2
+ import pytest
3
+ import tkinter as tk
4
+ from tkhtmlview import HTMLScrolledText
5
+ import tkinter.font as tkfont
6
+
7
+ @pytest.fixture
8
+ def widget():
9
+ root = tk.Tk()
10
+ w = HTMLScrolledText(root)
11
+ w.pack(fill="both", expand=True)
12
+ root.update_idletasks()
13
+ yield w
14
+ root.destroy() # ← always runs, even if the test fails
15
+
16
+ def test_strikethrough(widget):
17
+ widget.set_html("<p><del>struck</del></p>")
18
+ pos = widget.search("struck", "1.0", stopindex="end")
19
+ assert pos, "text 'struck' not found"
20
+ for t in widget.tag_names(pos):
21
+ try:
22
+ f = tkfont.Font(font=widget.tag_cget(t, "font"))
23
+ if f.cget("overstrike"):
24
+ return # passed
25
+ except tk.TclError:
26
+ pass
27
+ pytest.fail(f"No overstrike at {pos}")
28
+
29
+ def test_blockquote_indent(widget):
30
+ widget.set_html("<blockquote><p>quoted</p></blockquote>")
31
+ tags = widget.tag_names("1.1")
32
+ has_lmargin = False
33
+ for t in tags:
34
+ try:
35
+ if int(widget.tag_cget(t, "lmargin1")) > 0:
36
+ has_lmargin = True
37
+ break
38
+ except tk.TclError:
39
+ pass
40
+ assert has_lmargin
41
+
42
+ def test_hr_renders(widget):
43
+ widget.set_html("<hr>")
44
+ content = widget.get("1.0", "end-1c")
45
+ assert "─" in content
@@ -0,0 +1,134 @@
1
+ """
2
+ tkinter HTML text widgets
3
+ """
4
+ import sys
5
+ import tkinter as tk
6
+ from tkhtmlview import html_parser
7
+ from tkhtmlview.utils import RenderHTML
8
+
9
+ VERSION = "0.1.0"
10
+
11
+
12
+ class _ScrolledText(tk.Text):
13
+ def __init__(self, master=None, **kw):
14
+ self.frame = tk.Frame(master)
15
+
16
+ self.vbar = tk.Scrollbar(self.frame)
17
+ self.xscroll = tk.Scrollbar(self.frame, orient="horizontal")
18
+
19
+ if "xscroll" in kw:
20
+ # self.vbar.orient = "vertical"
21
+ # print("vs")
22
+ kw["xscrollcommand"] = self.xscroll.set
23
+ self.xscroll.pack(side=tk.BOTTOM, fill="x")
24
+ self.xscroll["command"] = self.xview
25
+ del kw["xscroll"]
26
+
27
+ kw["yscrollcommand"] = self.vbar.set
28
+ self.vbar.pack(side=tk.RIGHT, fill=tk.Y)
29
+ self.vbar["command"] = self.yview
30
+
31
+ tk.Text.__init__(self, self.frame, **kw)
32
+ self.pack(side=tk.LEFT, fill=tk.BOTH, expand=True)
33
+
34
+ text_meths = vars(tk.Text).keys()
35
+ methods = vars(tk.Pack).keys() | vars(tk.Grid).keys() | vars(tk.Place).keys()
36
+ methods = methods.difference(text_meths)
37
+
38
+ for m in methods:
39
+ if m[0] != "_" and m != "config" and m != "configure":
40
+ setattr(self, m, getattr(self.frame, m))
41
+
42
+ def __str__(self):
43
+ return str(self.frame)
44
+
45
+
46
+ class HTMLScrolledText(_ScrolledText):
47
+
48
+ """
49
+ HTML scrolled text widget
50
+ """
51
+
52
+ def __init__(self, *args, html=None, **kwargs):
53
+ super().__init__(*args, **kwargs)
54
+ self._w_init(kwargs)
55
+ self.html_parser = html_parser.HTMLTextParser()
56
+ if isinstance(html, str):
57
+ self.set_html(html)
58
+ elif isinstance(html, RenderHTML):
59
+ self.set_html(html.get_html())
60
+
61
+ def _w_init(self, kwargs):
62
+ if "wrap" not in kwargs.keys():
63
+ self.config(wrap="word")
64
+ if "background" not in kwargs.keys():
65
+ if sys.platform.startswith("win"):
66
+ self.config(background="SystemWindow")
67
+ else:
68
+ self.config(background="white")
69
+
70
+ def fit_height(self):
71
+ """
72
+ Fit widget height to wrapped lines
73
+ """
74
+ for h in range(1, 4):
75
+ self.config(height=h)
76
+ self.master.update()
77
+ if self.yview()[1] >= 1:
78
+ break
79
+ else:
80
+ self.config(height=0.5 + 3 / self.yview()[1])
81
+
82
+ def set_html(self, html, strip=True):
83
+ """
84
+ Set HTML widget text. If strip is enabled (default) it ignores spaces and new lines.
85
+ """
86
+ prev_state = self.cget("state")
87
+ self.config(state=tk.NORMAL)
88
+ self.delete("1.0", tk.END)
89
+ for tag in self.tag_names():
90
+ self.tag_delete(tag)
91
+
92
+ self.html_parser.w_set_html(self, html, strip=strip)
93
+ self.config(state=prev_state)
94
+
95
+
96
+ class HTMLText(HTMLScrolledText):
97
+
98
+ """
99
+ HTML text widget
100
+ """
101
+
102
+ def _w_init(self, kwargs):
103
+ super()._w_init(kwargs)
104
+ self.vbar.pack_forget()
105
+
106
+ def fit_height(self):
107
+ super().fit_height()
108
+ # self.master.update()
109
+ self.vbar.pack_forget()
110
+
111
+
112
+ class HTMLLabel(HTMLText):
113
+
114
+ """
115
+ HTML label widget
116
+ """
117
+
118
+ def _w_init(self, kwargs):
119
+ super()._w_init(kwargs)
120
+ if "background" not in kwargs.keys():
121
+ if sys.platform.startswith("win"):
122
+ self.config(background="SystemButtonFace")
123
+ else:
124
+ self.config(background="#d9d9d9")
125
+
126
+ if "borderwidth" not in kwargs.keys():
127
+ self.config(borderwidth=0)
128
+
129
+ if "padx" not in kwargs.keys():
130
+ self.config(padx=3)
131
+
132
+ def set_html(self, *args, **kwargs):
133
+ super().set_html(*args, **kwargs)
134
+ self.config(state=tk.DISABLED)