Skip to content

Attributes Extension

Vladimir Schneider edited this page Sep 6, 2019 · 5 revisions

Converts attributes {...} syntax set HTML attributes for immediately preceding sibling element during HTML rendering.

  • Simplified rules with No plain text attributes selected

    Applied to the preceding element, if that element is plain text then attributes are applied to the parent element of the text.

    If the attributes element is the first element of a paragraph then the attributes will be applied to the paragraph's parent element. Effectively putting attributes element first in a paragraph allows you to set the attributes of list items, block quotes or other paragraph containers.

  • Default Extended Behavior, No plain text attributes not selected:

    If an attribute element is spaced from the previous plain text element some text {attributes} then attributes are for the parent of the text. If they are attached to the text element some text{attributes} then they are assigned to the immediately preceding plain text span.

    Within an inline element same rules apply: **bold text {attr}** are for the strong emphasis span, while **bold text{attr}** will wrap the text between the strong emphasis tags, in a span with given attributes.

    If a plain text span is interrupted by an HTML comment then it is considered as two separate plain text spans. ie. some <!---->text{attr} will result in some <!----><span attr>text</span> rendering.

The attributes is a space separated list of attribute syntax of one of the following:

  • name=value
  • name='value'
  • name="value"
  • #id
  • .class

Attribute which starts with # such as #id-string is equivalent to id="id-string" and .class-name are equivalent to class="class-name"

ℹ️ Handling of multiple value assignment for attributes depends on its name:

  • class values are accumulated as a space ( ) separated list.
  • style values are accumulated as a semicolon (;) separated list.
  • all others override any previous values of the same name.

ℹ️ For fenced code elements, only attributes elements at the end of the info string line will be parsed.

For example:

```info {#not-id} not {title="Title" caption="Cap"} {caption="Caption"}

```

The {#not-id} is not parsed as attributes because it is followed non-attributes element and will result in the following HTML:

<pre title="Title" caption="Caption"><code class="language-info">
</code></pre>