table-png 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.
- table_png-0.1.0/LICENSE +21 -0
- table_png-0.1.0/PKG-INFO +194 -0
- table_png-0.1.0/README.md +170 -0
- table_png-0.1.0/pyproject.toml +50 -0
- table_png-0.1.0/setup.cfg +4 -0
- table_png-0.1.0/src/table_png/__init__.py +19 -0
- table_png-0.1.0/src/table_png/__main__.py +6 -0
- table_png-0.1.0/src/table_png/cli.py +120 -0
- table_png-0.1.0/src/table_png/fonts.py +434 -0
- table_png-0.1.0/src/table_png/inputs.py +270 -0
- table_png-0.1.0/src/table_png/render.py +662 -0
- table_png-0.1.0/src/table_png/theme.py +68 -0
- table_png-0.1.0/src/table_png.egg-info/PKG-INFO +194 -0
- table_png-0.1.0/src/table_png.egg-info/SOURCES.txt +16 -0
- table_png-0.1.0/src/table_png.egg-info/dependency_links.txt +1 -0
- table_png-0.1.0/src/table_png.egg-info/entry_points.txt +2 -0
- table_png-0.1.0/src/table_png.egg-info/requires.txt +1 -0
- table_png-0.1.0/src/table_png.egg-info/top_level.txt +1 -0
table_png-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 El Fenomeno
|
|
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.
|
table_png-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: table-png
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Render a table (Markdown, CSV or JSON) as a PNG image with correct Korean, Chinese and Japanese text and colour emoji, for chat apps, notifications and bots that cannot show a Markdown table.
|
|
5
|
+
Author: El Fenomeno
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/elfenomenokim/table-png
|
|
8
|
+
Project-URL: Repository, https://github.com/elfenomenokim/table-png
|
|
9
|
+
Project-URL: Issues, https://github.com/elfenomenokim/table-png/issues
|
|
10
|
+
Keywords: table,png,image,markdown,csv,cjk,korean,emoji,chat,cli
|
|
11
|
+
Classifier: Development Status :: 4 - Beta
|
|
12
|
+
Classifier: Environment :: Console
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: Operating System :: OS Independent
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
17
|
+
Classifier: Topic :: Multimedia :: Graphics :: Graphics Conversion
|
|
18
|
+
Classifier: Topic :: Text Processing :: Markup :: Markdown
|
|
19
|
+
Requires-Python: >=3.9
|
|
20
|
+
Description-Content-Type: text/markdown
|
|
21
|
+
License-File: LICENSE
|
|
22
|
+
Requires-Dist: Pillow>=9.2
|
|
23
|
+
Dynamic: license-file
|
|
24
|
+
|
|
25
|
+
# table-png
|
|
26
|
+
|
|
27
|
+
[한국어](https://github.com/elfenomenokim/table-png/blob/main/README.ko.md)
|
|
28
|
+
|
|
29
|
+
Turn a table into a PNG image that renders correctly everywhere — Korean, Chinese and Japanese text included.
|
|
30
|
+
|
|
31
|
+

|
|
32
|
+
|
|
33
|
+
Chat apps, phone notifications, bots, issue trackers and social posts all show Markdown as literal pipes. This tool draws the table as an image instead, so the reader sees a table and not `| 서비스 | 상태 |`.
|
|
34
|
+
|
|
35
|
+
```console
|
|
36
|
+
$ pipx install table-png
|
|
37
|
+
$ table-png status.md --out status.png
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## Why
|
|
41
|
+
|
|
42
|
+
- **CJK text that actually renders.** The renderer picks a Korean-capable font on macOS, Linux and Windows, and falls back per glyph when a symbol is missing.
|
|
43
|
+
- **Colour emoji.** ✅ ⚠️ ❌ and family or flag sequences stay in colour when the system has a colour emoji font. Without one they show as boxes, and the command tells you which font to install.
|
|
44
|
+
- **Readable on a phone.** Cells wrap inside their column, widths balance across the table, and a long table paginates instead of shrinking to an unreadable strip.
|
|
45
|
+
- **Three input formats.** JSON, a Markdown pipe table, or CSV. Markdown markup (`**bold**`, `` `code` ``, links) is stripped to plain text, so a table copied out of a document works as is. Give it a whole Markdown answer: the first table is used and the prose around it is ignored.
|
|
46
|
+
- **One dependency.** Pillow. No browser, no headless Chrome, no network.
|
|
47
|
+
|
|
48
|
+
## Install
|
|
49
|
+
|
|
50
|
+
```console
|
|
51
|
+
$ pipx install table-png # recommended: isolated, on PATH
|
|
52
|
+
$ uvx table-png --help # or run without installing
|
|
53
|
+
$ pip install table-png # inside a project
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
Python 3.9 or newer. On a minimal Linux box you also need a CJK font:
|
|
57
|
+
|
|
58
|
+
```console
|
|
59
|
+
$ sudo apt install fonts-noto-cjk fonts-noto-color-emoji
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## Usage
|
|
63
|
+
|
|
64
|
+
### Markdown table
|
|
65
|
+
|
|
66
|
+
```console
|
|
67
|
+
$ table-png status.md --out status.png
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
```markdown
|
|
71
|
+
| 서비스 | 상태 | 응답 시간 |
|
|
72
|
+
|---|---|---|
|
|
73
|
+
| API | ✅ 정상 | 120ms |
|
|
74
|
+
| 배치 작업 | ⚠️ 지연 | 3.2s |
|
|
75
|
+
| 알림 발송 | ❌ 중단 | — |
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### CSV
|
|
79
|
+
|
|
80
|
+
```console
|
|
81
|
+
$ table-png report.csv --out report.png --title "주간 리포트"
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
### JSON
|
|
85
|
+
|
|
86
|
+
```console
|
|
87
|
+
$ table-png table.json --out table.png
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
```json
|
|
91
|
+
{
|
|
92
|
+
"headers": ["항목", "수량", "설명"],
|
|
93
|
+
"rows": [
|
|
94
|
+
["사과", 12, "아삭하고 달콤한 국내산 사과"],
|
|
95
|
+
["배", 3, "긴 설명도 셀 너비 안에서 줄바꿈됩니다"]
|
|
96
|
+
],
|
|
97
|
+
"align": ["l", "r", "l"]
|
|
98
|
+
}
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
`align` is optional; each entry is `l`, `c` or `r` and defaults to `l`.
|
|
102
|
+
|
|
103
|
+
### Pipe from another command
|
|
104
|
+
|
|
105
|
+
```console
|
|
106
|
+
$ some-command --format markdown | table-png - --out out.png
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
`-` is the default input, so the last argument can be omitted when the table arrives on stdin.
|
|
110
|
+
|
|
111
|
+
### Dark theme
|
|
112
|
+
|
|
113
|
+
For a dark chat client or a dark slide background:
|
|
114
|
+
|
|
115
|
+
```console
|
|
116
|
+
$ table-png status.md --out status-dark.png --theme dark
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+

|
|
120
|
+
|
|
121
|
+
### Wrapped cells
|
|
122
|
+
|
|
123
|
+
Long text wraps inside its column; the row grows and the table stays readable:
|
|
124
|
+
|
|
125
|
+

|
|
126
|
+
|
|
127
|
+
## Options
|
|
128
|
+
|
|
129
|
+
| Option | Default | Meaning |
|
|
130
|
+
|---|---|---|
|
|
131
|
+
| `INPUT` | stdin | Input file, or `-` for stdin |
|
|
132
|
+
| `-o`, `--out PATH` | required | Output PNG. Pagination adds `-001`, `-002`, … |
|
|
133
|
+
| `-f`, `--format auto\|json\|markdown\|csv` | `auto` | Input format. `auto` looks at the content, then the file extension |
|
|
134
|
+
| `--title TEXT` | empty | Heading drawn above the table |
|
|
135
|
+
| `-w`, `--width PX` | `1080` | Image width, clamped to 720–1600 |
|
|
136
|
+
| `--font-size PX` | `30` | Body text size; padding and title scale with it |
|
|
137
|
+
| `--rows-per-page N` | `40` | Rows per image before pagination |
|
|
138
|
+
| `--theme light\|dark` | `light` | Colour theme |
|
|
139
|
+
| `--font PATH` | auto | CJK-capable font file |
|
|
140
|
+
| `--emoji-font PATH` | auto | Colour emoji font file |
|
|
141
|
+
| `--json` | off | Print the machine-readable result object |
|
|
142
|
+
| `--version` | | Print the version |
|
|
143
|
+
|
|
144
|
+
Environment variables: `TABLE_PNG_FONT` and `TABLE_PNG_EMOJI_FONT` do the same as `--font` and `--emoji-font`.
|
|
145
|
+
|
|
146
|
+
### Result object
|
|
147
|
+
|
|
148
|
+
With `--json` the command prints one JSON object and exits non-zero on failure:
|
|
149
|
+
|
|
150
|
+
```json
|
|
151
|
+
{"ok":true,"png":"/abs/status.png","width":1080,"height":401,"rows":4}
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
A paginated render returns arrays: `"png": ["…-001.png", "…-002.png"]` and a matching `"height"`. An error prints `{"error":"…"}` and exits 1.
|
|
155
|
+
|
|
156
|
+
## Python API
|
|
157
|
+
|
|
158
|
+
```python
|
|
159
|
+
from pathlib import Path
|
|
160
|
+
|
|
161
|
+
from table_png import RenderOptions, read_table, render_table
|
|
162
|
+
|
|
163
|
+
table = read_table("| 이름 | 점수 |\n|---|---|\n| 김 | 92 |", fmt="markdown")
|
|
164
|
+
result = render_table(
|
|
165
|
+
table,
|
|
166
|
+
Path("score.png"),
|
|
167
|
+
RenderOptions(title="점수", theme="dark", width=900),
|
|
168
|
+
)
|
|
169
|
+
print(result["png"], result["height"])
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
`read_table(text, fmt="auto")` parses a string; `read_source(path_or_dash)` reads a file or stdin; `render_table(table, path, options)` draws the pages.
|
|
173
|
+
|
|
174
|
+
## Fonts
|
|
175
|
+
|
|
176
|
+
The first font that loads wins. Override it with `--font` or `TABLE_PNG_FONT`.
|
|
177
|
+
|
|
178
|
+
| Platform | Text font | Colour emoji |
|
|
179
|
+
|---|---|---|
|
|
180
|
+
| macOS | Apple SD Gothic Neo, PingFang, Arial Unicode | Apple Color Emoji |
|
|
181
|
+
| Linux | Noto Sans CJK (several distro paths), NanumGothic, UnDotum, then `fc-match sans-serif:lang=ko` | Noto Color Emoji, then `fc-match emoji` |
|
|
182
|
+
| Windows | Malgun Gothic, Yu Gothic, Microsoft YaHei, MS Gothic, SimSun | Segoe UI Emoji |
|
|
183
|
+
|
|
184
|
+
Tested on macOS and Ubuntu 24.04. The Windows font paths are standard but not yet tested; reports welcome.
|
|
185
|
+
|
|
186
|
+
If no CJK font can be found, the command fails with a message that names `--font` and `TABLE_PNG_FONT` instead of drawing empty boxes.
|
|
187
|
+
|
|
188
|
+
## Agents
|
|
189
|
+
|
|
190
|
+
If you are an AI agent asked to produce a table image, read [AGENTS.md](https://github.com/elfenomenokim/table-png/blob/main/AGENTS.md). The Claude Code skill lives in [`skill/table-png/SKILL.md`](https://github.com/elfenomenokim/table-png/blob/main/skill/table-png/SKILL.md); install it by copying that folder to `~/.claude/skills/table-png/`.
|
|
191
|
+
|
|
192
|
+
## License
|
|
193
|
+
|
|
194
|
+
MIT — see [LICENSE](https://github.com/elfenomenokim/table-png/blob/main/LICENSE).
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
# table-png
|
|
2
|
+
|
|
3
|
+
[한국어](https://github.com/elfenomenokim/table-png/blob/main/README.ko.md)
|
|
4
|
+
|
|
5
|
+
Turn a table into a PNG image that renders correctly everywhere — Korean, Chinese and Japanese text included.
|
|
6
|
+
|
|
7
|
+

|
|
8
|
+
|
|
9
|
+
Chat apps, phone notifications, bots, issue trackers and social posts all show Markdown as literal pipes. This tool draws the table as an image instead, so the reader sees a table and not `| 서비스 | 상태 |`.
|
|
10
|
+
|
|
11
|
+
```console
|
|
12
|
+
$ pipx install table-png
|
|
13
|
+
$ table-png status.md --out status.png
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## Why
|
|
17
|
+
|
|
18
|
+
- **CJK text that actually renders.** The renderer picks a Korean-capable font on macOS, Linux and Windows, and falls back per glyph when a symbol is missing.
|
|
19
|
+
- **Colour emoji.** ✅ ⚠️ ❌ and family or flag sequences stay in colour when the system has a colour emoji font. Without one they show as boxes, and the command tells you which font to install.
|
|
20
|
+
- **Readable on a phone.** Cells wrap inside their column, widths balance across the table, and a long table paginates instead of shrinking to an unreadable strip.
|
|
21
|
+
- **Three input formats.** JSON, a Markdown pipe table, or CSV. Markdown markup (`**bold**`, `` `code` ``, links) is stripped to plain text, so a table copied out of a document works as is. Give it a whole Markdown answer: the first table is used and the prose around it is ignored.
|
|
22
|
+
- **One dependency.** Pillow. No browser, no headless Chrome, no network.
|
|
23
|
+
|
|
24
|
+
## Install
|
|
25
|
+
|
|
26
|
+
```console
|
|
27
|
+
$ pipx install table-png # recommended: isolated, on PATH
|
|
28
|
+
$ uvx table-png --help # or run without installing
|
|
29
|
+
$ pip install table-png # inside a project
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Python 3.9 or newer. On a minimal Linux box you also need a CJK font:
|
|
33
|
+
|
|
34
|
+
```console
|
|
35
|
+
$ sudo apt install fonts-noto-cjk fonts-noto-color-emoji
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## Usage
|
|
39
|
+
|
|
40
|
+
### Markdown table
|
|
41
|
+
|
|
42
|
+
```console
|
|
43
|
+
$ table-png status.md --out status.png
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
```markdown
|
|
47
|
+
| 서비스 | 상태 | 응답 시간 |
|
|
48
|
+
|---|---|---|
|
|
49
|
+
| API | ✅ 정상 | 120ms |
|
|
50
|
+
| 배치 작업 | ⚠️ 지연 | 3.2s |
|
|
51
|
+
| 알림 발송 | ❌ 중단 | — |
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
### CSV
|
|
55
|
+
|
|
56
|
+
```console
|
|
57
|
+
$ table-png report.csv --out report.png --title "주간 리포트"
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
### JSON
|
|
61
|
+
|
|
62
|
+
```console
|
|
63
|
+
$ table-png table.json --out table.png
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
```json
|
|
67
|
+
{
|
|
68
|
+
"headers": ["항목", "수량", "설명"],
|
|
69
|
+
"rows": [
|
|
70
|
+
["사과", 12, "아삭하고 달콤한 국내산 사과"],
|
|
71
|
+
["배", 3, "긴 설명도 셀 너비 안에서 줄바꿈됩니다"]
|
|
72
|
+
],
|
|
73
|
+
"align": ["l", "r", "l"]
|
|
74
|
+
}
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
`align` is optional; each entry is `l`, `c` or `r` and defaults to `l`.
|
|
78
|
+
|
|
79
|
+
### Pipe from another command
|
|
80
|
+
|
|
81
|
+
```console
|
|
82
|
+
$ some-command --format markdown | table-png - --out out.png
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
`-` is the default input, so the last argument can be omitted when the table arrives on stdin.
|
|
86
|
+
|
|
87
|
+
### Dark theme
|
|
88
|
+
|
|
89
|
+
For a dark chat client or a dark slide background:
|
|
90
|
+
|
|
91
|
+
```console
|
|
92
|
+
$ table-png status.md --out status-dark.png --theme dark
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+

|
|
96
|
+
|
|
97
|
+
### Wrapped cells
|
|
98
|
+
|
|
99
|
+
Long text wraps inside its column; the row grows and the table stays readable:
|
|
100
|
+
|
|
101
|
+

|
|
102
|
+
|
|
103
|
+
## Options
|
|
104
|
+
|
|
105
|
+
| Option | Default | Meaning |
|
|
106
|
+
|---|---|---|
|
|
107
|
+
| `INPUT` | stdin | Input file, or `-` for stdin |
|
|
108
|
+
| `-o`, `--out PATH` | required | Output PNG. Pagination adds `-001`, `-002`, … |
|
|
109
|
+
| `-f`, `--format auto\|json\|markdown\|csv` | `auto` | Input format. `auto` looks at the content, then the file extension |
|
|
110
|
+
| `--title TEXT` | empty | Heading drawn above the table |
|
|
111
|
+
| `-w`, `--width PX` | `1080` | Image width, clamped to 720–1600 |
|
|
112
|
+
| `--font-size PX` | `30` | Body text size; padding and title scale with it |
|
|
113
|
+
| `--rows-per-page N` | `40` | Rows per image before pagination |
|
|
114
|
+
| `--theme light\|dark` | `light` | Colour theme |
|
|
115
|
+
| `--font PATH` | auto | CJK-capable font file |
|
|
116
|
+
| `--emoji-font PATH` | auto | Colour emoji font file |
|
|
117
|
+
| `--json` | off | Print the machine-readable result object |
|
|
118
|
+
| `--version` | | Print the version |
|
|
119
|
+
|
|
120
|
+
Environment variables: `TABLE_PNG_FONT` and `TABLE_PNG_EMOJI_FONT` do the same as `--font` and `--emoji-font`.
|
|
121
|
+
|
|
122
|
+
### Result object
|
|
123
|
+
|
|
124
|
+
With `--json` the command prints one JSON object and exits non-zero on failure:
|
|
125
|
+
|
|
126
|
+
```json
|
|
127
|
+
{"ok":true,"png":"/abs/status.png","width":1080,"height":401,"rows":4}
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
A paginated render returns arrays: `"png": ["…-001.png", "…-002.png"]` and a matching `"height"`. An error prints `{"error":"…"}` and exits 1.
|
|
131
|
+
|
|
132
|
+
## Python API
|
|
133
|
+
|
|
134
|
+
```python
|
|
135
|
+
from pathlib import Path
|
|
136
|
+
|
|
137
|
+
from table_png import RenderOptions, read_table, render_table
|
|
138
|
+
|
|
139
|
+
table = read_table("| 이름 | 점수 |\n|---|---|\n| 김 | 92 |", fmt="markdown")
|
|
140
|
+
result = render_table(
|
|
141
|
+
table,
|
|
142
|
+
Path("score.png"),
|
|
143
|
+
RenderOptions(title="점수", theme="dark", width=900),
|
|
144
|
+
)
|
|
145
|
+
print(result["png"], result["height"])
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
`read_table(text, fmt="auto")` parses a string; `read_source(path_or_dash)` reads a file or stdin; `render_table(table, path, options)` draws the pages.
|
|
149
|
+
|
|
150
|
+
## Fonts
|
|
151
|
+
|
|
152
|
+
The first font that loads wins. Override it with `--font` or `TABLE_PNG_FONT`.
|
|
153
|
+
|
|
154
|
+
| Platform | Text font | Colour emoji |
|
|
155
|
+
|---|---|---|
|
|
156
|
+
| macOS | Apple SD Gothic Neo, PingFang, Arial Unicode | Apple Color Emoji |
|
|
157
|
+
| Linux | Noto Sans CJK (several distro paths), NanumGothic, UnDotum, then `fc-match sans-serif:lang=ko` | Noto Color Emoji, then `fc-match emoji` |
|
|
158
|
+
| Windows | Malgun Gothic, Yu Gothic, Microsoft YaHei, MS Gothic, SimSun | Segoe UI Emoji |
|
|
159
|
+
|
|
160
|
+
Tested on macOS and Ubuntu 24.04. The Windows font paths are standard but not yet tested; reports welcome.
|
|
161
|
+
|
|
162
|
+
If no CJK font can be found, the command fails with a message that names `--font` and `TABLE_PNG_FONT` instead of drawing empty boxes.
|
|
163
|
+
|
|
164
|
+
## Agents
|
|
165
|
+
|
|
166
|
+
If you are an AI agent asked to produce a table image, read [AGENTS.md](https://github.com/elfenomenokim/table-png/blob/main/AGENTS.md). The Claude Code skill lives in [`skill/table-png/SKILL.md`](https://github.com/elfenomenokim/table-png/blob/main/skill/table-png/SKILL.md); install it by copying that folder to `~/.claude/skills/table-png/`.
|
|
167
|
+
|
|
168
|
+
## License
|
|
169
|
+
|
|
170
|
+
MIT — see [LICENSE](https://github.com/elfenomenokim/table-png/blob/main/LICENSE).
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=77"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "table-png"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Render a table (Markdown, CSV or JSON) as a PNG image with correct Korean, Chinese and Japanese text and colour emoji, for chat apps, notifications and bots that cannot show a Markdown table."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.9"
|
|
11
|
+
license = "MIT"
|
|
12
|
+
license-files = ["LICENSE"]
|
|
13
|
+
authors = [{ name = "El Fenomeno" }]
|
|
14
|
+
keywords = [
|
|
15
|
+
"table",
|
|
16
|
+
"png",
|
|
17
|
+
"image",
|
|
18
|
+
"markdown",
|
|
19
|
+
"csv",
|
|
20
|
+
"cjk",
|
|
21
|
+
"korean",
|
|
22
|
+
"emoji",
|
|
23
|
+
"chat",
|
|
24
|
+
"cli",
|
|
25
|
+
]
|
|
26
|
+
classifiers = [
|
|
27
|
+
"Development Status :: 4 - Beta",
|
|
28
|
+
"Environment :: Console",
|
|
29
|
+
"Intended Audience :: Developers",
|
|
30
|
+
"Operating System :: OS Independent",
|
|
31
|
+
"Programming Language :: Python :: 3",
|
|
32
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
33
|
+
"Topic :: Multimedia :: Graphics :: Graphics Conversion",
|
|
34
|
+
"Topic :: Text Processing :: Markup :: Markdown",
|
|
35
|
+
]
|
|
36
|
+
dependencies = ["Pillow>=9.2"]
|
|
37
|
+
|
|
38
|
+
[project.urls]
|
|
39
|
+
Homepage = "https://github.com/elfenomenokim/table-png"
|
|
40
|
+
Repository = "https://github.com/elfenomenokim/table-png"
|
|
41
|
+
Issues = "https://github.com/elfenomenokim/table-png/issues"
|
|
42
|
+
|
|
43
|
+
[project.scripts]
|
|
44
|
+
table-png = "table_png.cli:main"
|
|
45
|
+
|
|
46
|
+
[tool.setuptools]
|
|
47
|
+
package-dir = { "" = "src" }
|
|
48
|
+
|
|
49
|
+
[tool.setuptools.packages.find]
|
|
50
|
+
where = ["src"]
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"""Render a small table as a PNG with correct Korean, Chinese and Japanese text."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
__version__ = "0.1.0"
|
|
6
|
+
|
|
7
|
+
from .inputs import Table, read_source, read_table # noqa: E402
|
|
8
|
+
from .render import RenderOptions, render_table # noqa: E402
|
|
9
|
+
from .theme import THEMES # noqa: E402
|
|
10
|
+
|
|
11
|
+
__all__ = [
|
|
12
|
+
"RenderOptions",
|
|
13
|
+
"THEMES",
|
|
14
|
+
"Table",
|
|
15
|
+
"__version__",
|
|
16
|
+
"read_source",
|
|
17
|
+
"read_table",
|
|
18
|
+
"render_table",
|
|
19
|
+
]
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
"""Command line entry point: `table-png`."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import argparse
|
|
6
|
+
import json
|
|
7
|
+
from pathlib import Path
|
|
8
|
+
|
|
9
|
+
from . import __version__
|
|
10
|
+
from .fonts import EMOJI_FONT_ENV, FONT_ENV, FontError
|
|
11
|
+
from .inputs import FORMATS, InputError, read_source
|
|
12
|
+
from .render import DEFAULT_ROWS_PER_PAGE, DEFAULT_WIDTH, RenderOptions, render_table
|
|
13
|
+
from .theme import THEMES
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class JsonArgumentParser(argparse.ArgumentParser):
|
|
17
|
+
"""argparse that reports errors through the JSON contract instead of exiting."""
|
|
18
|
+
|
|
19
|
+
def error(self, message: str) -> None: # type: ignore[override]
|
|
20
|
+
raise ValueError(message)
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def build_parser() -> argparse.ArgumentParser:
|
|
24
|
+
parser = JsonArgumentParser(
|
|
25
|
+
prog="table-png",
|
|
26
|
+
description=(
|
|
27
|
+
"Render a small table as a PNG image with correct Korean, Chinese and "
|
|
28
|
+
"Japanese text, for places that cannot show a Markdown table."
|
|
29
|
+
),
|
|
30
|
+
)
|
|
31
|
+
parser.add_argument(
|
|
32
|
+
"input",
|
|
33
|
+
nargs="?",
|
|
34
|
+
default=None,
|
|
35
|
+
help="input file, or - for stdin (default: stdin)",
|
|
36
|
+
)
|
|
37
|
+
parser.add_argument(
|
|
38
|
+
"--in",
|
|
39
|
+
dest="input_option",
|
|
40
|
+
default=None,
|
|
41
|
+
metavar="PATH",
|
|
42
|
+
help="input file (same as the positional argument; kept for existing scripts)",
|
|
43
|
+
)
|
|
44
|
+
parser.add_argument(
|
|
45
|
+
"-o", "--out", required=True, help="output PNG path (pagination adds -001, -002, ...)"
|
|
46
|
+
)
|
|
47
|
+
parser.add_argument(
|
|
48
|
+
"-f",
|
|
49
|
+
"--format",
|
|
50
|
+
choices=FORMATS,
|
|
51
|
+
default="auto",
|
|
52
|
+
help="input format (default: auto)",
|
|
53
|
+
)
|
|
54
|
+
parser.add_argument("--title", default="", help="heading drawn above the table")
|
|
55
|
+
parser.add_argument(
|
|
56
|
+
"-w",
|
|
57
|
+
"--width",
|
|
58
|
+
type=int,
|
|
59
|
+
default=DEFAULT_WIDTH,
|
|
60
|
+
help=f"image width in pixels, clamped to 720-1600 (default: {DEFAULT_WIDTH})",
|
|
61
|
+
)
|
|
62
|
+
parser.add_argument(
|
|
63
|
+
"--font-size", type=int, default=30, help="body text size in pixels (default: 30)"
|
|
64
|
+
)
|
|
65
|
+
parser.add_argument(
|
|
66
|
+
"--rows-per-page",
|
|
67
|
+
type=int,
|
|
68
|
+
default=DEFAULT_ROWS_PER_PAGE,
|
|
69
|
+
help=f"rows per image before pagination (default: {DEFAULT_ROWS_PER_PAGE})",
|
|
70
|
+
)
|
|
71
|
+
parser.add_argument(
|
|
72
|
+
"--theme",
|
|
73
|
+
choices=sorted(THEMES),
|
|
74
|
+
default="light",
|
|
75
|
+
help="colour theme (default: light)",
|
|
76
|
+
)
|
|
77
|
+
parser.add_argument(
|
|
78
|
+
"--font", default=None, help=f"path to a CJK-capable font (or set {FONT_ENV})"
|
|
79
|
+
)
|
|
80
|
+
parser.add_argument(
|
|
81
|
+
"--emoji-font",
|
|
82
|
+
default=None,
|
|
83
|
+
help=f"path to a colour emoji font (or set {EMOJI_FONT_ENV})",
|
|
84
|
+
)
|
|
85
|
+
parser.add_argument(
|
|
86
|
+
"--json", action="store_true", help="print the machine-readable result object"
|
|
87
|
+
)
|
|
88
|
+
parser.add_argument("--version", action="version", version=f"%(prog)s {__version__}")
|
|
89
|
+
return parser
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
def main(argv: list[str] | None = None) -> int:
|
|
93
|
+
try:
|
|
94
|
+
args = build_parser().parse_args(argv)
|
|
95
|
+
source = args.input_option or args.input or "-"
|
|
96
|
+
table = read_source(source, args.format)
|
|
97
|
+
options = RenderOptions(
|
|
98
|
+
width=args.width,
|
|
99
|
+
font_size=args.font_size,
|
|
100
|
+
rows_per_page=args.rows_per_page,
|
|
101
|
+
theme=args.theme,
|
|
102
|
+
title=args.title,
|
|
103
|
+
font_path=args.font,
|
|
104
|
+
emoji_font_path=args.emoji_font,
|
|
105
|
+
)
|
|
106
|
+
result = render_table(table, Path(args.out), options)
|
|
107
|
+
except (ValueError, OSError, FontError, InputError) as exc:
|
|
108
|
+
print(json.dumps({"error": str(exc)}, ensure_ascii=False, separators=(",", ":")))
|
|
109
|
+
return 1
|
|
110
|
+
if args.json:
|
|
111
|
+
print(json.dumps(result, ensure_ascii=False, separators=(",", ":")))
|
|
112
|
+
else:
|
|
113
|
+
pages = result["png"]
|
|
114
|
+
for path in pages if isinstance(pages, list) else [pages]:
|
|
115
|
+
print(path)
|
|
116
|
+
return 0
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
if __name__ == "__main__":
|
|
120
|
+
raise SystemExit(main())
|