gettalong / kramdown

kramdown is a fast, pure Ruby Markdown superset converter, using a strict syntax definition and supporting several common extensions.
http://kramdown.gettalong.org
Other
1.72k stars 274 forks source link

Can't apply inline attribute to markdown <li> #730

Closed dabrahams closed 3 years ago

dabrahams commented 3 years ago

Say you have an <ol> ordered list of 3 items in markdown, and you want to add a .class to the middle one. There's no way to use an IAL to do that, because it has to appear on a line following the element, and that ends up breaking up the markdown into two <ol>s. Maybe there should be a rule that an IAL at the end of a line can apply to the inner block generated by that line or something.

gettalong commented 3 years ago

You mean something like this:

1. First item
2. {:.class} second item
3. Third item

Output:

<ol>
  <li>First item</li>
  <li class="class">second item</li>
  <li>Third item</li>
</ol>
dabrahams commented 3 years ago

Oh, cool; that should be documented! Now is there a way to attach attributes to the <code> tag generated for this (or heck, the <pre> tag or the inner <div> that rouge wraps it in)?

```c++
// Does the fragment get applied to pre or code?
```
gettalong commented 3 years ago

It is documented, see https://kramdown.gettalong.org/syntax.html#lists at the end of that heading, before the "Definition Lists" heading.

If you are using triple tildes for pre tags, the IAL is applied to the pre tag:

$ kramdown --syntax-highlighter nil
{:.cls}
^D
<pre class="cls"><code>
</code></pre>

If you are using a syntax highlighter, it is assigned to the outermost div tag:

$ kramdown
~~~ ruby
x = Class.new

{:.cls}

x = Class.new


In the above cases you need to use a CSS sub-selector like `.cls code` or `.cls .highlight` to process the tags you want.
dabrahams commented 3 years ago

Thanks!