Is there a way to add an attribute to the list (ol,ul)?
I can't figure out the syntax for adding an attribute to the entire list rather than a list element. Is that supported by the attributes extension? I can add attributes to each list item but I'm unable to figure out how to do it for the containing list.
Hi Alex,
I just tested this within our product (which is using flexmark). It is not so nice, but this seems to work:
Markdown source:
* {title="Tool tipp"} one
* two
* three
Resulting in HTML:
<ul title="Tool tipp">
<li>one</li>
<li>two</li>
<li>three</li>
</ul>
I think I tried almost that with no space before the attribute (and many other combinations), but not exactly that… Thanks! -Alex
On Feb 6, 2023, at 8:10 AM, Alexander Krapf @.***> wrote:
Since not all HTML elements are in the markdown, attribute extension has a few quirks to allow assigning attributes to these invisible elements. From the test spec file for the attributes extension https://github.com/vsch/flexmark-java/blob/master/flexmark-ext-attributes/src/test/resources/ext_attributes_ast_spec.md link to this file is in the extensions wiki, under Attributes https://github.com/vsch/flexmark-java/wiki/Extensions#attributes
Actual test for lists on line 464:
Cond 3.1
Cond 3.1 attributes go to the paragraph parent's parent
attributes are assigned to the list element
```````````````````````````````` example No Previous Sibling - Cond 3.1: 1
* {.red} list item 1
* list item 2
* list item 1
* {.red} list item 2
.
<ul class="red">
<li>
<p>list item 1</p>
</li>
<li>
<p>list item 2</p>
</li>
<li>
<p>list item 1</p>
</li>
<li>
<p>list item 2</p>
</li>
</ul>
.
Document[0, 70]
BulletList[0, 70] isLoose
BulletListItem[0, 21] open:[0, 1, "*"] isLoose
Paragraph[2, 21]
AttributesNode[2, 8] textOpen:[2, 3, "{"] text:[3, 7, ".red"] textClose:[7, 8, "}"]
AttributeNode[3, 7] name:[3, 4, "."] value:[4, 7, "red"] isImplicit isClass
Text[9, 20] chars:[9, 20, "list … tem 1"]
BulletListItem[21, 35] open:[21, 22, "*"] isLoose hadBlankLineAfter
Paragraph[23, 35] isTrailingBlankLine
Text[23, 34] chars:[23, 34, "list … tem 2"]
BulletListItem[36, 50] open:[36, 37, "*"] isLoose
Paragraph[38, 50]
Text[38, 49] chars:[38, 49, "list … tem 1"]
BulletListItem[50, 70] open:[50, 51, "*"] isLoose
Paragraph[52, 70]
AttributesNode[52, 58] textOpen:[52, 53, "{"] text:[53, 57, ".red"] textClose:[57, 58, "}"]
AttributeNode[53, 57] name:[53, 54, "."] value:[54, 57, "red"] isImplicit isClass
Text[59, 70] chars:[59, 70, "list … tem 2"]
````````````````````````````````
From the top of the spec test file description:
Attributes
Converts attributes {...} syntax into attributes AST nodes and adds an attribute provider to
set attributes for preceding node based on attribute assignment rules.
The attributes is a space separated list of attribute syntax of one of the following:
-
attr=value -
attr='value' -
attr="value" -
#anchor: equivalent toid="anchor" -
.class-name: equivalent toclass="class-name"
NOTE: Handling of multiple value assignment for attributes depends on its name:
-
classvalues are accumulated as a space () separated list. -
stylevalues are accumulated as a semicolon (;) separated list. - all others override any previous values of the same name.
The goal for this extension is to give maximum flexibility of assigning attributes to any element in the markdown hierarchy in an intuitive manner so the target of the assignment can be determined at a glance.
The attributes are used with a postfix notation, where they define the attributes for preceding element in the document.
The following terms are used in the specification of rules for determining the attribute owner:
previous sibling : a markdown element preceding the element within its parent element's child list
no previous sibling : a markdown element which is first within its parent element's child list
next sibling : a markdown element following the element within its parent element's child list
no next sibling : a markdown element which is last within its parent element's child list
paragraph item container : a markdown element which is an item in a parent list element. In
which case the first child paragraph is considered the item's text container and not a regular
paragraph. eg. ListItem, DefinitionItem, Footnote
text element : markdown element representing a contiguous span of undecorated plain text uninterrupted by any other markdown element.
anchor target node : any node which can contain an id or name attribute and be a target of
an anchor reference in a link and naturally will compute its own id absent one being
explicitly assigned. eg. Heading
attached attributes attributes are attached : attributes element without intervening white space between it and its previous sibling is said to be attached to its previous sibling.
unattached attributes attributes are not attached attributes are unattached : attributes element with intervening white space between it and its previous sibling is said to be unattached.
There are two modes of attribute assignment determination for text nodes:
Text Node Previous Sibling
Assignment of attributes to text elements is determined by the boolean extension option
ASSIGN_TEXT_ATTRIBUTES, by default true.
For the rest of the specification the options following the example will contain:
no-text-attributes if ASSIGN_TEXT_ATTRIBUTES is false, and true otherwise.
- if text assignment is false
- Cond 1.1 attributes are assigned to the parent of attributes element.
- else
- if attributes are attached to the previous sibling
- Cond 1.2 attributes are assigned to the text element
- else
- Cond 1.3 attributes are assigned to the text element
- if attributes are attached to the previous sibling
To allow greater control of attribute assignment it is possible to set
USE_EMPTY_IMPLICIT_AS_SPAN_DELIMITER to true, will treat {.} or {#} as markers for start
of closest matching attributes node to give greater control of where attributes are attached in
text.
NOTE: If ASSIGN_TEXT_ATTRIBUTES is set to false then
USE_EMPTY_IMPLICIT_AS_SPAN_DELIMITER option is ignored.