Skip to content

Commit b1014ea

Browse files
committed
Document generating HTML
Otherwise how will people know about it
1 parent 30af90c commit b1014ea

File tree

4 files changed

+83
-2
lines changed

4 files changed

+83
-2
lines changed

README.md

+13-1
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,21 @@ Lukas Oppermann and
2424
https://www.figma.com/community/file/946837271092540314 by Joe Horton and
2525
licensed under [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/).
2626

27+
## HTML
28+
29+
Generate HTML from Figma nodes or components.
30+
31+
```bash
32+
cargo run --release -- to-html 213:6 < example-figma-files/gov-uk-design-system.json > example-figma-files/gov-uk-design-system-components/button.html
33+
```
34+
35+
[Read more](src/to_html/README.md)
36+
2737
## Schema Definitions
2838

29-
Schema definitions are exported for various languages using [1Password's typeshare](https://github.com/1Password/typeshare). PRs are welcome to make better use of `typeshare`'s potential.
39+
Schema definitions are exported for various languages using
40+
[1Password's typeshare](https://github.com/1Password/typeshare). PRs are welcome
41+
to make better use of `typeshare`'s potential.
3042

3143
[TypeScript](./typescript/) has an NPM package and support for Deno.
3244

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"scripts": {
3-
"prettier": "prettier --write --prose-wrap=always **/*.md **/*.json **/*.html"
3+
"prettier": "prettier --write --prose-wrap=always '**/*.md' '**/*.json' '**/*.html'"
44
},
55
"devDependencies": {
66
"prettier": "^2.8.0"

selecting-node-id.png

550 KB
Loading

src/to_html/README.md

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# Figma REST API HTML Generator
2+
3+
Generate HTML files from files fetched through the
4+
[Figma REST API](https://www.figma.com/developers/api).
5+
6+
## Example output discussed
7+
8+
[example](../../example-figma-files/gov-uk-design-system-components/button.html)
9+
10+
```html
11+
<div
12+
style="
13+
color: #fff;
14+
font-family: GDS Transport Website;
15+
font-size: 19px;
16+
font-weight: 300;
17+
line-height: 25px;
18+
"
19+
data-figma-name="Content: Text"
20+
data-figma-id="1:9"
21+
>
22+
Button
23+
</div>
24+
```
25+
26+
The CSS used to format the HTML is inline on each HTML tag. No attempt is yet
27+
made to use CSS stylesheets or assign helpers like CSS classes.
28+
29+
Some absolute positioning and absolute sizing is used where it can't be avoided.
30+
Using
31+
[auto-layout](https://help.figma.com/hc/en-us/articles/5731482952599-Using-auto-layout)
32+
mostly prevents that as it gets converted to flex-box.
33+
34+
The HTML maps directly to nodes within Figma. A deeply nested Figma design will
35+
generate deeploy nested html.
36+
37+
No fallback fonts are specified.
38+
39+
Vectors are replaced by an SVG placeholder.
40+
41+
## Direction
42+
43+
I'm undecided to if this is going to be:
44+
45+
- A general purpose HTML generator.
46+
- A generator designed to adapt to peculiarities of a few designs (for example
47+
ones I use at work).
48+
- A tool designed to be flexible with lots of configuration.
49+
- An inspiration from which other generators can be built. These could even in
50+
other languages like TypeScript since I generate types.
51+
52+
## Usage
53+
54+
```bash
55+
cargo run --release -- to-html 213:6 < example-figma-files/gov-uk-design-system.json > example-figma-files/gov-uk-design-system-components/button.html
56+
```
57+
58+
You can get the node id from the URL when using the web-ui.
59+
60+
![Screenshot of Gov UK design system in Figma web view with Button component selected and node-id=213-6 highlighted in the address bar](../../selecting-node-id.png)
61+
62+
The HTML can be piped through additional commands to add fallback fonts and to
63+
format the HTML.
64+
65+
```bash
66+
cargo run --release -- to-html 213:6 < example-figma-files/gov-uk-design-system.json \
67+
| sed 's/font-family: GDS Transport Website;/font-family: GDS Transport Website,arial,sans-serif;/g' \
68+
| npx prettier@2.8.4 --parser html > example-figma-files/gov-uk-design-system-components/button.html
69+
```

0 commit comments

Comments
 (0)