Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Native support for indents #8751

Open
GermanJablo opened this issue Jan 19, 2023 · 3 comments
Open

Native support for indents #8751

GermanJablo opened this issue Jan 19, 2023 · 3 comments

Comments

@GermanJablo
Copy link

GermanJablo commented Jan 19, 2023

I would like to propose that HTML natively supports indents. Although I'm thinking that it could be used in tags like headings or paragraphs, an important point of the suggestion is that they could be used in li tags without requiring ul or ol wrapping.

This would simplify browsers' implementation of the execCommand API, as well as text editors.

But there are other reasons:

Nested lists are problematic. The execCommand API outputs incorrect HTML when indenting.[1]
Fixing that would not be possible even by changing the API, at least satisfactorily, since it would make it so that if one wanted to indent a li two or more times against its parent, the prefixes for nested lists (1.1, 1.2 [...] ) would be incorrect.[2]

The concept of nesting may make sense when considering that each nesting always increases a single level of depth, but what happens in real life is that an item can be 2 or more levels deep compared to the previous item; in which case it makes more sense to use a flat model.

Related discussions:
[1] #5567
[2] facebook/lexical#2951

@Jamesernator
Copy link

execCommand API, as well as text editors.

The execCommand API is very historical and is known to be not a very good API. Due to it's age though is a good chance changes to it would be a breaking change (even in spite of the quirks).

There is a proposal for improving editing behaviour although no browsers seem to have indicated an intent to take on the proposal yet. Though with such an API you could just generate <ul> nesting yourself by responding to the appropriate edit events.

@acywatson
Copy link

acywatson commented Jan 25, 2023

Though with such an API you could just generate <ul> nesting yourself by responding to the appropriate edit events.

The problem is that the the HTML spec itself doesn't provide a canonical way to represent list items that are indented multiple levels. So even if you were to generate ul nesting yourself, you couldn't do it in a way that would be semantically correct and function in sane way in modern browsers.

@RokeJulianLockhart
Copy link

RokeJulianLockhart commented Feb 22, 2025

#8751 (comment)

@GermanJablo, I've wanted this for a long time, because:

  1. It would allow me to stop wrapping my <h[1-6]>s in <li>s to demonstrate hierarchy using indentation, since that method breaks list-style: outside;.
  2. That method renders multi-line CommonMark unreadable (due to it not supporting source indentation inside HTML tags).

I think of it like YAML – specifically, HTML currently supports:

  1. Heading:
    Content
    Heading:
    Content
  2. Heading:
    - Heading:
      Content
    - Heading:
      Content

Adding what this issue proposes would also provide the undermentioned:

Heading:
Content
  Heading:
  Content
  Heading:
  Content
Heading:
Content

Example

This matters when you have a situation like:

Heading:
Content
- Heading:
  Content
  - Heading:
    Content
- Content
- Content

...because it can be replaced with:

Heading:
  Content
  Heading:
    Content
    Heading:
      Content
  - Content
  - Content

...ensuring that headings remain separate from lists that are unrelated.

We've always had this functionality available to us in text/plain files. It's a real regression that something as versatile as HTML doesn't provide this without the user having to create an unsemantic div class in CSS3 that inherently can't gracefully regress to pure HTML.

I've seen ol and ul used as a replacement, due to most default stylesheets indenting them if they have list-style: outside; set (since they should solely ever contain lis).

Would you propose that this be implemented with an <indent> tag (or another mechanism)?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

4 participants