You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+96-77Lines changed: 96 additions & 77 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,9 @@
1
1
# SuperHTML
2
+
2
3
HTML Validator, Formatter, LSP, and Templating Language Library
3
4
4
5
## SuperHTML CLI Tool
6
+
5
7
The SuperHTML CLI Tool offers **validation** and **autoformatting** features for HTML files.
6
8
7
9
The tool can be used either directly (for example by running it on save), or through a LSP client implementation.
@@ -22,152 +24,152 @@ General Options:
22
24
--syntax-only Disable HTML element and attribute validation.
23
25
```
24
26
25
-
>[!WARNING]
26
-
>SuperHTML only supports HTML5 (the WHATWG living spec) regardless of what you put in your doctype (a warning will be generated for unsupported doctypes).
27
+
>[!WARNING]
28
+
>SuperHTML only supports HTML5 (the WHATWG living spec) regardless of what you put in your doctype (a warning will be generated for unsupported doctypes).
27
29
28
-
>[!WARNING]
29
-
>Templated HTML (Jinja2, Angular, Mustache, ...) is not yet supported when all validation rules are enabled, use `--syntax-only` (or the relative Extension Setting in VSCode) to limit validation to syntax errors to use SuperHTML with templated HTML documents.
30
+
>[!WARNING]
31
+
>Templated HTML (Jinja2, Angular, Mustache, ...) is not yet supported when all validation rules are enabled, use `--syntax-only` (or the relative Extension Setting in VSCode) to limit validation to syntax errors to use SuperHTML with templated HTML documents.
30
32
>
31
-
> Compatibility with popular templating languages is being explored.
32
-
33
+
> Compatibility with popular templating languages is being explored.
33
34
34
35
### Diagnostics
36
+
35
37
SuperHTML validates not only syntax but also element nesting and attribute values.
36
38
No other language server implements the full HTML spec in its validation code.
37
39
38
40

39
41
40
-
41
42
### Autoformatting
43
+
42
44
The autoformatter has two main ways of interacting with it in order to request for horizontal / vertical alignment.
43
45
44
46
1. Adding / removing whitespace between the **start tag** of an element and its content.
45
-
2. Adding / removing whitespace between the **last attribute** of a start tag and the closing `>`.
46
-
47
-
48
-
>[!TIP]
49
-
>Consider using `superhtml fmt --check` in your CI to enforce every change to be performed on normalized HTML files. This is a technique commonly used in Zig (and Go) for source code that can also help streamline frontend development.
47
+
2. Adding / removing whitespace between the **last attribute** of a start tag and the closing `>`.
50
48
49
+
> [!TIP]
50
+
> Consider using `superhtml fmt --check` in your CI to enforce every change to be performed on normalized HTML files. This is a technique commonly used in Zig (and Go) for source code that can also help streamline frontend development.
Install the [Super HTML VSCode extension](https://marketplace.visualstudio.com/items?itemName=LorisCro.super) (doesn't require the CLI tool as it bundles a WASM build of the language server).
120
119
121
120
#### Neovim
121
+
122
122
1. Download a prebuilt version of `superhtml` from the Releases section (or build it yourself).
See [WeetHet/superhtml-zed](https://github.com/WeetHet/superhtml-zed).
180
183
181
184
#### Other editors
182
-
Follow your editor specific instructions on how to define a new Language Server for a given language / file format.
183
185
184
-
*(Also feel free to contribute more specific instructions to this readme / add files under the `editors/` subdirectory).*
186
+
Follow your editor specific instructions on how to define a new Language Server for a given language / file format.
185
187
188
+
_(Also feel free to contribute more specific instructions to this readme / add files under the `editors/` subdirectory)._
186
189
187
190
## FAQs
191
+
188
192
### Why doesn't SuperHTML support self-closing tags?
193
+
189
194
Because self-closing tags don't exist in HTML and, while harmless when used with void elements, it just keeps misleating people into thinking that you can self-close HTML tags.
190
195
191
196
In particular, given this HTML code:
192
197
193
198
```html
194
199
<!doctype html>
195
-
<html>
200
+
<html>
196
201
<head></head>
197
202
<body>
198
-
<div/>
203
+
<div/>
199
204
<p></p>
200
205
</body>
201
206
</html>
@@ -208,9 +213,11 @@ Add to that the fact that tooling like the default HTML formatter in VSCode will
### Why doesn't SuperHTML report duplicate values in `[class]` as an error?
211
-
The HTML spec defines the global `class` attribute as a space-separated list of tokens, as opposed to a space-separated list of *unique* tokens, like some other attributes are (e.g. `accesskey`).
216
+
217
+
The HTML spec defines the global `class` attribute as a space-separated list of tokens, as opposed to a space-separated list of _unique_ tokens, like some other attributes are (e.g. `accesskey`).
212
218
213
219
### Why is `<style>` under `<body>` an error? It works in all browsers!
220
+
214
221
As far as I'm concerned, there is no good reason to forbid `<style>` in body, but that's what the HTML spec does.
215
222
216
223
Related upstream issue: https://github.com/whatwg/html/issues/1605
@@ -222,23 +229,24 @@ One common example is `<li>`, which enables this usage pattern:
222
229
223
230
```html
224
231
<ul>
225
-
<li>First point
226
-
<li>Second point
227
-
</ul>
232
+
<li>First point</li>
233
+
<li>Second point</li>
234
+
</ul>
228
235
```
229
236
230
237
The reason why this is not ambiguous is that `<li>`cannot be nested inside
231
238
another `<li>` so whe the second sibling is encountered, it's possible to always
232
239
correctly implicitly close the first `<li>`.
233
240
234
241
SuperHTML breaks compatibility with the HTML spec in this regard for one main reason:
235
-
while implicitly closed tags are unambiguous in *valid* HTML documents, it creates a
242
+
while implicitly closed tags are unambiguous in _valid_ HTML documents, it creates a
236
243
problematic gray area when it comes to typos.
237
244
238
245
Consider the following snippet:
239
246
240
247
```html
241
-
<li>first point<li>
248
+
<li>first point</li>
249
+
<li></li>
242
250
```
243
251
244
252
If SuperHTML were to follow the HTML spec it would have to consider this valid
@@ -254,16 +262,26 @@ If you want to write HTML code that leverages this feature, do not use SuperHTML
254
262
as there are no plans to ever support it.
255
263
256
264
#### But what about Google AMP?
265
+
257
266
Why are you letting an ad company decide what the world wide web should look like.
258
267
Do you want ads? Because that's how you get ads.
259
268
260
269
## Templating Language Library
261
-
SuperHTML is also a HTML templating language. More on that soon.
270
+
271
+
SuperHTML is also a HTML templating language.
272
+
273
+
First make sure to familiarize yourself with the process to setup a
274
+
ScriptyVM (see https://github.com/kristoff-it/scripty).
275
+
276
+
See `src/example.zig` for more info. Note that the API is not polished yet and
277
+
will change over time.
262
278
263
279
## Contributing
280
+
264
281
SuperHTML tracks the latest Zig release (0.15.1 at the moment of writing).
265
282
266
283
### Contributing to the HTML parser & LSP
284
+
267
285
Contributing to the HTML parser and LSP doesn't require you to be familiar with the templating language, basically limiting the scope of what you have to worry about to:
268
286
269
287
-`src/cli.zig`
@@ -277,6 +295,7 @@ You can invoke `zig build test` to run all unit tests.
277
295
Running `zig build` will compile the SuperHTML CLI tool, allowing you to also then test the LSP behavior directly from your favorite editor.
278
296
279
297
For testing within VSCode:
298
+
280
299
1. Run `zig build wasm -p src/editors/vscode/wasm`
0 commit comments