tentags 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.
- tentags-0.1.0/LICENSE +21 -0
- tentags-0.1.0/MANIFEST.in +14 -0
- tentags-0.1.0/PKG-INFO +220 -0
- tentags-0.1.0/README.md +183 -0
- tentags-0.1.0/example.png +0 -0
- tentags-0.1.0/pyproject.toml +53 -0
- tentags-0.1.0/requirements.txt +2 -0
- tentags-0.1.0/setup.cfg +4 -0
- tentags-0.1.0/setup.py +4 -0
- tentags-0.1.0/tentags.egg-info/PKG-INFO +220 -0
- tentags-0.1.0/tentags.egg-info/SOURCES.txt +16 -0
- tentags-0.1.0/tentags.egg-info/dependency_links.txt +1 -0
- tentags-0.1.0/tentags.egg-info/requires.txt +11 -0
- tentags-0.1.0/tentags.egg-info/top_level.txt +1 -0
- tentags-0.1.0/tentags.py +770 -0
- tentags-0.1.0/tentags_logo.png +0 -0
- tentags-0.1.0/test_data.csv +3 -0
- tentags-0.1.0/test_library.py +213 -0
tentags-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Zhandos Mambetali
|
|
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,14 @@
|
|
|
1
|
+
include README.md
|
|
2
|
+
include LICENSE
|
|
3
|
+
include requirements.txt
|
|
4
|
+
include pyproject.toml
|
|
5
|
+
include test_data.csv
|
|
6
|
+
include test_library.py
|
|
7
|
+
include tentags_logo.png
|
|
8
|
+
include example.png
|
|
9
|
+
|
|
10
|
+
exclude *.xlsx
|
|
11
|
+
exclude *.html
|
|
12
|
+
recursive-exclude __pycache__ *
|
|
13
|
+
recursive-exclude venv *
|
|
14
|
+
recursive-exclude .pytest_cache *
|
tentags-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: tentags
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Advanced Table Markdown for HTML & Excel spreadsheets with rich styling and multi-cell merge grids using 10 core tags.
|
|
5
|
+
Author-email: Zhandos Mambetali <zhandos.mambetali@gmail.com>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://pycells.com
|
|
8
|
+
Project-URL: Documentation, https://pycells.com/tentags
|
|
9
|
+
Project-URL: Repository, https://github.com/Jandos77/tentags
|
|
10
|
+
Project-URL: Issues, https://github.com/Jandos77/tentags/issues
|
|
11
|
+
Keywords: html,excel,xlsx,table,generator,spreadsheet,pycells,tags,parser
|
|
12
|
+
Classifier: Development Status :: 4 - Beta
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: Operating System :: OS Independent
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
21
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
22
|
+
Classifier: Topic :: Text Processing :: Markup :: HTML
|
|
23
|
+
Classifier: Topic :: Office/Business :: Financial :: Spreadsheet
|
|
24
|
+
Requires-Python: >=3.8
|
|
25
|
+
Description-Content-Type: text/markdown
|
|
26
|
+
License-File: LICENSE
|
|
27
|
+
Provides-Extra: excel
|
|
28
|
+
Requires-Dist: openpyxl>=3.1.0; extra == "excel"
|
|
29
|
+
Requires-Dist: et_xmlfile>=2.0.0; extra == "excel"
|
|
30
|
+
Provides-Extra: dev
|
|
31
|
+
Requires-Dist: openpyxl>=3.1.0; extra == "dev"
|
|
32
|
+
Requires-Dist: et_xmlfile>=2.0.0; extra == "dev"
|
|
33
|
+
Requires-Dist: pytest>=7.0.0; extra == "dev"
|
|
34
|
+
Requires-Dist: build>=1.0.0; extra == "dev"
|
|
35
|
+
Requires-Dist: twine>=4.0.0; extra == "dev"
|
|
36
|
+
Dynamic: license-file
|
|
37
|
+
|
|
38
|
+
# TenTags ๐ท๏ธ
|
|
39
|
+
|
|
40
|
+
<p align="center">
|
|
41
|
+
<img src="tentags_logo.png" alt="TenTags Logo" width="450">
|
|
42
|
+
</p>
|
|
43
|
+
|
|
44
|
+
[](https://pypi.org/project/tentags/)
|
|
45
|
+
[](https://pypi.org/project/tentags/)
|
|
46
|
+
[](https://opensource.org/licenses/MIT)
|
|
47
|
+
|
|
48
|
+
**TenTags** is a standalone, zero-dependency **Advanced Table Markdown** library for Python. It turns compact, expressive string formulas into pixel-perfect **HTML** and native **Excel (`.xlsx`)** spreadsheets using **10 core structural and styling tags**.
|
|
49
|
+
|
|
50
|
+
### ๐ก Why TenTags? (Advanced Markdown for Tables)
|
|
51
|
+
|
|
52
|
+
Standard Markdown (`| A | B |`) is notoriously rigid when it comes to tables: it cannot merge complex cell grids across rows (`rowspan`) or columns (`colspan`), it lacks background fills and typography controls, and it cannot compile directly to native Excel spreadsheets.
|
|
53
|
+
|
|
54
|
+
**TenTags** bridges this gap. Think of it as **next-generation Table Markdown** that gives you:
|
|
55
|
+
- ๐ **Advanced Grid Merges**: Effortlessly merge cells rightward across columns (`<cm>`) and downward across rows (`<rm>`).
|
|
56
|
+
- ๐จ **Rich Typography & Styling**: Inline control over font size (`<fs>`), bold (`<b>`), italic (`<i>`), horizontal alignment (`<left>`, `<center>`, `<right>`), text color (`<color=>`), and cell fills (`<bg=>`).
|
|
57
|
+
- ๐ **Native Excel Export**: Directly compiles your markup into styled, production-ready `.xlsx` files with exact `openpyxl` grid merges (`ws.merge_cells`), font weights, text alignments, and pattern fills.
|
|
58
|
+
- โก **Zero Core Dependencies**: Pure Python runtime (`xml.etree.ElementTree`) that tokenizes and parses at lightning speed.
|
|
59
|
+
|
|
60
|
+
---
|
|
61
|
+
|
|
62
|
+
## ๐ฆ Installation
|
|
63
|
+
|
|
64
|
+
Install from PyPI via pip:
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
pip install tentags
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
If you plan to export to Excel (`.xlsx`), install the optional `excel` dependency:
|
|
71
|
+
|
|
72
|
+
```bash
|
|
73
|
+
pip install tentags[excel]
|
|
74
|
+
# or directly: pip install openpyxl
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
---
|
|
78
|
+
|
|
79
|
+
## ๐ Quickstart
|
|
80
|
+
|
|
81
|
+
```python
|
|
82
|
+
import tentags
|
|
83
|
+
|
|
84
|
+
# Define a table expression with custom border color, background fill, and tags
|
|
85
|
+
formula = '2,2,1,"#0f172a","solid",0,40, data(Header 1, <b>Header 2</b>; <color=red><i>Red Italic</i></color>, <bg=#e2e8f0>Gray Cell</bg>)'
|
|
86
|
+
|
|
87
|
+
# 1. Direct rendering to HTML string
|
|
88
|
+
html = tentags.render(formula)
|
|
89
|
+
print(html)
|
|
90
|
+
|
|
91
|
+
# 2. Parsing to intermediate TableModel
|
|
92
|
+
model = tentags.parse(formula)
|
|
93
|
+
print(f"Rows: {model.rows}, Cols: {model.cols}, Border: {model.border_color}")
|
|
94
|
+
|
|
95
|
+
# 3. Render TableModel to Excel (.xlsx) file
|
|
96
|
+
tentags.render_xlsx(model, "styled_report.xlsx")
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
---
|
|
100
|
+
|
|
101
|
+
## ๐จ Advanced Example: Beautiful Styled Table & Merges
|
|
102
|
+
|
|
103
|
+
Here is how a single, clean **TenTags** expression generates an enterprise-grade financial dashboard table featuring merged headers (`<cm>`), custom font sizing (`<fs>`), cell background colors (`<bg=>`), text alignment (`<left>`, `<right>`), and custom typography (`<b>`, `<i>`, `<color=>`) across both **HTML** and **Excel (`.xlsx`)**:
|
|
104
|
+
|
|
105
|
+
```python
|
|
106
|
+
import tentags
|
|
107
|
+
|
|
108
|
+
# Define an advanced 4x4 styled financial performance grid
|
|
109
|
+
formula = '''4,4,1,"#cbd5e1","solid",0,45, data(
|
|
110
|
+
<fs=18><bg=#1e293b><color=white><b><cm>Q3 Financial Performance Dashboard</cm></b></color></bg></fs>, None, None, None;
|
|
111
|
+
<bg=#f1f5f9><b><left>Department</left></b></bg>, <bg=#f1f5f9><b><center>Revenue</center></b></bg>, <bg=#f1f5f9><b><center>Expenses</center></b></bg>, <bg=#f1f5f9><b><center>Net Profit</center></b></bg>;
|
|
112
|
+
<left>Engineering</left>, <right>"$240,000"</right>, <right>"$180,000"</right>, <bg=#dcfce7><color=#166534><b><right>"+$60,000"</right></b></color></bg>;
|
|
113
|
+
<left>Sales & Marketing</left>, <right>"$310,000"</right>, <right>"$210,000"</right>, <bg=#dcfce7><color=#166534><b><right>"+$100,000"</right></b></color></bg>
|
|
114
|
+
)'''
|
|
115
|
+
|
|
116
|
+
# 1. Export directly to native Excel spreadsheet with exact fonts, fills, & merge_cells
|
|
117
|
+
model = tentags.parse(formula)
|
|
118
|
+
tentags.render_xlsx(model, "Q3_Financial_Dashboard.xlsx")
|
|
119
|
+
|
|
120
|
+
# 2. Render to responsive HTML string with inline CSS
|
|
121
|
+
html_table = tentags.render_html(model)
|
|
122
|
+
print(html_table)
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
### ๐ Visual Structure & Styling Result:
|
|
126
|
+
|
|
127
|
+
| Department / Header | Revenue | Expenses | Net Profit |
|
|
128
|
+
| :--- | :---: | :---: | :---: |
|
|
129
|
+
| **Q3 Financial Performance Dashboard** *(Merged across 4 columns (`colspan=4`), 18px Bold, White text, Dark Slate `#1e293b` background)* | โ | โ | โ |
|
|
130
|
+
| **Department** *(Left aligned, Light Gray `#f1f5f9` BG)* | **Revenue** *(Centered, Bold)* | **Expenses** *(Centered, Bold)* | **Net Profit** *(Centered, Bold)* |
|
|
131
|
+
| Engineering *(Left aligned)* | $240,000 *(Right aligned)* | $180,000 *(Right aligned)* | **+$60,000** *(Right aligned, Bold, Green `#dcfce7` BG, Dark Green text)* |
|
|
132
|
+
| Sales & Marketing *(Left aligned)* | $310,000 *(Right aligned)* | $210,000 *(Right aligned)* | **+$100,000** *(Right aligned, Bold, Green `#dcfce7` BG, Dark Green text)* |
|
|
133
|
+
|
|
134
|
+
---
|
|
135
|
+
|
|
136
|
+
## ๐ Excel Matrix Example: Row Merges (`<rm>`), Column Merges (`<cm>`) & Colors
|
|
137
|
+
|
|
138
|
+
To see how **TenTags** shines as a native Excel spreadsheet generator, here is a 5x5 **Enterprise Allocation Matrix** utilizing combined row merges (`<rm>`), multi-column merges (`<cm>`), and classic Microsoft Excel color palettes (`#1F4E78`, `#DDEBF7`, `#E2EFDA`, `#FFF2CC`):
|
|
139
|
+
|
|
140
|
+
```python
|
|
141
|
+
import tentags
|
|
142
|
+
|
|
143
|
+
# Define an Excel matrix with vertical row merges (<rm>) and horizontal column merges (<cm>)
|
|
144
|
+
excel_formula = '''5,5,1,"#B0C4DE","solid",0,35, data(
|
|
145
|
+
<fs=16><bg=#1F4E78><color=white><b><cm>2026 Enterprise Budget & Allocation Matrix, None, None, None, None</cm></b></color></bg></fs>;
|
|
146
|
+
<bg=#DDEBF7><b><rm><center>Category</center></rm></b></bg>, <bg=#DDEBF7><b><cm><center>Q1 & Q2 Allocation</center>, None</cm></b></bg>, <bg=#DDEBF7><b><cm><center>Q3 & Q4 Allocation</center>, None</cm></b></bg>;
|
|
147
|
+
<bg=#DDEBF7><b><rm>None</rm></b></bg>, <bg=#F2F2F2><b><center>Hardware</center></b></bg>, <bg=#F2F2F2><b><center>Software</center></b></bg>, <bg=#F2F2F2><b><center>Hardware</center></b></bg>, <bg=#F2F2F2><b><center>Software</center></b></bg>;
|
|
148
|
+
<bg=#FFF2CC><b><left>R&D Division</left></b></bg>, <right>"$150,000"</right>, <right>"$85,000"</right>, <right>"$120,000"</right>, <right>"$95,000"</right>;
|
|
149
|
+
<bg=#E2EFDA><color=#375623><b><left>Total Budget</left></b></color></bg>, <bg=#E2EFDA><color=#375623><b><cm><right>"$235,000"</right>, None</cm></b></color></bg>, <bg=#E2EFDA><color=#375623><b><cm><right>"+$215,000"</right>, None</cm></b></color></bg>
|
|
150
|
+
)'''
|
|
151
|
+
|
|
152
|
+
# Export to a native Excel spreadsheet (.xlsx) with true merged regions & fills
|
|
153
|
+
model = tentags.parse(excel_formula)
|
|
154
|
+
tentags.render_xlsx(model, "Enterprise_Budget_Matrix.xlsx")
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
### ๐๏ธ Visual Spreadsheet Grid Structure (`A1:E5`):
|
|
158
|
+
|
|
159
|
+
<p align="center">
|
|
160
|
+
<img src="example.png" alt="TenTags Excel Matrix Output" width="750">
|
|
161
|
+
</p>
|
|
162
|
+
|
|
163
|
+
Notice how `None` is passed in slots that get swallowed by an adjacent cell's `<cm>` horizontal merge or `<rm>` vertical merge. When opened in Microsoft Excel or rendered in HTML, the boundaries cleanly dissolve into unified multi-cell headers and summary blocks!
|
|
164
|
+
|
|
165
|
+
---
|
|
166
|
+
|
|
167
|
+
## ๐ท๏ธ The 10 Tags in `data(...)`
|
|
168
|
+
|
|
169
|
+
TenTags derives its name from the **10 core structural and styling tags** supported inside the `data(...)` argument block:
|
|
170
|
+
|
|
171
|
+
| # | Tag / Syntax | Type | Description | Example |
|
|
172
|
+
|---|---|---|---|---|
|
|
173
|
+
| 1 | `<fs=...>` | Typography | Sets custom font size (`font-size` in HTML, `size` in Excel `openpyxl`). | `data(<fs=16>Heading</fs>, Text)` |
|
|
174
|
+
| 2 | `<b>...</b>` | Typography | Renders cell text in **Bold** font weight (`font-weight: bold`). | `data(<b>Total</b>, 100)` |
|
|
175
|
+
| 3 | `<i>...</i>` | Typography | Renders cell text in *Italic* font style (`font-style: italic`). | `data(<i>Pending</i>, Done)` |
|
|
176
|
+
| 4 | `<left>` | Alignment | Aligns cell content to the **left** (`text-align: left`). | `data(<left>Left aligned text)` |
|
|
177
|
+
| 5 | `<center>` | Alignment | Aligns cell content to the **center** (`text-align: center`). | `data(<center>Centered text)` |
|
|
178
|
+
| 6 | `<right>` | Alignment | Aligns cell content to the **right** (`text-align: right`). | `data(<right>Right aligned $5,000)` |
|
|
179
|
+
| 7 | `<color=...>` | Text Color | Sets custom HEX or CSS text color (`color: ...` / font color). | `data(<color=#ef4444>Error</color>, OK)` |
|
|
180
|
+
| 8 | `<bg=...>` | Background Fill | Sets cell background fill color (`background-color: ...` / PatternFill). | `data(<bg=#f8fafc>Summary</bg>, $500)` |
|
|
181
|
+
| 9 | `<cm>...</cm>` | Column Merge | Merges the cell rightward with adjacent columns (`colspan`). | `data(<cm>Merged Title</cm>, None; A, B)` |
|
|
182
|
+
| 10 | `<rm>...</rm>` | Row Merge | Merges the cell downward with rows below it (`rowspan`). | `data(<rm>Date</rm>, Job; <cm>, Engineer)` |
|
|
183
|
+
|
|
184
|
+
> **Note on Tag Transfer**: When merging (`<cm>`, `<rm>`) or expanding ranges across styled cells (`<fs>`, `<b>`, `<i>`, `<color>`, `<bg>`, `<left>`, `<center>`, `<right>`), TenTags automatically transfers and preserves all formatting across cell boundaries in both HTML and Excel outputs.
|
|
185
|
+
>
|
|
186
|
+
> **Dynamic Data Expressions**: In addition to the 10 markup tags above, TenTags `data(...)` supports dynamic line numbering (`#`), variable context substitution (`VarName`), CSV URL/file import (`csv(...)`), and cell range expansion (`A1:B3`).
|
|
187
|
+
|
|
188
|
+
---
|
|
189
|
+
|
|
190
|
+
## ๐ ๏ธ API Reference
|
|
191
|
+
|
|
192
|
+
### `tentags.render(formula: str, context: dict = None) -> str`
|
|
193
|
+
Parses the input DSL formula string and returns a complete `<table>...</table>` HTML string.
|
|
194
|
+
- **`formula`**: String in format `'rows, cols, border_width, "border_color", "border_style", margin, row_height, data(...)'`.
|
|
195
|
+
- **`context`**: Optional dictionary of variable names and their replacement values (`{'VarName': 'Value'}`).
|
|
196
|
+
|
|
197
|
+
### `tentags.parse(formula: str, context: dict = None) -> TableModel`
|
|
198
|
+
Parses the formula into a structured `TableModel` instance containing 2D cell grids (`CellDesc`), `BorderFlags`, and styles without generating HTML.
|
|
199
|
+
|
|
200
|
+
### `tentags.render_html(model: TableModel) -> str`
|
|
201
|
+
Renders a previously parsed `TableModel` instance into an HTML string.
|
|
202
|
+
|
|
203
|
+
### `tentags.render_xlsx(model: TableModel, output_filename: str) -> None`
|
|
204
|
+
Exports a `TableModel` directly to an Excel `.xlsx` file using `openpyxl`. Applies `openpyxl.styles.Font` (bold, italic, color), `openpyxl.styles.PatternFill` (background color), and `openpyxl.styles.Border` according to the table formula.
|
|
205
|
+
|
|
206
|
+
---
|
|
207
|
+
|
|
208
|
+
## ๐งช Running Tests
|
|
209
|
+
|
|
210
|
+
To run the standalone test suite and generate sample visual outputs (`test_output.html`, `test_output.xlsx`, `test_style_output.xlsx`):
|
|
211
|
+
|
|
212
|
+
```bash
|
|
213
|
+
python test_library.py
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
---
|
|
217
|
+
|
|
218
|
+
## ๐ License
|
|
219
|
+
|
|
220
|
+
Licensed under the [MIT License](LICENSE). Copyright (c) 2026 Zhandos Mambetali.
|
tentags-0.1.0/README.md
ADDED
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
# TenTags ๐ท๏ธ
|
|
2
|
+
|
|
3
|
+
<p align="center">
|
|
4
|
+
<img src="tentags_logo.png" alt="TenTags Logo" width="450">
|
|
5
|
+
</p>
|
|
6
|
+
|
|
7
|
+
[](https://pypi.org/project/tentags/)
|
|
8
|
+
[](https://pypi.org/project/tentags/)
|
|
9
|
+
[](https://opensource.org/licenses/MIT)
|
|
10
|
+
|
|
11
|
+
**TenTags** is a standalone, zero-dependency **Advanced Table Markdown** library for Python. It turns compact, expressive string formulas into pixel-perfect **HTML** and native **Excel (`.xlsx`)** spreadsheets using **10 core structural and styling tags**.
|
|
12
|
+
|
|
13
|
+
### ๐ก Why TenTags? (Advanced Markdown for Tables)
|
|
14
|
+
|
|
15
|
+
Standard Markdown (`| A | B |`) is notoriously rigid when it comes to tables: it cannot merge complex cell grids across rows (`rowspan`) or columns (`colspan`), it lacks background fills and typography controls, and it cannot compile directly to native Excel spreadsheets.
|
|
16
|
+
|
|
17
|
+
**TenTags** bridges this gap. Think of it as **next-generation Table Markdown** that gives you:
|
|
18
|
+
- ๐ **Advanced Grid Merges**: Effortlessly merge cells rightward across columns (`<cm>`) and downward across rows (`<rm>`).
|
|
19
|
+
- ๐จ **Rich Typography & Styling**: Inline control over font size (`<fs>`), bold (`<b>`), italic (`<i>`), horizontal alignment (`<left>`, `<center>`, `<right>`), text color (`<color=>`), and cell fills (`<bg=>`).
|
|
20
|
+
- ๐ **Native Excel Export**: Directly compiles your markup into styled, production-ready `.xlsx` files with exact `openpyxl` grid merges (`ws.merge_cells`), font weights, text alignments, and pattern fills.
|
|
21
|
+
- โก **Zero Core Dependencies**: Pure Python runtime (`xml.etree.ElementTree`) that tokenizes and parses at lightning speed.
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
## ๐ฆ Installation
|
|
26
|
+
|
|
27
|
+
Install from PyPI via pip:
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
pip install tentags
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
If you plan to export to Excel (`.xlsx`), install the optional `excel` dependency:
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
pip install tentags[excel]
|
|
37
|
+
# or directly: pip install openpyxl
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
---
|
|
41
|
+
|
|
42
|
+
## ๐ Quickstart
|
|
43
|
+
|
|
44
|
+
```python
|
|
45
|
+
import tentags
|
|
46
|
+
|
|
47
|
+
# Define a table expression with custom border color, background fill, and tags
|
|
48
|
+
formula = '2,2,1,"#0f172a","solid",0,40, data(Header 1, <b>Header 2</b>; <color=red><i>Red Italic</i></color>, <bg=#e2e8f0>Gray Cell</bg>)'
|
|
49
|
+
|
|
50
|
+
# 1. Direct rendering to HTML string
|
|
51
|
+
html = tentags.render(formula)
|
|
52
|
+
print(html)
|
|
53
|
+
|
|
54
|
+
# 2. Parsing to intermediate TableModel
|
|
55
|
+
model = tentags.parse(formula)
|
|
56
|
+
print(f"Rows: {model.rows}, Cols: {model.cols}, Border: {model.border_color}")
|
|
57
|
+
|
|
58
|
+
# 3. Render TableModel to Excel (.xlsx) file
|
|
59
|
+
tentags.render_xlsx(model, "styled_report.xlsx")
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
---
|
|
63
|
+
|
|
64
|
+
## ๐จ Advanced Example: Beautiful Styled Table & Merges
|
|
65
|
+
|
|
66
|
+
Here is how a single, clean **TenTags** expression generates an enterprise-grade financial dashboard table featuring merged headers (`<cm>`), custom font sizing (`<fs>`), cell background colors (`<bg=>`), text alignment (`<left>`, `<right>`), and custom typography (`<b>`, `<i>`, `<color=>`) across both **HTML** and **Excel (`.xlsx`)**:
|
|
67
|
+
|
|
68
|
+
```python
|
|
69
|
+
import tentags
|
|
70
|
+
|
|
71
|
+
# Define an advanced 4x4 styled financial performance grid
|
|
72
|
+
formula = '''4,4,1,"#cbd5e1","solid",0,45, data(
|
|
73
|
+
<fs=18><bg=#1e293b><color=white><b><cm>Q3 Financial Performance Dashboard</cm></b></color></bg></fs>, None, None, None;
|
|
74
|
+
<bg=#f1f5f9><b><left>Department</left></b></bg>, <bg=#f1f5f9><b><center>Revenue</center></b></bg>, <bg=#f1f5f9><b><center>Expenses</center></b></bg>, <bg=#f1f5f9><b><center>Net Profit</center></b></bg>;
|
|
75
|
+
<left>Engineering</left>, <right>"$240,000"</right>, <right>"$180,000"</right>, <bg=#dcfce7><color=#166534><b><right>"+$60,000"</right></b></color></bg>;
|
|
76
|
+
<left>Sales & Marketing</left>, <right>"$310,000"</right>, <right>"$210,000"</right>, <bg=#dcfce7><color=#166534><b><right>"+$100,000"</right></b></color></bg>
|
|
77
|
+
)'''
|
|
78
|
+
|
|
79
|
+
# 1. Export directly to native Excel spreadsheet with exact fonts, fills, & merge_cells
|
|
80
|
+
model = tentags.parse(formula)
|
|
81
|
+
tentags.render_xlsx(model, "Q3_Financial_Dashboard.xlsx")
|
|
82
|
+
|
|
83
|
+
# 2. Render to responsive HTML string with inline CSS
|
|
84
|
+
html_table = tentags.render_html(model)
|
|
85
|
+
print(html_table)
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
### ๐ Visual Structure & Styling Result:
|
|
89
|
+
|
|
90
|
+
| Department / Header | Revenue | Expenses | Net Profit |
|
|
91
|
+
| :--- | :---: | :---: | :---: |
|
|
92
|
+
| **Q3 Financial Performance Dashboard** *(Merged across 4 columns (`colspan=4`), 18px Bold, White text, Dark Slate `#1e293b` background)* | โ | โ | โ |
|
|
93
|
+
| **Department** *(Left aligned, Light Gray `#f1f5f9` BG)* | **Revenue** *(Centered, Bold)* | **Expenses** *(Centered, Bold)* | **Net Profit** *(Centered, Bold)* |
|
|
94
|
+
| Engineering *(Left aligned)* | $240,000 *(Right aligned)* | $180,000 *(Right aligned)* | **+$60,000** *(Right aligned, Bold, Green `#dcfce7` BG, Dark Green text)* |
|
|
95
|
+
| Sales & Marketing *(Left aligned)* | $310,000 *(Right aligned)* | $210,000 *(Right aligned)* | **+$100,000** *(Right aligned, Bold, Green `#dcfce7` BG, Dark Green text)* |
|
|
96
|
+
|
|
97
|
+
---
|
|
98
|
+
|
|
99
|
+
## ๐ Excel Matrix Example: Row Merges (`<rm>`), Column Merges (`<cm>`) & Colors
|
|
100
|
+
|
|
101
|
+
To see how **TenTags** shines as a native Excel spreadsheet generator, here is a 5x5 **Enterprise Allocation Matrix** utilizing combined row merges (`<rm>`), multi-column merges (`<cm>`), and classic Microsoft Excel color palettes (`#1F4E78`, `#DDEBF7`, `#E2EFDA`, `#FFF2CC`):
|
|
102
|
+
|
|
103
|
+
```python
|
|
104
|
+
import tentags
|
|
105
|
+
|
|
106
|
+
# Define an Excel matrix with vertical row merges (<rm>) and horizontal column merges (<cm>)
|
|
107
|
+
excel_formula = '''5,5,1,"#B0C4DE","solid",0,35, data(
|
|
108
|
+
<fs=16><bg=#1F4E78><color=white><b><cm>2026 Enterprise Budget & Allocation Matrix, None, None, None, None</cm></b></color></bg></fs>;
|
|
109
|
+
<bg=#DDEBF7><b><rm><center>Category</center></rm></b></bg>, <bg=#DDEBF7><b><cm><center>Q1 & Q2 Allocation</center>, None</cm></b></bg>, <bg=#DDEBF7><b><cm><center>Q3 & Q4 Allocation</center>, None</cm></b></bg>;
|
|
110
|
+
<bg=#DDEBF7><b><rm>None</rm></b></bg>, <bg=#F2F2F2><b><center>Hardware</center></b></bg>, <bg=#F2F2F2><b><center>Software</center></b></bg>, <bg=#F2F2F2><b><center>Hardware</center></b></bg>, <bg=#F2F2F2><b><center>Software</center></b></bg>;
|
|
111
|
+
<bg=#FFF2CC><b><left>R&D Division</left></b></bg>, <right>"$150,000"</right>, <right>"$85,000"</right>, <right>"$120,000"</right>, <right>"$95,000"</right>;
|
|
112
|
+
<bg=#E2EFDA><color=#375623><b><left>Total Budget</left></b></color></bg>, <bg=#E2EFDA><color=#375623><b><cm><right>"$235,000"</right>, None</cm></b></color></bg>, <bg=#E2EFDA><color=#375623><b><cm><right>"+$215,000"</right>, None</cm></b></color></bg>
|
|
113
|
+
)'''
|
|
114
|
+
|
|
115
|
+
# Export to a native Excel spreadsheet (.xlsx) with true merged regions & fills
|
|
116
|
+
model = tentags.parse(excel_formula)
|
|
117
|
+
tentags.render_xlsx(model, "Enterprise_Budget_Matrix.xlsx")
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
### ๐๏ธ Visual Spreadsheet Grid Structure (`A1:E5`):
|
|
121
|
+
|
|
122
|
+
<p align="center">
|
|
123
|
+
<img src="example.png" alt="TenTags Excel Matrix Output" width="750">
|
|
124
|
+
</p>
|
|
125
|
+
|
|
126
|
+
Notice how `None` is passed in slots that get swallowed by an adjacent cell's `<cm>` horizontal merge or `<rm>` vertical merge. When opened in Microsoft Excel or rendered in HTML, the boundaries cleanly dissolve into unified multi-cell headers and summary blocks!
|
|
127
|
+
|
|
128
|
+
---
|
|
129
|
+
|
|
130
|
+
## ๐ท๏ธ The 10 Tags in `data(...)`
|
|
131
|
+
|
|
132
|
+
TenTags derives its name from the **10 core structural and styling tags** supported inside the `data(...)` argument block:
|
|
133
|
+
|
|
134
|
+
| # | Tag / Syntax | Type | Description | Example |
|
|
135
|
+
|---|---|---|---|---|
|
|
136
|
+
| 1 | `<fs=...>` | Typography | Sets custom font size (`font-size` in HTML, `size` in Excel `openpyxl`). | `data(<fs=16>Heading</fs>, Text)` |
|
|
137
|
+
| 2 | `<b>...</b>` | Typography | Renders cell text in **Bold** font weight (`font-weight: bold`). | `data(<b>Total</b>, 100)` |
|
|
138
|
+
| 3 | `<i>...</i>` | Typography | Renders cell text in *Italic* font style (`font-style: italic`). | `data(<i>Pending</i>, Done)` |
|
|
139
|
+
| 4 | `<left>` | Alignment | Aligns cell content to the **left** (`text-align: left`). | `data(<left>Left aligned text)` |
|
|
140
|
+
| 5 | `<center>` | Alignment | Aligns cell content to the **center** (`text-align: center`). | `data(<center>Centered text)` |
|
|
141
|
+
| 6 | `<right>` | Alignment | Aligns cell content to the **right** (`text-align: right`). | `data(<right>Right aligned $5,000)` |
|
|
142
|
+
| 7 | `<color=...>` | Text Color | Sets custom HEX or CSS text color (`color: ...` / font color). | `data(<color=#ef4444>Error</color>, OK)` |
|
|
143
|
+
| 8 | `<bg=...>` | Background Fill | Sets cell background fill color (`background-color: ...` / PatternFill). | `data(<bg=#f8fafc>Summary</bg>, $500)` |
|
|
144
|
+
| 9 | `<cm>...</cm>` | Column Merge | Merges the cell rightward with adjacent columns (`colspan`). | `data(<cm>Merged Title</cm>, None; A, B)` |
|
|
145
|
+
| 10 | `<rm>...</rm>` | Row Merge | Merges the cell downward with rows below it (`rowspan`). | `data(<rm>Date</rm>, Job; <cm>, Engineer)` |
|
|
146
|
+
|
|
147
|
+
> **Note on Tag Transfer**: When merging (`<cm>`, `<rm>`) or expanding ranges across styled cells (`<fs>`, `<b>`, `<i>`, `<color>`, `<bg>`, `<left>`, `<center>`, `<right>`), TenTags automatically transfers and preserves all formatting across cell boundaries in both HTML and Excel outputs.
|
|
148
|
+
>
|
|
149
|
+
> **Dynamic Data Expressions**: In addition to the 10 markup tags above, TenTags `data(...)` supports dynamic line numbering (`#`), variable context substitution (`VarName`), CSV URL/file import (`csv(...)`), and cell range expansion (`A1:B3`).
|
|
150
|
+
|
|
151
|
+
---
|
|
152
|
+
|
|
153
|
+
## ๐ ๏ธ API Reference
|
|
154
|
+
|
|
155
|
+
### `tentags.render(formula: str, context: dict = None) -> str`
|
|
156
|
+
Parses the input DSL formula string and returns a complete `<table>...</table>` HTML string.
|
|
157
|
+
- **`formula`**: String in format `'rows, cols, border_width, "border_color", "border_style", margin, row_height, data(...)'`.
|
|
158
|
+
- **`context`**: Optional dictionary of variable names and their replacement values (`{'VarName': 'Value'}`).
|
|
159
|
+
|
|
160
|
+
### `tentags.parse(formula: str, context: dict = None) -> TableModel`
|
|
161
|
+
Parses the formula into a structured `TableModel` instance containing 2D cell grids (`CellDesc`), `BorderFlags`, and styles without generating HTML.
|
|
162
|
+
|
|
163
|
+
### `tentags.render_html(model: TableModel) -> str`
|
|
164
|
+
Renders a previously parsed `TableModel` instance into an HTML string.
|
|
165
|
+
|
|
166
|
+
### `tentags.render_xlsx(model: TableModel, output_filename: str) -> None`
|
|
167
|
+
Exports a `TableModel` directly to an Excel `.xlsx` file using `openpyxl`. Applies `openpyxl.styles.Font` (bold, italic, color), `openpyxl.styles.PatternFill` (background color), and `openpyxl.styles.Border` according to the table formula.
|
|
168
|
+
|
|
169
|
+
---
|
|
170
|
+
|
|
171
|
+
## ๐งช Running Tests
|
|
172
|
+
|
|
173
|
+
To run the standalone test suite and generate sample visual outputs (`test_output.html`, `test_output.xlsx`, `test_style_output.xlsx`):
|
|
174
|
+
|
|
175
|
+
```bash
|
|
176
|
+
python test_library.py
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
---
|
|
180
|
+
|
|
181
|
+
## ๐ License
|
|
182
|
+
|
|
183
|
+
Licensed under the [MIT License](LICENSE). Copyright (c) 2026 Zhandos Mambetali.
|
|
Binary file
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61.0", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "tentags"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Advanced Table Markdown for HTML & Excel spreadsheets with rich styling and multi-cell merge grids using 10 core tags."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
authors = [
|
|
11
|
+
{ name = "Zhandos Mambetali", email = "zhandos.mambetali@gmail.com" }
|
|
12
|
+
]
|
|
13
|
+
license = "MIT"
|
|
14
|
+
license-files = ["LICENSE"]
|
|
15
|
+
classifiers = [
|
|
16
|
+
"Development Status :: 4 - Beta",
|
|
17
|
+
"Intended Audience :: Developers",
|
|
18
|
+
"Operating System :: OS Independent",
|
|
19
|
+
"Programming Language :: Python :: 3",
|
|
20
|
+
"Programming Language :: Python :: 3.8",
|
|
21
|
+
"Programming Language :: Python :: 3.9",
|
|
22
|
+
"Programming Language :: Python :: 3.10",
|
|
23
|
+
"Programming Language :: Python :: 3.11",
|
|
24
|
+
"Programming Language :: Python :: 3.12",
|
|
25
|
+
"Topic :: Software Development :: Libraries :: Python Modules",
|
|
26
|
+
"Topic :: Text Processing :: Markup :: HTML",
|
|
27
|
+
"Topic :: Office/Business :: Financial :: Spreadsheet",
|
|
28
|
+
]
|
|
29
|
+
keywords = ["html", "excel", "xlsx", "table", "generator", "spreadsheet", "pycells", "tags", "parser"]
|
|
30
|
+
dependencies = []
|
|
31
|
+
requires-python = ">=3.8"
|
|
32
|
+
|
|
33
|
+
[project.optional-dependencies]
|
|
34
|
+
excel = [
|
|
35
|
+
"openpyxl>=3.1.0",
|
|
36
|
+
"et_xmlfile>=2.0.0"
|
|
37
|
+
]
|
|
38
|
+
dev = [
|
|
39
|
+
"openpyxl>=3.1.0",
|
|
40
|
+
"et_xmlfile>=2.0.0",
|
|
41
|
+
"pytest>=7.0.0",
|
|
42
|
+
"build>=1.0.0",
|
|
43
|
+
"twine>=4.0.0"
|
|
44
|
+
]
|
|
45
|
+
|
|
46
|
+
[project.urls]
|
|
47
|
+
Homepage = "https://pycells.com"
|
|
48
|
+
Documentation = "https://pycells.com/tentags"
|
|
49
|
+
Repository = "https://github.com/Jandos77/tentags"
|
|
50
|
+
Issues = "https://github.com/Jandos77/tentags/issues"
|
|
51
|
+
|
|
52
|
+
[tool.setuptools]
|
|
53
|
+
py-modules = ["tentags"]
|
tentags-0.1.0/setup.cfg
ADDED
tentags-0.1.0/setup.py
ADDED