Skip to content

Commit d58839d

Browse files
committed
Alternative: exact HTML syntax
1 parent 15dd922 commit d58839d

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

exploration/open-close-expressions.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,3 +245,43 @@ This is <html:strong>bold</html:strong> and this is <html:img alt="an image">.
245245
* It cannot be validated via the AST nor the reigstry.
246246
* It cannot be protected, unless put inside literal expressions.
247247
* It is not supported by `formatToParts`, which in turn makes double-parsing difficult.
248+
249+
### HTML Syntax
250+
251+
We could parse the HTML syntax as part of MessageFormat parsing,
252+
and represent markup as first-class data-model concepts of MessageFormat.
253+
254+
```
255+
This is <html:strong>bold</html:strong> and this is <html:img alt="an image">.
256+
```
257+
258+
To represent HTML's auto-closing tags, like `<img>`,
259+
we could follow HTML's syntax to the letter, similer to the snippet above,
260+
and use the *span-open* syntax for them.
261+
This would be consistent with HTML, but would require:
262+
263+
* Either the parser to hardcode which elements are standalone;
264+
this approach wouldn't scale well beyond the current set of HTML elements.
265+
266+
* Or, the validation and processing which leverages the open/close and standalone concepts
267+
to be possible only when the registry is available.
268+
269+
Alternatively, we could diverge from proper HTML,
270+
and use the stricter XML syntax: `<img/>`.
271+
272+
```
273+
This is <html:strong>bold</html:strong> and this is <html:img alt="an image" />.
274+
```
275+
276+
The same approach would be used for self-closing elements defined by other dialects of XML.
277+
278+
#### Pros:
279+
280+
* Looks like HTML.
281+
* The least surprising syntax for developers and translators.
282+
283+
#### Cons:
284+
285+
* Looks like HTML, but isn't *exactly* HTML, unless we go to great lengths to make it so.
286+
See the differences between HTML and React's JSX as a case-study of consequences.
287+
* Requires quoting in XML-based containers.

0 commit comments

Comments
 (0)