Skip to content

Instantly share code, notes, and snippets.

@tabatkins
Created April 3, 2014 01:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tabatkins/9946593 to your computer and use it in GitHub Desktop.
Save tabatkins/9946593 to your computer and use it in GitHub Desktop.
Markdown BS: `<dl>` format

Similarly to Markdown ULs and OLs, the DL format is defined by grouping its items.

A DT is indicated by a line starting with a :. A DD is indicated by a line starting with a ::. As with UL/OL, you can linebreak within a block by indenting the subsequent lines, and a block can contain multiple paragraphs as long as you indent. Two blank lines, or a single blank line followed by an unindented line, ends the list.

:term
::definition
:another term
::a longer definition
    stretching over two lines
:a third term
::an even longer definition

    This definition has two paragraphs!

The DTs and DDs serve equally well to define the DL. Just like in HTML, you can have as many DTs and DDs in a sequence as you want, and you can even start a list with a DD or end with a DT (though that's not semantically meaningful...).

There are several shortcut forms to this syntax.

You can supply the DD on the same line as the DT if you end the DT with another ::

:compact DL: A DL that puts its DTs and DDs on the same line.
:long-form DL: One that puts its DDs on the following line.

You can also stack multiple DTs onto a single line by just concatenating them, wrapping each in :s on either side and separating them with whitespace:

:apple: :orange: kinds of fruit
:tomato: :zucchini: kinds of vegetables

Hm, those shortcut syntaxes are a little confusing. Maybe instead, you're just allowed to stack DT/DDs into a single line as normal?

:compact DL ::A DL that puts its DTs and DDs on the same line
:long-form DL ::One that puts its DDs on the following line
:apple :orange ::kinds of fruit
:tomato :zucchini ::kinds of vegetables

This syntax leads directly from the long-form syntax, and so is probably easier to understand.


There's also a big issue with stacking dts/dds on a single line: I had thought that any literal use of the : characters could just be escaped, but it really can't be, because it's part of common CSS syntaxes (pseudo-classes, pseudo-elements, example property: values lines).

Couple ways to address this:

  1. Drop the stacked syntaxes, so DTs and DDs are only one per line.
  2. Very carefully track when elements are opened/closed, so only top-level : characters are acted on. We'd need to be careful about the way that some of the other markup shortcuts are done - I think Markdown processing happens before any of the linking shortcuts are turned into elements.
  3. Use a more exotic character for lists (but this doesn't deal with the problem forever, and if some char is used for non-CSS stuff, it'll have the same problems).
  4. ???
@shans
Copy link

shans commented Apr 3, 2014

  1. Escape : inside definition titles as : (there's precedence for this with numbered lists).
    e.g. :width: auto: the width is calculated based on ...

  2. Escape : inside definition titles as ::
    e.g. :width:: auto: the width is calculated based on ...

@tabatkins
Copy link
Author

Hmm, on further consideration, I guess that just escaping the : is fine (your option 4). It's a little confusing, but it's also kinda rare.

It's less bad for UL/OL, because you only have to be on the watch for lines starting with the metacharacter.

@tabatkins
Copy link
Author

What do you think about the "just stack the normal syntax into one line" suggestion?

@shans
Copy link

shans commented Apr 3, 2014

I like it a lot. I might switch to it.

It also means you can do:

: this is a
multiline title
:: and its
definition

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