Skip to content

Proposal for syntax for attributes on list items#262

Open
tmke8 wants to merge 2 commits into
jgm:mainfrom
tmke8:patch-1
Open

Proposal for syntax for attributes on list items#262
tmke8 wants to merge 2 commits into
jgm:mainfrom
tmke8:patch-1

Conversation

@tmke8

@tmke8 tmke8 commented Dec 15, 2023

Copy link
Copy Markdown

As previously discussed in #185

I'm not sure what the process is for a syntax change, so I'm just starting it by adding a description to syntax.md.

If you do like this syntax, I'm guessing I would

Rendered docs:

image

@dereuromark

Copy link
Copy Markdown
Contributor

I like it. Is this repo still maintained? There wasnt any feedback so far on it.

@jgm

jgm commented Nov 27, 2025

Copy link
Copy Markdown
Owner

It's a natural idea. I just haven't had bandwidth for this recently.

dereuromark added a commit to php-collective/djot-php that referenced this pull request Nov 28, 2025
List items can now have attributes on the following line at content indent:

```djot
- item 1
  {.highlight #id1}
- item 2
  {data-value="test"}
```

Renders as:
```html
<li class="highlight" id="id1">item 1</li>
<li data-value="test">item 2</li>
```

Works with:
- Unordered lists
- Ordered lists
- Task lists

Related: jgm/djot#262

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
dereuromark added a commit to php-collective/djot-php that referenced this pull request Nov 28, 2025
List items can now have attributes on the following line at content indent:

```djot
- item 1
  {.highlight #id1}
- item 2
  {data-value="test"}
```

Renders as:
```html
<li class="highlight" id="id1">item 1</li>
<li data-value="test">item 2</li>
```

Works with:
- Unordered lists
- Ordered lists
- Task lists

Related: jgm/djot#262

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude <noreply@anthropic.com>
@dereuromark

dereuromark commented Dec 3, 2025

Copy link
Copy Markdown
Contributor

The single space making the different of item vs content can be maybe for some a bit misleading.

I propose to have this appending the item:

- item 1
  {.highlight #id1}
- item 2
  {data-value="test"}

Refs demo implementation @ php-collective/djot-php#5

This would also be consistent with sub-elements in general (e.g. DL and DD):
https://php-collective.github.io/djot-php/reference/enhancements#list-item-attributes

Comment thread doc/syntax.md
To attach attributes to a list item, the curly braces must immediately
follow the list marker:

+{.blue} A blue list item.

@Omikhleia Omikhleia Jan 14, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the expected interpretation for the marker? How does one apply attributes on a given list marker only?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess directly attaching is also fine from parser rules. And would probably make sense.
But if you look at my implementation (and the linked docs examples), you will see that it improves human readability if in this case those are put into the item as appended new line.
And I think one important goal is the readability for humans in the end, in this case the "list" itself.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I'd be fine with that.

@tmke8 tmke8 May 19, 2026

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe open a new spec PR with your proposed syntax? Then it's easier to compare and discuss.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have plenty of open PRs that got almost no review or even any initial minimal feedback.
I would like to first see the maintainer(s) chiming in giving their 5 cents, before I would open up any spec + reference impl PR.

@jgm

jgm commented May 20, 2026

Copy link
Copy Markdown
Owner

I'm a bit undecided, but leaning towards the original proposal (attributes immediately after the list marker): it just seems a bit more obvious in that case that the attribute is meant to apply to the list item.

@dereuromark

Copy link
Copy Markdown
Contributor

Thinking about this more I also are in favor of this solution here, my implemented approach fails on certain elements inside the content then, or at least isn't able to do it in all cases.
So the proposed here is the clean approach 👍

dereuromark added a commit to php-collective/djot-php that referenced this pull request Jun 11, 2026
Support the djot proposal jgm/djot#262: attributes in curly braces that
immediately follow a list marker (no space before the brace) attach to the
<li> element, e.g.

    +{.blue} A blue list item.
    (a){.bar} Ordered list item with an attribute.
    1.{data-value="test"} Numbered item with a data attribute.

Works across every marker type (bullet, ordered numeric, parenthesized,
roman, alpha, and task lists). A space before the brace keeps the old
meaning, the {...} is item content and acts as a block attribute for the
following block inside the item.

The previous separate-indented-line form is soft-deprecated but still
attaches to the <li> for back-compat; marker attributes seed the item and
the separate-line form merges on top.

Also teach the opt-in blocksInterruptParagraphs mode to recognize the
attributed markers so they interrupt an open paragraph just like the plain
markers do.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants