htmlforge 0.0.1__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.
- htmlforge-0.0.1/.gitignore +8 -0
- htmlforge-0.0.1/LICENSE +1 -0
- htmlforge-0.0.1/PKG-INFO +205 -0
- htmlforge-0.0.1/README.md +187 -0
- htmlforge-0.0.1/demo.py +58 -0
- htmlforge-0.0.1/demo_simple.py +87 -0
- htmlforge-0.0.1/pyproject.toml +36 -0
- htmlforge-0.0.1/src/htmlforge/__init__.py +27 -0
- htmlforge-0.0.1/src/htmlforge/__main__.py +5 -0
- htmlforge-0.0.1/src/htmlforge/cli.py +194 -0
- htmlforge-0.0.1/src/htmlforge/core.py +687 -0
- htmlforge-0.0.1/src/htmlforge/simple.py +331 -0
- htmlforge-0.0.1/style_demo.py +94 -0
- htmlforge-0.0.1/tests/__init__.py +0 -0
- htmlforge-0.0.1/tests/buttons.py +17 -0
- htmlforge-0.0.1/tests/test_cli.py +106 -0
- htmlforge-0.0.1/tests/test_core.py +335 -0
- htmlforge-0.0.1/tests/test_simple.py +311 -0
htmlforge-0.0.1/LICENSE
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Mozilla Public License Version 2.0
|
htmlforge-0.0.1/PKG-INFO
ADDED
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: htmlforge
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: Build web pages with Python, export to HTML with a single command
|
|
5
|
+
Project-URL: Homepage, https://github.com/htmlforge/htmlforge
|
|
6
|
+
Author: htmlforge contributors
|
|
7
|
+
License-Expression: MPL-2.0
|
|
8
|
+
License-File: LICENSE
|
|
9
|
+
Keywords: builder,html,page,static-site,web
|
|
10
|
+
Classifier: Development Status :: 3 - Alpha
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: License :: OSI Approved :: Mozilla Public License 2.0 (MPL 2.0)
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Topic :: Internet :: WWW/HTTP
|
|
15
|
+
Classifier: Topic :: Text Processing :: Markup :: HTML
|
|
16
|
+
Requires-Python: >=3.9
|
|
17
|
+
Description-Content-Type: text/markdown
|
|
18
|
+
|
|
19
|
+
# htmlforge
|
|
20
|
+
|
|
21
|
+
Build web pages with Python, export to HTML with a single command — like manim generates videos.
|
|
22
|
+
|
|
23
|
+
```
|
|
24
|
+
manim scene.py MyScene → mp4
|
|
25
|
+
htmlforge page.py MyPage → html
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Installation
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
pip install htmlforge
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
Development install:
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
pip install -e ".[dev]"
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## Quick Start
|
|
41
|
+
|
|
42
|
+
### 1. Write a Python page script `mysite.py`
|
|
43
|
+
|
|
44
|
+
```python
|
|
45
|
+
from htmlforge import Doc
|
|
46
|
+
|
|
47
|
+
page = Doc("My Site")
|
|
48
|
+
|
|
49
|
+
# Generate styles with Python code (no CSS needed!)
|
|
50
|
+
page.style("body", background="#f5f5f5", font_family="sans-serif")
|
|
51
|
+
page.style(".py-card", border_radius="12px", box_shadow="0 2px 8px rgba(0,0,0,.1)")
|
|
52
|
+
|
|
53
|
+
# Build the page
|
|
54
|
+
page.heading("Welcome to My Site")
|
|
55
|
+
page.text("Built with **htmlforge**, supports *Markdown* syntax")
|
|
56
|
+
|
|
57
|
+
page.card("Features",
|
|
58
|
+
"40+ HTML components",
|
|
59
|
+
"Generate styles with Python code",
|
|
60
|
+
"Export HTML with one command",
|
|
61
|
+
)
|
|
62
|
+
|
|
63
|
+
page.table(
|
|
64
|
+
["Feature", "Description"],
|
|
65
|
+
[
|
|
66
|
+
["Components", "40+ HTML components"],
|
|
67
|
+
["Built-in theme", "Works out of the box"],
|
|
68
|
+
["CLI tools", "render / serve / watch"],
|
|
69
|
+
],
|
|
70
|
+
)
|
|
71
|
+
|
|
72
|
+
page.button("Click me", on_click="alert('Hello!')", color="#4CAF50")
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
### 2. Run the command to export HTML
|
|
76
|
+
|
|
77
|
+
```bash
|
|
78
|
+
# Basic render
|
|
79
|
+
htmlforge render mysite.py
|
|
80
|
+
|
|
81
|
+
# Specify output directory
|
|
82
|
+
htmlforge render mysite.py -o build
|
|
83
|
+
|
|
84
|
+
# Render and start a local server
|
|
85
|
+
htmlforge render mysite.py -s
|
|
86
|
+
|
|
87
|
+
# Watch for file changes and auto-rebuild
|
|
88
|
+
htmlforge render mysite.py -w
|
|
89
|
+
|
|
90
|
+
# Render a specific page (when file has multiple pages)
|
|
91
|
+
htmlforge render mysite.py MyPage
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
## CLI Commands
|
|
95
|
+
|
|
96
|
+
| Command | Description |
|
|
97
|
+
|---|---|
|
|
98
|
+
| `htmlforge render <file.py>` | Render all pages to `dist/` |
|
|
99
|
+
| `htmlforge render <file.py> -o <dir>` | Specify output directory |
|
|
100
|
+
| `htmlforge render <file.py> <page>` | Render only the specified page |
|
|
101
|
+
| `htmlforge render <file.py> -s` | Start HTTP server after render |
|
|
102
|
+
| `htmlforge render <file.py> -s -p 3000` | Specify server port |
|
|
103
|
+
| `htmlforge render <file.py> -w` | Watch for changes and auto-rebuild |
|
|
104
|
+
|
|
105
|
+
## Doc API — Ultra Simple
|
|
106
|
+
|
|
107
|
+
`Doc` is a high-level API designed for Python programmers who don't know HTML. It comes with a built-in theme — no CSS required to build great-looking pages.
|
|
108
|
+
|
|
109
|
+
```python
|
|
110
|
+
from htmlforge import Doc
|
|
111
|
+
|
|
112
|
+
page = Doc("Title")
|
|
113
|
+
|
|
114
|
+
# Generate styles with Python kwargs (no CSS strings!)
|
|
115
|
+
page.style("body", background="linear-gradient(135deg, #667eea, #764ba2)", color="white")
|
|
116
|
+
page.style("h1", font_size="3rem", text_align="center")
|
|
117
|
+
page.style(".py-card", background="rgba(255,255,255,.15)", backdrop_filter="blur(10px)")
|
|
118
|
+
|
|
119
|
+
# Content (supports **Markdown** syntax)
|
|
120
|
+
page.heading("Hello World")
|
|
121
|
+
page.text("Supports **bold**, *italic*, `code`, [links](url)")
|
|
122
|
+
|
|
123
|
+
page.card("Card Title", "Card content, **supports Markdown**")
|
|
124
|
+
page.list(["Item A", "Item B", "Item C"])
|
|
125
|
+
page.table(["Col 1", "Col 2"], [["a", "b"], ["c", "d"]])
|
|
126
|
+
page.button("Button", on_click="alert('hi')", color="#e74c3c")
|
|
127
|
+
page.input("Type here...", name="name")
|
|
128
|
+
page.select(["Option A", "Option B", "Option C"])
|
|
129
|
+
page.code("print('hello')", lang="python")
|
|
130
|
+
page.details("Collapsible", "Hidden content...")
|
|
131
|
+
page.nav(("Home", "/"), ("About", "/about"))
|
|
132
|
+
page.divider()
|
|
133
|
+
|
|
134
|
+
# Layout
|
|
135
|
+
page.row(Doc.make_card("A"), Doc.make_card("B"), Doc.make_card("C"))
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
## Page API — Fine-grained Control
|
|
139
|
+
|
|
140
|
+
Use `Page` + the component system when you need more control:
|
|
141
|
+
|
|
142
|
+
```python
|
|
143
|
+
from htmlforge import Page, H1, P, Div, Table, Button
|
|
144
|
+
|
|
145
|
+
page = Page("Title", lang="en")
|
|
146
|
+
page.add_css("body { font-family: sans-serif; }")
|
|
147
|
+
page.add(
|
|
148
|
+
H1("Welcome"),
|
|
149
|
+
P("Hello World"),
|
|
150
|
+
Div(class_="card").add(
|
|
151
|
+
H1("Features", level=2),
|
|
152
|
+
P("Content..."),
|
|
153
|
+
),
|
|
154
|
+
)
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
### Element — Chainable API
|
|
158
|
+
|
|
159
|
+
```python
|
|
160
|
+
div = Div(id="main", class_="wrapper")
|
|
161
|
+
div.add(H1("Title"), P("Content")) # Add child elements
|
|
162
|
+
div.css(color="red", font_size="16px") # Set inline styles (camelCase → kebab-case)
|
|
163
|
+
div.attr("data-id", "123") # Set attributes
|
|
164
|
+
html = div.render() # → HTML string
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
### Components
|
|
168
|
+
|
|
169
|
+
| Category | Components |
|
|
170
|
+
|---|---|
|
|
171
|
+
| **Structure** | `Div`, `Section`, `Header`, `Footer`, `Nav`, `Main`, `Article`, `Aside`, `Span`, `Container` |
|
|
172
|
+
| **Text** | `H1`-`H6`, `P`, `Strong`, `Em`, `Blockquote`, `Code`, `Pre`, `Small`, `Mark` |
|
|
173
|
+
| **Links/Media** | `Link`, `Img`, `Video`, `Audio`, `Iframe`, `Canvas` |
|
|
174
|
+
| **Lists** | `Ul`, `Ol`, `Li`, `List` |
|
|
175
|
+
| **Tables** | `Table`, `Thead`, `Tbody`, `Tr`, `Th`, `Td`, `Caption` |
|
|
176
|
+
| **Forms** | `Form`, `Input`, `Textarea`, `Select`, `Option`, `Checkbox`, `Radio`, `Label`, `Button` |
|
|
177
|
+
| **Other** | `Hr`, `Br`, `Text`, `Progress`, `Details`, `Summary` |
|
|
178
|
+
|
|
179
|
+
## Example: Multi-page Site
|
|
180
|
+
|
|
181
|
+
```python
|
|
182
|
+
# site.py
|
|
183
|
+
from htmlforge import Doc
|
|
184
|
+
|
|
185
|
+
home = Doc("Home")
|
|
186
|
+
home.heading("Home")
|
|
187
|
+
home.text("Welcome to the home page")
|
|
188
|
+
|
|
189
|
+
about = Doc("About")
|
|
190
|
+
about.heading("About Us")
|
|
191
|
+
about.text("This is the about page")
|
|
192
|
+
|
|
193
|
+
blog = Doc("Blog")
|
|
194
|
+
blog.heading("Blog")
|
|
195
|
+
blog.text("Latest posts...")
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
```bash
|
|
199
|
+
htmlforge render site.py
|
|
200
|
+
# → dist/home.html, dist/about.html, dist/blog.html
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
## License
|
|
204
|
+
|
|
205
|
+
[MPL-2.0](LICENSE)
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
# htmlforge
|
|
2
|
+
|
|
3
|
+
Build web pages with Python, export to HTML with a single command — like manim generates videos.
|
|
4
|
+
|
|
5
|
+
```
|
|
6
|
+
manim scene.py MyScene → mp4
|
|
7
|
+
htmlforge page.py MyPage → html
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
## Installation
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
pip install htmlforge
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
Development install:
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
pip install -e ".[dev]"
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Quick Start
|
|
23
|
+
|
|
24
|
+
### 1. Write a Python page script `mysite.py`
|
|
25
|
+
|
|
26
|
+
```python
|
|
27
|
+
from htmlforge import Doc
|
|
28
|
+
|
|
29
|
+
page = Doc("My Site")
|
|
30
|
+
|
|
31
|
+
# Generate styles with Python code (no CSS needed!)
|
|
32
|
+
page.style("body", background="#f5f5f5", font_family="sans-serif")
|
|
33
|
+
page.style(".py-card", border_radius="12px", box_shadow="0 2px 8px rgba(0,0,0,.1)")
|
|
34
|
+
|
|
35
|
+
# Build the page
|
|
36
|
+
page.heading("Welcome to My Site")
|
|
37
|
+
page.text("Built with **htmlforge**, supports *Markdown* syntax")
|
|
38
|
+
|
|
39
|
+
page.card("Features",
|
|
40
|
+
"40+ HTML components",
|
|
41
|
+
"Generate styles with Python code",
|
|
42
|
+
"Export HTML with one command",
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
page.table(
|
|
46
|
+
["Feature", "Description"],
|
|
47
|
+
[
|
|
48
|
+
["Components", "40+ HTML components"],
|
|
49
|
+
["Built-in theme", "Works out of the box"],
|
|
50
|
+
["CLI tools", "render / serve / watch"],
|
|
51
|
+
],
|
|
52
|
+
)
|
|
53
|
+
|
|
54
|
+
page.button("Click me", on_click="alert('Hello!')", color="#4CAF50")
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
### 2. Run the command to export HTML
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
# Basic render
|
|
61
|
+
htmlforge render mysite.py
|
|
62
|
+
|
|
63
|
+
# Specify output directory
|
|
64
|
+
htmlforge render mysite.py -o build
|
|
65
|
+
|
|
66
|
+
# Render and start a local server
|
|
67
|
+
htmlforge render mysite.py -s
|
|
68
|
+
|
|
69
|
+
# Watch for file changes and auto-rebuild
|
|
70
|
+
htmlforge render mysite.py -w
|
|
71
|
+
|
|
72
|
+
# Render a specific page (when file has multiple pages)
|
|
73
|
+
htmlforge render mysite.py MyPage
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
## CLI Commands
|
|
77
|
+
|
|
78
|
+
| Command | Description |
|
|
79
|
+
|---|---|
|
|
80
|
+
| `htmlforge render <file.py>` | Render all pages to `dist/` |
|
|
81
|
+
| `htmlforge render <file.py> -o <dir>` | Specify output directory |
|
|
82
|
+
| `htmlforge render <file.py> <page>` | Render only the specified page |
|
|
83
|
+
| `htmlforge render <file.py> -s` | Start HTTP server after render |
|
|
84
|
+
| `htmlforge render <file.py> -s -p 3000` | Specify server port |
|
|
85
|
+
| `htmlforge render <file.py> -w` | Watch for changes and auto-rebuild |
|
|
86
|
+
|
|
87
|
+
## Doc API — Ultra Simple
|
|
88
|
+
|
|
89
|
+
`Doc` is a high-level API designed for Python programmers who don't know HTML. It comes with a built-in theme — no CSS required to build great-looking pages.
|
|
90
|
+
|
|
91
|
+
```python
|
|
92
|
+
from htmlforge import Doc
|
|
93
|
+
|
|
94
|
+
page = Doc("Title")
|
|
95
|
+
|
|
96
|
+
# Generate styles with Python kwargs (no CSS strings!)
|
|
97
|
+
page.style("body", background="linear-gradient(135deg, #667eea, #764ba2)", color="white")
|
|
98
|
+
page.style("h1", font_size="3rem", text_align="center")
|
|
99
|
+
page.style(".py-card", background="rgba(255,255,255,.15)", backdrop_filter="blur(10px)")
|
|
100
|
+
|
|
101
|
+
# Content (supports **Markdown** syntax)
|
|
102
|
+
page.heading("Hello World")
|
|
103
|
+
page.text("Supports **bold**, *italic*, `code`, [links](url)")
|
|
104
|
+
|
|
105
|
+
page.card("Card Title", "Card content, **supports Markdown**")
|
|
106
|
+
page.list(["Item A", "Item B", "Item C"])
|
|
107
|
+
page.table(["Col 1", "Col 2"], [["a", "b"], ["c", "d"]])
|
|
108
|
+
page.button("Button", on_click="alert('hi')", color="#e74c3c")
|
|
109
|
+
page.input("Type here...", name="name")
|
|
110
|
+
page.select(["Option A", "Option B", "Option C"])
|
|
111
|
+
page.code("print('hello')", lang="python")
|
|
112
|
+
page.details("Collapsible", "Hidden content...")
|
|
113
|
+
page.nav(("Home", "/"), ("About", "/about"))
|
|
114
|
+
page.divider()
|
|
115
|
+
|
|
116
|
+
# Layout
|
|
117
|
+
page.row(Doc.make_card("A"), Doc.make_card("B"), Doc.make_card("C"))
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
## Page API — Fine-grained Control
|
|
121
|
+
|
|
122
|
+
Use `Page` + the component system when you need more control:
|
|
123
|
+
|
|
124
|
+
```python
|
|
125
|
+
from htmlforge import Page, H1, P, Div, Table, Button
|
|
126
|
+
|
|
127
|
+
page = Page("Title", lang="en")
|
|
128
|
+
page.add_css("body { font-family: sans-serif; }")
|
|
129
|
+
page.add(
|
|
130
|
+
H1("Welcome"),
|
|
131
|
+
P("Hello World"),
|
|
132
|
+
Div(class_="card").add(
|
|
133
|
+
H1("Features", level=2),
|
|
134
|
+
P("Content..."),
|
|
135
|
+
),
|
|
136
|
+
)
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
### Element — Chainable API
|
|
140
|
+
|
|
141
|
+
```python
|
|
142
|
+
div = Div(id="main", class_="wrapper")
|
|
143
|
+
div.add(H1("Title"), P("Content")) # Add child elements
|
|
144
|
+
div.css(color="red", font_size="16px") # Set inline styles (camelCase → kebab-case)
|
|
145
|
+
div.attr("data-id", "123") # Set attributes
|
|
146
|
+
html = div.render() # → HTML string
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
### Components
|
|
150
|
+
|
|
151
|
+
| Category | Components |
|
|
152
|
+
|---|---|
|
|
153
|
+
| **Structure** | `Div`, `Section`, `Header`, `Footer`, `Nav`, `Main`, `Article`, `Aside`, `Span`, `Container` |
|
|
154
|
+
| **Text** | `H1`-`H6`, `P`, `Strong`, `Em`, `Blockquote`, `Code`, `Pre`, `Small`, `Mark` |
|
|
155
|
+
| **Links/Media** | `Link`, `Img`, `Video`, `Audio`, `Iframe`, `Canvas` |
|
|
156
|
+
| **Lists** | `Ul`, `Ol`, `Li`, `List` |
|
|
157
|
+
| **Tables** | `Table`, `Thead`, `Tbody`, `Tr`, `Th`, `Td`, `Caption` |
|
|
158
|
+
| **Forms** | `Form`, `Input`, `Textarea`, `Select`, `Option`, `Checkbox`, `Radio`, `Label`, `Button` |
|
|
159
|
+
| **Other** | `Hr`, `Br`, `Text`, `Progress`, `Details`, `Summary` |
|
|
160
|
+
|
|
161
|
+
## Example: Multi-page Site
|
|
162
|
+
|
|
163
|
+
```python
|
|
164
|
+
# site.py
|
|
165
|
+
from htmlforge import Doc
|
|
166
|
+
|
|
167
|
+
home = Doc("Home")
|
|
168
|
+
home.heading("Home")
|
|
169
|
+
home.text("Welcome to the home page")
|
|
170
|
+
|
|
171
|
+
about = Doc("About")
|
|
172
|
+
about.heading("About Us")
|
|
173
|
+
about.text("This is the about page")
|
|
174
|
+
|
|
175
|
+
blog = Doc("Blog")
|
|
176
|
+
blog.heading("Blog")
|
|
177
|
+
blog.text("Latest posts...")
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
```bash
|
|
181
|
+
htmlforge render site.py
|
|
182
|
+
# → dist/home.html, dist/about.html, dist/blog.html
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
## License
|
|
186
|
+
|
|
187
|
+
[MPL-2.0](LICENSE)
|
htmlforge-0.0.1/demo.py
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"""Demo: 用 htmlforge 构建一个示例页面."""
|
|
2
|
+
import sys
|
|
3
|
+
sys.path.insert(0, r"E:\py\____My Lib\htmlforge\src")
|
|
4
|
+
|
|
5
|
+
from htmlforge import Page, H1, H2, P, Div, Table, Button, Img, List, Code, Pre
|
|
6
|
+
|
|
7
|
+
page = Page("htmlforge Demo")
|
|
8
|
+
|
|
9
|
+
page.add_css("""
|
|
10
|
+
body { font-family: 'Segoe UI', sans-serif; max-width: 800px; margin: 2rem auto; padding: 0 1rem; color: #333; }
|
|
11
|
+
.hero { text-align: center; padding: 2rem; background: linear-gradient(135deg, #667eea, #764ba2); color: white; border-radius: 12px; margin-bottom: 2rem; }
|
|
12
|
+
.card { border: 1px solid #e0e0e0; border-radius: 8px; padding: 1.5rem; margin: 1rem 0; }
|
|
13
|
+
table { width: 100%; border-collapse: collapse; }
|
|
14
|
+
th, td { padding: 8px 12px; border: 1px solid #ddd; text-align: left; }
|
|
15
|
+
th { background: #f5f5f5; }
|
|
16
|
+
.btn { background: #4CAF50; color: white; padding: 10px 20px; border: none; border-radius: 6px; cursor: pointer; font-size: 16px; }
|
|
17
|
+
""")
|
|
18
|
+
|
|
19
|
+
# Hero 区域
|
|
20
|
+
page.add(
|
|
21
|
+
Div(class_="hero").add(
|
|
22
|
+
H1("htmlforge"),
|
|
23
|
+
P("用 Python 写网页,一条命令导出 HTML"),
|
|
24
|
+
),
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
# 功能卡片
|
|
28
|
+
page.add(
|
|
29
|
+
Div(class_="card").add(
|
|
30
|
+
H2("为什么用 htmlforge?"),
|
|
31
|
+
List([
|
|
32
|
+
"零外部依赖,纯 Python 实现",
|
|
33
|
+
"40+ HTML 组件,覆盖所有常用标签",
|
|
34
|
+
"链式调用 API,写起来很舒服",
|
|
35
|
+
"类 manim 的 CLI 工具",
|
|
36
|
+
]),
|
|
37
|
+
),
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
# 对比表格
|
|
41
|
+
page.add(
|
|
42
|
+
Div(class_="card").add(
|
|
43
|
+
H2("对比"),
|
|
44
|
+
Table(
|
|
45
|
+
headers=["", "manim", "htmlforge"],
|
|
46
|
+
rows=[
|
|
47
|
+
["写什么", "Python 代码", "Python 代码"],
|
|
48
|
+
["输出什么", "MP4 视频", "HTML 网页"],
|
|
49
|
+
["\u547d\u4ee4", "manim scene.py", "htmlforge page.py"],
|
|
50
|
+
],
|
|
51
|
+
),
|
|
52
|
+
),
|
|
53
|
+
)
|
|
54
|
+
|
|
55
|
+
# 按钮
|
|
56
|
+
page.add(
|
|
57
|
+
Button("试试点击", onclick="alert('Hello from htmlforge!')", class_="btn"),
|
|
58
|
+
)
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"""htmlforge Doc 综合演示 — 完全不需要 HTML 知识."""
|
|
2
|
+
import sys
|
|
3
|
+
sys.path.insert(0, r"E:\py\____My Lib\htmlforge\src")
|
|
4
|
+
|
|
5
|
+
from htmlforge import Doc
|
|
6
|
+
|
|
7
|
+
page = Doc("htmlforge 演示")
|
|
8
|
+
|
|
9
|
+
# ---- 导航栏 ----
|
|
10
|
+
page.nav(("首页", "#"), ("文档", "#"), ("关于", "#"))
|
|
11
|
+
|
|
12
|
+
# ---- 标题 ----
|
|
13
|
+
page.heading("欢迎来到 htmlforge")
|
|
14
|
+
page.text("用 **Python** 写网页,一条命令导出 HTML。`零 HTML 知识`也能做到!")
|
|
15
|
+
|
|
16
|
+
# ---- 特性卡片 ----
|
|
17
|
+
page.heading("核心特性", 2)
|
|
18
|
+
|
|
19
|
+
page.card("零依赖", "不需要安装任何第三方库,纯 Python 实现")
|
|
20
|
+
page.card("内置主题", "自动自带一套简洁现代的样式,开箱即用")
|
|
21
|
+
page.card("Markdown 文本", "支持 **加粗**、*斜体*、`代码`、[链接](url)")
|
|
22
|
+
|
|
23
|
+
# ---- 三列布局 ----
|
|
24
|
+
page.heading("布局展示", 2)
|
|
25
|
+
|
|
26
|
+
page.row(
|
|
27
|
+
Doc.make_card("Python", "写你最擅长的语言"),
|
|
28
|
+
Doc.make_card("导出", "一条命令变成 HTML"),
|
|
29
|
+
Doc.make_card("部署", "放到任何静态托管"),
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
# ---- 表格 ----
|
|
33
|
+
page.heading("命令对比", 2)
|
|
34
|
+
|
|
35
|
+
page.table(
|
|
36
|
+
["工具", "输入", "输出", "命令"],
|
|
37
|
+
[
|
|
38
|
+
["manim", "Python 代码", "MP4 视频", "manim scene.py"],
|
|
39
|
+
["htmlforge", "Python 代码", "HTML 网页", "htmlforge page.py"],
|
|
40
|
+
],
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
# ---- 列表 ----
|
|
44
|
+
page.heading("组件一览", 2)
|
|
45
|
+
|
|
46
|
+
page.list([
|
|
47
|
+
"标题、段落、链接、图片",
|
|
48
|
+
"按钮、输入框、下拉框、文本区域",
|
|
49
|
+
"表格、列表、代码块",
|
|
50
|
+
"卡片、网格、折叠面板",
|
|
51
|
+
"导航栏、分隔线",
|
|
52
|
+
])
|
|
53
|
+
|
|
54
|
+
# ---- 代码块 ----
|
|
55
|
+
page.heading("代码示例", 2)
|
|
56
|
+
|
|
57
|
+
page.code("""\
|
|
58
|
+
from htmlforge import Doc
|
|
59
|
+
|
|
60
|
+
page = Doc("Hello")
|
|
61
|
+
page.heading("World")
|
|
62
|
+
page.text("Easy!")
|
|
63
|
+
""", lang="python")
|
|
64
|
+
|
|
65
|
+
# ---- 交互 ----
|
|
66
|
+
page.heading("试试看", 2)
|
|
67
|
+
|
|
68
|
+
page.button("点我弹窗", on_click="alert('Hello from htmlforge!')")
|
|
69
|
+
page.button("红色按钮", color="#e74c3c")
|
|
70
|
+
page.button("蓝色按钮", color="#3498db")
|
|
71
|
+
|
|
72
|
+
# ---- 表单 ----
|
|
73
|
+
page.heading("表单示例", 2)
|
|
74
|
+
|
|
75
|
+
page.input("你的名字", name="name")
|
|
76
|
+
page.input("你的邮箱", type="email", name="email")
|
|
77
|
+
page.textarea("留言内容...", rows="3")
|
|
78
|
+
page.select(["Python", "JavaScript", "Rust", "Go"])
|
|
79
|
+
|
|
80
|
+
# ---- 折叠面板 ----
|
|
81
|
+
page.details("常见问题:htmlforge 需要什么基础?",
|
|
82
|
+
"只需要会 Python!不需要了解 HTML 和 CSS。")
|
|
83
|
+
page.details("能自定义样式吗?",
|
|
84
|
+
"当然可以!用 `page.add_css()` 添加自定义 CSS。")
|
|
85
|
+
|
|
86
|
+
page.divider()
|
|
87
|
+
page.text("*用 [htmlforge](https://github.com) 构建 — Made with Python*")
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "htmlforge"
|
|
7
|
+
version = "0.0.1"
|
|
8
|
+
description = "Build web pages with Python, export to HTML with a single command"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = "MPL-2.0"
|
|
11
|
+
requires-python = ">=3.9"
|
|
12
|
+
keywords = ["html", "web", "page", "builder", "static-site"]
|
|
13
|
+
authors = [
|
|
14
|
+
{ name = "htmlforge contributors" }
|
|
15
|
+
]
|
|
16
|
+
classifiers = [
|
|
17
|
+
"Development Status :: 3 - Alpha",
|
|
18
|
+
"Intended Audience :: Developers",
|
|
19
|
+
"License :: OSI Approved :: Mozilla Public License 2.0 (MPL 2.0)",
|
|
20
|
+
"Programming Language :: Python :: 3",
|
|
21
|
+
"Topic :: Internet :: WWW/HTTP",
|
|
22
|
+
"Topic :: Text Processing :: Markup :: HTML",
|
|
23
|
+
]
|
|
24
|
+
dependencies = []
|
|
25
|
+
|
|
26
|
+
[project.scripts]
|
|
27
|
+
htmlforge = "htmlforge.cli:render"
|
|
28
|
+
|
|
29
|
+
[project.urls]
|
|
30
|
+
Homepage = "https://github.com/htmlforge/htmlforge"
|
|
31
|
+
|
|
32
|
+
[tool.hatch.build.targets.wheel]
|
|
33
|
+
packages = ["src/htmlforge"]
|
|
34
|
+
|
|
35
|
+
[tool.pytest.ini_options]
|
|
36
|
+
testpaths = ["tests"]
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"""htmlforge — Build web pages with Python, export to HTML."""
|
|
2
|
+
|
|
3
|
+
__version__ = "0.0.1"
|
|
4
|
+
|
|
5
|
+
from htmlforge.simple import Doc
|
|
6
|
+
|
|
7
|
+
from htmlforge.core import (
|
|
8
|
+
# Base
|
|
9
|
+
Element, Page,
|
|
10
|
+
# Structural
|
|
11
|
+
Div, Section, Header, Footer, Nav, Main, Article, Aside, Span, Container,
|
|
12
|
+
# Text
|
|
13
|
+
H1, H2, H3, H4, H5, H6, P, Strong, Em, Blockquote,
|
|
14
|
+
Code, Pre, Small, Mark, Sub, Sup,
|
|
15
|
+
Text, Link,
|
|
16
|
+
# Lists
|
|
17
|
+
Ul, Ol, Li, List,
|
|
18
|
+
# Media
|
|
19
|
+
Img, Video, Audio, Source, Iframe, Canvas,
|
|
20
|
+
# Table
|
|
21
|
+
Table, Thead, Tbody, Tr, Th, Td, Caption,
|
|
22
|
+
# Forms
|
|
23
|
+
Form, Input, Textarea, Select, Option,
|
|
24
|
+
Checkbox, Radio, Label, Button,
|
|
25
|
+
# Misc
|
|
26
|
+
Hr, Br, Meta, Progress, Details, Summary,
|
|
27
|
+
)
|