Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I don't know if there's a proper name for this ability, but neither JSON nor YAML allow you to embed child tree nodes inside of node values. This ability requires named end tags. Example:

    <p>This is <b>bold</b> text.</p>
    "p": "This is ... uh ... nevermind."
You could make a compelling argument that you shouldn't do this (separate block level and inline elements into separate encodings), but remember that even the relatively minor HTML->XHTML movement to put a bit of sanity into single-use tags like <br> -> <br/> failed miserably.


Nodes have multiple children. In this case, you can split the <p>'s children into three: a "text node"; a <b> node; and another text node. You'd end up with something like this:

    {
      p: [
        { text: 'This is' },
        { b: { text: 'bold' }},
        { text: 'text.'}
      ]
    }
Not that I don't agree with you -- my suggestion is pretty messy and doesn't even go into how we'd deal with tag attributes -- but it's doable.


This has to be pre-processed somehow, if people don't like writing HTML by hand, consider writing that.


Yeah, and that's not really equivalent HTML either. That's more like:

    <p>
      <text>This is</text>
      <b><text>bold</text></b>
      <text>text.</text>
    </p>
(which is a lot easier for a machine to parse, at least.)

JSON and YAML are great for what they do: data serialization, but they're just not appropriate choices for text markup. You have to use the right tool for the job.

There was a time when the industry wanted to cram 100% of everything into XML, and that gave us XSLT, XAML, SOAP, etc. We don't want to go back to that, either.

Personally, I'm most fond of an extended Markdown syntax to replace HTML. But I'm not going to hold my breath waiting on web browser vendors to agree on such a syntax, so instead I have my HTTP server do the conversion to HTML for me.

But if you had to force it into JSON, then I would suggest using a different markup for inline elements, eg:

    html
      body
        p: "This is [/italic/] text."
        p: "This is [[google.com => a hyperlink.]]"




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: