Ordered lists with non-number markers

Request: Add “type” attribute of <ol> to whitelist. Suggestion to do the same with “reversed” for <ol>, and “value” for <li>, for similar but less common reasons.

Purpose: These attributes are intended for use where the marker of ordered list items itself conveys meaning to the content of the list. Typically this is the case when list items are intended to be referred to via this marker. This is in contrast to CSS list-style-type which is intended where the choice of marker carries no significant purpose. (Though I did see it recommended for forum-wide localization, which is pretty great!)

Background: While attempting to quote an official reference document, I discovered an apparent limitation in list formatting which prevents doing so accurately. Quite often, list markers are purely stylistic. However, they are occasionally used to facilitate reference in list-heavy documents. For example, in official and legal documents, a list item (or sub-item) might be referred to by list marker: “Official Document Article I, section 1(a)(i)”

For Markdown, there’s no mention in the CommonMark specification, and indeed it specifies only digits, 0-9. But while most interpreters don’t permit letters for lists(including markdown-it), a couple do:

I’m uncertain of whether a standard method is available in BBCode, to the extent anything is standard in BBCode. I was unable to find anything more advanced than starting at an arbitrary digit. BBCode list tags don’t appear used by Discourse, anyway.

With HTML and HTML+style, neither produce the correct result:

3 个赞

Looking at GitHub, implementing this would likely be simply a matter of adding them to this list:
https://github.com/discourse/discourse/blob/master/app/assets/javascripts/pretty-text/white-lister.js#L181-L183

Though I do notice that introducing these will leave the HTML-to-markdown converter unaware of these attributes. But as demonstrated above, markdown-it currently can’t handle markdown syntax representing these anyway. For that, it may be desirable to go a step further and implement list types in CommonMark…

2 个赞

There are no plans for this.

The lack of this makes it very difficult to quote official documents, legal documents, software licenses, or anything else which use non-number markers for document references.

1 个赞

Add a wrapper to those lists and some CSS

In posts use:

[wrap="letterlist"]
1. is the first
2. is the second.
3. is the third
[/wrap]

IN your theme add:

.cooked div[data-wrap="letterlist"]
  list-style: upper-alpha;
}
1 个赞

That’s a good solution if the goal is arbitrary list decorations, but the HTML type attribute is specifically meant for semantically-meaningful situations where the difference between list markers are more than decorative. From <ol>: The Ordered List element - HTML: HyperText Markup Language | MDN

Unless the type of the list number matters (like legal or technical documents where items are referenced by their number/letter), use the CSS list-style-type property instead.

It’s a common enough need that although the HTML attribute was deprecated in HTML 4.01 (with justification of it being purely stylistic), it was subsequently re-introduced in HTML5 for the specific purpose of encoding reference lists as described by MDN.

1 个赞

我尝试使用此解决方案,它有效,将 CSS 修正为以下内容(第一行缺少 ol {):

.cooked div[data-wrap="letterlist"] ol {
  list-style: upper-alpha;
}

但是,我无法在编辑器预览窗口中显示它,这对我的大多数用户来说将是一个问题。我尝试使用网络浏览器进行检查,似乎自定义 CSS 未加载或未应用于预览(我不是这方面的专业人士,所以可能错了)。

您能想到任何解决此问题的方法吗,@Falco

1 个赞

我相信现在已支持 HTML:

  1. This thing
  2. Another thing
  3. Something else
<ol type="A">
<li>This thing
<li>Another thing
<li>Something else
</ol>

以及类型 AaIi

还有 reversedstart=

  1. Bread
  2. Chips
  3. Watermelon
<ol reversed start=36>
<li>Bread
<li>Chips
<li>Watermelon
</ol>

看起来像这样使用 HTML 会禁用 <li> 中的 Markdown 解析,所以我不能真正将其提供给用户。

1 个赞

为了在其中使用其他格式,我认为您也必须使用 HTML 版本,因为它不喜欢混合使用:

  1. Bread
  2. Chips
  3. Watermelon
<ol reversed start=36>
<li> <b>Bread</b>
<li> <i>Chips</i>
<li> <strike>Watermelon</strike>
</ol>

我知道。正如我所说,我认为向我的用户提出这个建议是不可接受的——这完全改变了标记,仅仅因为你想要一个略有不同的列表。

抱歉,这对您来说不是一个可行的选项。

也许您可以在 Dev 主题中发帖求助,询问如何调整现有解决方案,或许有人能帮到您。 :+1:

1 个赞