This repository has been archived by the owner on Oct 1, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
spec.txt
1640 lines (1083 loc) · 36.9 KB
/
spec.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# MDX
> 🪦 **Archived**: this document is not maintained.
> This document was made jointly with `micromark`,
> which was later also turned into `markdown-rs`.
> At present,
> I don’t have the bandwidth to maintain 2 reference parsers
> *and* a spec.
> Markdown 💛 JSX
> This document is currently in progress.
> See also [micromark][], [cmsm][], and [mdxjs][].
## Contents
## Background
### What is MDX?
MDX is the combination of [Markdown][commonmark] with [JSX][].
This document defines a syntax for MDX (without JavaScript, [MDXjs][] does
that) by describing how to parse it.
### Who created MDX?
The idea of combining [Markdown][commonmark], [JavaScript][], and [JSX][] was
a collaborative effort by [Guillermo Rauch][mdx-rauchg] (**[@rauchg][]**),
[James K. Nelson][mdx-jamesknelson] (**[@jamesknelson][]**), [John
Otander][mdx-johno] (**[@johno][]**), Tim Neutkens (**[@timneutkens][]**),
Brent Jackson (**[@jxnblk][]**), Jessica Stokes (**[@ticky]**), and more.
Markdown was [created by John Gruber][md] (**[@gruber][]**).
[CommonMark by John McFarlane et al.][commonmark] (**[@jgm][]**) is a popular
variant.
JSX was [created by Sebastian Markbåge et al.][jsx] (**[@sebmarkbage][]**) at
Facebook, Inc.
### Why MDX?
Markdown does not have a syntax for custom components.
MDX solves this.
There are many languages objectively better than Markdown, however, Markdown
is great because:
* It looks like what it means and is relatively easy to read
* Although images are [confusing][], most stuff is relatively simple to write
* It’s loose and ambiguous: it may not work but you won’t get an error (great
for someone posting a comment to a forum if they forgot an asterisk)
Markdown *does* have a way to extend it, HTML, but that has drawbacks:
* HTML in Markdown is naïve, how it’s parsed sometimes doesn’t make sense
* HTML is unsafe by default, so it’s sometimes (partially) unsupported
* HTML and Markdown don’t mix well, resulting in confusing rules such as
blank lines or `markdown="1"` attributes
* HTML is coupled with browsers, Markdown is useful for other things too
The frontend world has an alternative to HTML: JSX.
JSX is great, amongst other things, because:
* It has a relatively familiar syntax (like XML)
* It’s agnostic to semantics and intended for compilers (can have any
domain-specific meaning)
* It’s strict and unambiguous (great if an editor forgot a slash somewhere, as
they’ll get an error early, instead of a book going to print with broken
stuff in it)
## Overview
This document first talks about the MDX syntax for authors, in the following
section.
Further sections define the syntax in-depth and for developers.
The appendix includes sections on notable differences from Markdown and JSX,
and a list of common MDX gotchas.
## MDX
This section explains MDX for authors.
### Hello World
The smallest MDX example looks like this:
```markdown
# Hello, world!
```
It displays a heading saying “Hello, world!” on the page.
With MDX you can add components:
```jsx
<MyComponent># Hello, world!</MyComponent>
```
MDX syntax can be boiled down to being JSX in Markdown.
It’s a superset of Markdown syntax that supports JSX.
### Markdown
Traditionally, Markdown is used to generate HTML.
Many developers like writing markup in Markdown as it often looks more like
what’s intended and it is typically terser.
Instead of the following HTML:
```html
<blockquote>
<p>A block quote with <em>some</em> emphasis.</p>
</blockquote>
```
You can write the equivalent in Markdown (or MDX) like so:
```markdown
> A block quote with _some_ emphasis.
```
Markdown is good for **content**.
MDX supports [most standard Markdown syntax][markdown-deviations].
It’s important to understand Markdown in order to learn MDX.
### JSX
Recently, more and more developers have started using [JSX][] to generate HTML
markup.
JSX is typically combined with a frontend framework like React or Vue.
These frameworks add support for components, which let you change repeating
things like the following markup:
```html
<h2>Hello, Venus!</h2>
<h2>Hello, Mars!</h2>
```
…to JSX (or MDX) like this:
```jsx
<Welcome name="Venus" />
<Welcome name="Mars" />
```
JSX is good for **components**.
It makes repeating things more clear and allows for separation of concerns.
MDX supports [most standard JSX syntax][jsx-deviations].
### MDX
MDX is the combination of Markdown and JSX, for example, like so:
````mdx
<MyComponent>> Block quote</MyComponent>
<MyCodeComponent>
```html
<!doctype html>
```
</MyCodeComponent>
<MyOtherComponent>
# Heading<Footnote id="1" />
- List
- Items
</MyOtherComponent>
<Image
alt='Photo of Lilo sitting in a tiny box'
src='lilo.png'
/>
<also-component {attribute expression} />
<math value={attribute value expression} />
{
block expression
}
The sum of `1 + 1` as calculated by an inline expression is {1 + 1}.
````
### Syntax
The syntax of MDX within Markdown is formally defined by how to parse in [§ 4
Parsing][parsing] and in further sections, relatively formally in [§ 7.1
Syntax][syntax]), and informally by example here.
As MDX is not tied to HTML or JavaScript, the following examples do not show
output examples in HTML, but instead show whether they are okay, or whether they
crash.
For ease of reading, block elements will be capitalized, whereas span elements
will be lowercase, in the following examples.
But, casing does not affect parsing.
#### Block
A block of MDX is an element or expression that is both the first thing on its
opening line, and the last thing on its closing line.
A self-closing block tag:
```mdx
<Component />
```
The start and end can be on different lines:
```mdx
<Component
/>
```
An arbitrary number of lines can be between the start and end:
```mdx
<Component
/>
```
This also applies to elements with opening and closing tags:
```mdx
<Component>
</Component>
```
Expressions can also be blocks:
```mdx
{
}
```
Parent containers of components don’t count when figuring out if something is
the first or last thing, such as in a block quote, a list, or in another block
component:
```mdx
> <Component />
- <Component />
<Parent>
<Child />
</Parent>
```
#### Span
A span of MDX is an element or expression that is not a block: it’s either not
the first thing, or the last thing, or both:
```mdx
This span is preceded by other things: <component />
<component /> This span is followed by other things.
These rules also apply to expressions ({ such as this one }).
```
#### Content
An MDX block element can contain further Markdown blocks, whereas an MDX span
element can contain further Markdown spans.
On a single line:
```mdx
<Component>> Block quote</Component>
```
With generous whitespace:
```mdx
<Component>
> Block quote
</Component>
```
With indentation:
```mdx
<Component>
> Block quote
</Component>
```
Spans cannot contain blocks:
```mdx
<component>> this is not a block quote</component>, because it’s not in a block
element.
Nor is this a <component># heading</component>
```
Blocks will create paragraphs:
```mdx
<Component>**Strongly important paragraph in a component**.</Component>
This <component>**is strongly important text in a component**</component> in a
paragraph.
```
Which gets a bit confusing if you are expected HTML semantics (to MDX, elements
don’t have semantics, so `h2` has no special meaning):
```mdx
<h2>And this is a paragraph in a heading!</h2>
```
MDX expressions can contain arbitrary data, with the exception that there must
be a matching number opening braces (c:{) and closing braces (c:}):
```mdx
{
This is a fine expression: no opening or closing braces
}
So is this: {{{}}}.
And this, an expression with extra closing braces after it: {}}}.
```
This example is incorrect, as there are not enough closing braces:
```mdx
{{{}.
```
#### Closing MDX
MDX elements and expressions must be closed, and what closes them must be in an
expected place:
This example is incorrect, an unclosed tag:
```mdx
<Component>
```
This example is incorrect, because the “closing” tag is in fenced code.
````mdx
<Component>
```js
</Component>
```
````
This example is incorrect, because the “closing” tag is outside of the block
quote:
```mdx
> <Component>
</Component>
```
This example is incorrect, because the “closing” tag is not in the paragraph:
```mdx
A span component <component>
</component>
```
This example is incorrect, because the “closing” tag is in a different
paragraph:
```mdx
<component>This is one paragraph, with an inline opening tag.
This is another paragraph, with an inline closing tag</component>.
```
The same rules apply to expressions:
```mdx
{This is all fine…
…but because there is a dot after the closing brace, it’s not a block, which
results in two paragraphs, which means that the first paragraph has an unclosed
expression}.
```
#### Attributes
MDX elements can have three types of attributes.
Attribute expressions:
```mdx
<Component {attribute expression} />
```
Boolean attributes:
```mdx
<Component boolean another />
```
Or initialized attributes, with a value.
```mdx
<Component key="value" other="more" />
```
Attribute values can also use single quotes:
```mdx
<Component quotes='single quotes: also known as apostrophes' />
```
Finally, attribute value expressions can be used with braces:
```mdx
<Component data={attribute value expression} />
```
#### Names
Element names are optional, which is a feature called “fragments”:
```mdx
<>Fragment block with a paragraph</>
A <>fragment span</> in a paragraph.
```
The syntax of the name of an element follows the syntax of variables in
JavaScript, and dashes are also allowed (but not at the start):
```mdx
This is fine: <π />.
Also fine: <ab /> (there’s a zero-width non-joiner in there).
Dashes are <c-d /> fine too!
```
Names can be prefixed with a namespace using a colon:
```mdx
<svg:rect />
```
Similar to namespaces, dots can be used to access methods from objects:
```mdx
<org.acme.example />
```
(Namespaces and methods cannot be combined).
#### Keys
Similar to names, keys of attributes also follow the same syntax as JavaScript
variables, and dashes are also allowed:
```mdx
This is all fine: <x π ab c-d />.
```
And namespaces can also be used:
```mdx
This is all fine: <z xml:lang="de" />.
```
(Methods don’t work for keys).
#### Whitespace
Whitespace is mostly optional, except between two identifiers (such as the
name and a key, or between two keys):
```mdx
This is fine: <x/>.
Also fine: <x{attribute expression}/>.
Fine too: <v w=""x=''y z/>.
```
Most places accept whitespace:
```mdx
A bit much, but sure: < w / >.
< x >Go ahead< / x >
< z do your = 'thing' >
```
## Parsing
The states of the [MDX state machine][] have certain effects, such as that they
create tokens in the [stack][] and [consume][] characters.
The purpose of the state machine is to tokenize.
The stack is used by adapters.
The [MDX adapter][] handles tokens, which has further effects, such as
validating whether they are conforming and figuring out when parsing is done.
The purpose of the adapter is to handle the results of the tokenizer.
To parse MDX is to feed the [input character][] to the [state][] of the state
machine, and when not [settled][], repeat this step.
If parsing [crashed][] with a label the content is nonsensical and the document
cannot be processed.
Without label, no MDX was found.
How MDX, whether it’s found or not, is handled is intentionally undefined and
left up to the host parser.
When to feed an [c:EOF] is similarly undefined.
Host parsers must not support indented code and autlinks, as those conflict with
MDX.
### Characters
A character is a Unicode code point and is represented as a four to six digit
hexadecimal number, prefixed with `U+` (**\[UNICODE]**).
#### Character groups
[Whitespace](#) is any character defined as [`WhiteSpace`][es-whitespace]
(**\[JavaScript]**).
[Identifier start](#) is any character defined as
[`IdentifierStart`][es-identifier-start], with the restriction that unicode
escape sequences do not apply (**\[JavaScript]**).
[Identifier](#) is any character defined as
[`IdentifierPart`][es-identifier-part], with the restriction that unicode escape
sequences do not apply (**\[JavaScript]**).
#### Conceptual characters
An [c:EOF](#) character is a conceptual character (as in, not real character)
representing the lack of any further characters in the input.
### Infra
The [input stream](#) consists of the characters pushed into it.
The [input character](#) is the first character in the [input stream][] that has
not been consumed.
Initially, the input character is the first character in the input.
Finally, when all character are consumed, the input character is an [c:EOF][].
The [stack](#) is a list of tokens that are open, initially empty.
The [current token](#) is the last token in the [stack][].
The [value](#) of a token are all characters in the [input stream][] from where
the token was [enter][]ed (including) to where it [exit][]ed (excluding).
The [element stack](#) is a list of elements that are open, initially empty.
The [current element](#) is the last element in the [element stack][].
[Settled](#) is used to signal when parsing is done, whether it was a success
or not, and is initially off.
[Crashed](#) is used to signal when parsing is unsuccessful, and is initially
off.
The [state](#) is the way a character is handled.
A variable is declared with `let`, cleared with `unset`, or changed with
`set` (to set a value), `increment` (to add a numeric value), `decrement` (to
subtract a numeric value), `append` (to add a string value), `push` (to add a
value to a list), or `pop` (to remove a value from the end of a list).
Which values are used are left to the host programming language, but this
definition requires compatibility with **\[JSON]** for primitives (strings,
numbers, booleans, and null) and structured types (objects and arrays).
The [shared space](#) is an object.
`size`, `sizeOpen`, `currentAttribute`, and `currentTag` are variables in the
[shared space][].
These variables are available globally to all states and adapters.
Other variables are available locally to a state or adapter and not shared.
To [dedent](#) is to remove up to X initial c:HT or c:SP characters from each
non-initial line in the given value, where X is the minimum number of c:HT or
c:SP characters of all non-initial lines that contain other characters.
To [decode](#) is to parse character references as defined in “Character
reference state” of § 12.2 Parsing HTML documents (**\[HTML]**).
### Effects
The [MDX state machine][] and [MDX adapter][] have certain common effects.
#### Switch
To [switch](#) to a state is to wait for a character in the given state.
#### Consume
To [consume](#) the [input character][] is to move on from it to the next
character in the [input stream][].
#### Enter
To [enter](#) a token is to push a new token of the given type to the [stack][],
making it the [current token][].
#### Exit
To [exit](#) is to pop the [current token][] from the [stack][].
#### Done
[Done](#) is used to mark parsing as [settled][].
#### Crash
[Crash](#) is used to mark parsing as [settled][] and [crashed][].
When crashing with a given label, crashing causes a parse error.
## State machine
The [MDX state machine](#) is used to tokenize MDX blocks and MDX spans.
Blocks (also known as flow) make up the structure of the document (such as
headings), whereas spans (also known as text or inline) make up the
intra-paragraph parts of the flow (such as emphasis).
The initial state varies based on whether flow or text is parsed, and is
respectively either s:before-mdx-block or s:before-mdx-span.
The final state is switched to by the [MDX adapter][], which right before
completion will [switch][] to either s:after-mdx-block or s:after-mdx-span.
### Before MDX block state
* ↪ **c:HT**\
↪ **c:SP**
[Consume][]
* ↪ **Anything else**
[Switch][] to s:before-mdx-span
### Before MDX span state
* ↪ **c:<**\
↪ **c:{**
[Switch][] to s:data
* ↪ **Anything else**
[Crash][]
### After MDX block state
* ↪ **c:HT**\
↪ **c:SP**
[Consume][]
* ↪ **[c:EOF][]**\
↪ **c:LF**\
↪ **c:CR**
[Done][]
* ↪ **Anything else**
[Crash][]
### After MDX span state
[Done][]
### Data state
* ↪ **c:<**
[Switch][] to s:before-name, [enter][] `'tag'`, and [consume][]
* ↪ **c:{**
[Switch][] to s:expression, [enter][] `'expression'`, let `size` be `1`, and
[consume][]
* ↪ **Anything else**
[Switch][] to s:text and [enter][] `'text'`
### Before name state
* ↪ **c:/**
[Switch][] to s:before-closing-tag-name, [enter][] `'closingSlash'`,
[consume][], and [exit][]
* ↪ **c:>**
[Switch][] to s:data, [enter][] `'name'`, [exit][], [consume][], and
[exit][]
* ↪ **[Whitespace][]**
[Consume][]
* ↪ **[Identifier start][]**
[Switch][] to s:primary-name, [enter][] `'name'`, [enter][] `'primaryName'`,
and [consume][]
* ↪ **Anything else**
[Crash][] `'before name'`
### Before closing tag name state
* ↪ **c:>**
[Switch][] to s:data, [enter][] `'name'`, [exit][], [consume][], and
[exit][]
* ↪ **[Whitespace][]**
[Consume][]
* ↪ **[Identifier start][]**
[Switch][] to s:primary-name, [enter][] `'name'`, [enter][] `'primaryName'`,
and [consume][]
* ↪ **Anything else**
[Crash][] `'before name'`
### Primary name state
* ↪ **c:-**\
↪ **[Identifier][]**
[Consume][]
* ↪ **c:.**\
↪ **c:/**\
↪ **c::**\
↪ **c:>**\
↪ **c:{**\
↪ **[Whitespace][]**
[Switch][] to s:after-primary-name and [exit][]
* ↪ **Anything else**
[Crash][] `'in name'`
### After primary name state
* ↪ **c:.**
[Switch][] to s:before-member-name and [consume][]
* ↪ **c::**
[Switch][] to s:before-local-name and [consume][]
* ↪ **c:/**\
↪ **c:>**\
↪ **c:{**\
↪ **[Identifier start][]**
[Switch][] to s:before-attribute and [exit][]
* ↪ **[Whitespace][]**
[Consume][]
* ↪ **Anything else**
[Crash][] `'after name'`
### Before member name state
* ↪ **[Identifier start][]**
[Switch][] to s:member-name, [enter][] `'memberName'`, and [consume][]
* ↪ **[Whitespace][]**
[Consume][]
* ↪ **Anything else**
[Crash][] `'before member name'`
### Member name state
* ↪ **c:-**\
↪ **[Identifier][]**
[Consume][]
* ↪ **c:.**\
↪ **c:/**\
↪ **c:>**\
↪ **c:{**\
↪ **[Whitespace][]**
[Switch][] to s:after-member-name and [exit][]
* ↪ **Anything else**
[Crash][] `'in member name'`
### After member name state
* ↪ **c:.**
[Switch][] to s:before-member-name and [consume][]
* ↪ **c:/**\
↪ **c:>**\
↪ **c:{**\
↪ **[Identifier start][]**
[Switch][] to s:before-attribute and [exit][]
* ↪ **[Whitespace][]**
[Consume][]
* ↪ **Anything else**
[Crash][] `'after member name'`
### Before local name state
* ↪ **[Identifier start][]**
[Switch][] to s:local-name, [enter][] `'localName'`, and [consume][]
* ↪ **[Whitespace][]**
[Consume][]
* ↪ **Anything else**
[Crash][] `'before local name'`
### Local name state
* ↪ **c:-**\
↪ **[Identifier][]**
[Consume][]
* ↪ **c:/**\
↪ **c:>**\
↪ **c:{**\
↪ **[Whitespace][]**
[Switch][] to s:after-local-name, [exit][], and [exit][]
* ↪ **Anything else**
[Crash][] `'in local name'`
### After local name state
* ↪ **c:/**\
↪ **c:>**\
↪ **c:{**\
↪ **[Identifier start][]**
[Switch][] to s:before-attribute
* ↪ **[Whitespace][]**
[Consume][]
* ↪ **Anything else**
[Crash][] `'after local name'`
### Before attribute state
* ↪ **c:/**
[Switch][] to s:self-closing, [enter][] `'selfClosingSlash'`, [consume][],
and [exit][]
* ↪ **c:>**
[Switch][] to s:data, [consume][], and [exit][]
* ↪ **c:{**
[Switch][] to s:attribute-expression, [enter][] `'attributeExpression'`, let
`size` be `1`, and [consume][]
* ↪ **[Whitespace][]**
[Consume][]
* ↪ **[Identifier start][]**
[Switch][] to s:attribute-name, [enter][] `'attributeName'`, and [consume][]
* ↪ **Anything else**
[Crash][] `'before attribute name'`
### Attribute expression state
* ↪ **[c:EOF][]**
[Crash][] `'in attribute expression'`
* ↪ **c:{**
Increment `size` by `1` and [consume][]
* ↪ **c:}**
If `size` is:
* ↪ **`1`**
[Switch][] to s:before-attribute, unset `size`, [consume][], and
[exit][]
* ↪ **Anything else**
Decrement `size` by `1` and [consume][]
* ↪ **Anything else**
[Consume][]
### Attribute name state
* ↪ **c:-**\
↪ **[Identifier start][]**
[Consume][]
* ↪ **c:/**\
↪ **c::**\
↪ **c:=**\
↪ **c:>**\
↪ **c:{**\
↪ **[Whitespace][]**
[Switch][] to s:after-attribute-name and [exit][]
* ↪ **Anything else**
[Crash][] `'in attribute name'`
### After attribute name state
* ↪ **c::**
[Switch][] to s:before-attribute-local-name and [consume][]
* ↪ **c:=**
[Switch][] to s:before-attribute-value and [consume][]
* ↪ **c:/**\
↪ **c:>**\
↪ **c:{**\
↪ **[Identifier start][]**
[Switch][] to s:before-attribute
* ↪ **[Whitespace][]**
[Consume][]
* ↪ **Anything else**
[Crash][] `'after attribute name'`
### Before attribute local name state
* ↪ **[Identifier start][]**
[Switch][] to s:attribute-local-name, [enter][] `'attributeLocalName'`, and
[consume][]
* ↪ **[Whitespace][]**
[Consume][]
* ↪ **Anything else**
[Crash][] `'before local attribute name'`
### Attribute local name state
* ↪ **c:-**\
↪ **[Identifier start][]**
[Consume][]
* ↪ **c:/**\
↪ **c:=**\
↪ **c:>**\
↪ **c:{**\
↪ **[Whitespace][]**
[Switch][] to s:after-attribute-local-name and [exit][]
* ↪ **Anything else**
[Crash][] `'in local attribute name'`
### After attribute local name state
* ↪ **c:=**
[Switch][] to s:before-attribute-value and [consume][]
* ↪ **c:/**\
↪ **c:>**\
↪ **c:{**\
↪ **[Identifier start][]**
[Switch][] to s:before-attribute
* ↪ **[Whitespace][]**
[Consume][]
* ↪ **Anything else**
[Crash][] `'after local attribute name'`
### Before attribute value state
* ↪ **c:"**
[Switch][] to s:attribute-value-double-quoted, [enter][] `'attributeValue'`,
and [consume][]
* ↪ **c:'**
[Switch][] to s:attribute-value-single-quoted, [enter][] `'attributeValue'`,
and [consume][]