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
|
Attributes have the following syntax:
attributes <- '{' whitespace* attribute (whitespace attribute)*
whitespace* '}'
attribute <- id_attribute | class_attribute | kv_attribute
id_attribute <- '#' letter (alphanum | '-' | '_' | ':' | '.')*
class_attribute <- '.' letter (alphanum | '-' | '_')*
kv_attribute <- attrname '=' attrvalue
attrname <- (asciiletter | '_' | ':')
(asciialphanum | '_' | '.' | '-' | ':')*
attrvalue <- unquotedvalue | quotedvalue
unquotedvalue <- [^"-=<>`:whitespace:]+
quotedvalue <- '"' ([^"] | '\' '"')* '"'
**Attributes that occur at the end of the text of
a Setext or ATX heading (separated by whitespace
from the text) affect the heading element.**
```````````````````````````````` example
# Heading {#ident .class key="value value" key2=value2}
.
<h1 id="ident" class="class" data-key="value value" data-key2="value2">Heading</h1>
````````````````````````````````
```````````````````````````````` example
Heading {#ident .class key="value"}
=====
.
<h1 id="ident" class="class" data-key="value">Heading</h1>
````````````````````````````````
Whitespace is tolerated around the delimiters:
```````````````````````````````` example
# Heading { #ident .class key="value" }
.
<h1 id="ident" class="class" data-key="value">Heading</h1>
````````````````````````````````
Multiple class attributes are combined:
```````````````````````````````` example
# Heading {.class1 .class2 class="class3"}
.
<h1 class="class1 class2 class3">Heading</h1>
````````````````````````````````
Only the last id attribute is used:
```````````````````````````````` example
# Heading {#id1 #id2 id="id3"}
.
<h1 id="id3">Heading</h1>
````````````````````````````````
Heading attributes can be followed by whitespace, but
otherwise must come at the end of the line.
```````````````````````````````` example
# Foo {#bar}
.
<h1 id="bar">Foo</h1>
````````````````````````````````
Headings should still work without attributes:
```````````````````````````````` example
# ATX
Setext
------
.
<h1>ATX</h1>
<h2>Setext</h2>
````````````````````````````````
**Attributes that occur after the opening fence
in a fenced code block affect the code block element.**
```````````````````````````````` example
``` {#ident .class key="value value" key2=value2}
xyz
```
.
<pre id="ident" class="class" data-key="value value" data-key2="value2"><code>xyz
</code></pre>
````````````````````````````````
```````````````````````````````` example
~~~~{#mycode .ruby .number-lines}
xyz
~~~~
.
<pre id="mycode" class="ruby number-lines"><code>xyz
</code></pre>
````````````````````````````````
If any non-space content comes after the attribute spec, the
whole thing is treated as a raw info string.
```````````````````````````````` example
``` {#foo} bar
xyz
```
.
<pre><code class="language-{#foo}">xyz
</code></pre>
````````````````````````````````
Here the attribute spec is at the end, so the
first word provides the info string and the rest is
treated as an attribute.
```````````````````````````````` example
``` bar {#foo}
xyz
```
.
<pre id="foo"><code class="language-bar">xyz
</code></pre>
````````````````````````````````
**Attributes on inline elements must immediately follow the element to
which they belong.** If they follow a space, then they belong
to the space.
```````````````````````````````` example
`hi`{#ident .class key=value}
.
<p><code id="ident" class="class" data-key="value">hi</code></p>
````````````````````````````````
```````````````````````````````` example
`hi` {#ident .class key=value}
.
<p><code>hi</code><span id="ident" class="class" data-key="value"> </span></p>
````````````````````````````````
The attributes can wrap:
```````````````````````````````` example
`hi`{#ident .class
key=value}
.
<p><code id="ident" class="class" data-key="value">hi</code></p>
````````````````````````````````
**Attributes that occur immediately before a block
element, on a line by themselves, affect that
element.**
```````````````````````````````` example
{.special}
* * * *
.
<hr class="special" />
````````````````````````````````
```````````````````````````````` example
{#foo .special}
bar
.
<p id="foo" class="special">bar</p>
````````````````````````````````
```````````````````````````````` example
{#foo .special}
# Hi
.
<h1 id="foo" class="special">Hi</h1>
````````````````````````````````
When conflicting specifications of the same attribute are given,
the last one takes precedence, except for classes, which are
cumulative.
```````````````````````````````` example
{#id1}
{#id2}
# Heading {#id3}
.
<h1 id="id3">Heading</h1>
````````````````````````````````
```````````````````````````````` example
{#id1}
{#id3}
# Heading
.
<h1 id="id3">Heading</h1>
````````````````````````````````
```````````````````````````````` example
{.class1 k=1}
{.class2 .class3 k=2}
# Heading {.class4}
.
<h1 class="class1 class2 class3 class4" data-k="2">Heading</h1>
````````````````````````````````
**Attributes that occur at the end of a reference
link definition affect links that refer to that
definition.**
```````````````````````````````` example
[foo]
[foo]: bar "title" {#ident .centered .big}
.
<p><a id="ident" class="centered big" href="bar" title="title">foo</a></p>
````````````````````````````````
**Attributes that occur immediately after an inline
element affect that element.**
```````````````````````````````` example
[foo](bar){#ident .class key="value value" key2=value2}
.
<p><a id="ident" class="class" data-key="value value" data-key2="value2" href="bar">foo</a></p>
````````````````````````````````
```````````````````````````````` example
{#ident .centered .big}
.
<p><img id="ident" class="centered big" src="bar" alt="foo" /></p>
````````````````````````````````
```````````````````````````````` example
[foo]{#ident .centered .big}
[foo]: bar
.
<p><a id="ident" class="centered big" href="bar">foo</a></p>
````````````````````````````````
```````````````````````````````` example
*hi*{.underline}
.
<p><em class="underline">hi</em></p>
````````````````````````````````
**Consecutive attribute specifiers may be used,
either for blocks or for inlines.**
```````````````````````````````` example
*hi*{.underline}{#foo}
.
<p><em class="underline" id="foo">hi</em></p>
````````````````````````````````
```````````````````````````````` example
{.special}
{#foo}
* * * *
.
<hr class="special" id="foo" />
````````````````````````````````
**Entities can be used in attribute values.**
```````````````````````````````` example
# Heading {key="value" }
.
<h1 data-key="value">Heading</h1>
````````````````````````````````
|