Elements of a great markup language
&gt; More or less, what I want from markup is to convert a text string into a document tree:<p><pre><code>  enum Element {
    Text(String),
    Node {
      tag: String,
      attributes: Map&lt;String, String&gt;
      children: Vec&lt;Element&gt;,
    }
  }

  fn parse_markup(input: &amp;str) -&gt; Element { ... }
</code></pre>
&gt; Markup language which nails this perfectly is HTML.<p>The reason HTML nails it perfectly is because this is modeled after HTML.<p>If I were to make up a markup language, I wouldn&#x27;t follow that model.<p>In particular I would get rid of attributes which to me are a restricted kind of children with a specialized syntax.<p>This is both unnecessary and undesirable in many cases.<p>The major problem with attributes is the &lt;String, String&gt; mapping. Once something is defined to be an attribute, it cannot be sensibly extended without creating an unnecessary problem.<p>For example the `class` attribute in HTML looks like it was originally designed to hold a single class name. Then people realized that it would be desirable to have multiple classes per element.<p>So, to keep things backwards-compatible, the value of the attribute was extended to hold a space-separated list of classes instead. Essentially creating a little DSL inside of the attribute&#x27;s value.<p>If `class` was instead a kind of child, initially limited to a single instance per element, extending to multiple instances in a backward-compatible manner would not require introducing the DSL. It would be natural. Just allow many `class` children.<p>A valid argument in HTML in favor of attributes is conciseness. But that&#x27;s an artifact of the syntax.<p>We could make up a language with syntax for nodes as concise as HTML attributes, eliminating that argument.<p>&gt; It feels like there’s a smaller, simpler language somewhere<p>Certainly.<p>I have experimented with many different designs for such a markup language on top of Jevko[0]. One interesting design that trivially maps to HTML looks like this:<p><pre><code>  h1 [Title]

  p [
    paragraph
  ]

  p [
    [paragraph with a ]
    a [
      href=[...]
      [link]
    ]
  ]
</code></pre>
Another one looks like this:<p><pre><code>  [h1][Title]

  [p][paragraph]

  [p][
    paragraph with a
    [href[...] a][link]
  ]
</code></pre>
Both are extremely simple and minimal, but also extensible and lend themselves to writing by hand.<p>[0] <a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=33287620" rel="nofollow">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=33287620</a>