News for hackers. Stuff that matters.
Re:Show HN: Embed HN comments in your website by bambax on Tuesday November 08, 2016 @07:49AM (#12899778)
This looks good.

Minor gripe: not sure if it's a good idea that the network be an attribute name instead of an attribute value; to this:

    <comment-box hackernews="11850599" limit="1" class="border"></comment-box>
I would prefer:

    <comment-box network="hackernews" items="11850599" limit="1" class="border"></comment-box>
If you have a different attribute name per network, the DTD changes every time you add a network. Not that anyone cares, but still.

- - -

Edit: a previous version of this comment asked why the tag was not self-closing; in fact, custom elements in HTML5 should indeed have a closing tag; see

http://stackoverflow.com/questions/23961178/do-custom-elemen...

Re:Show HN: Embed HN comments in your website by franciscop on Tuesday November 08, 2016 @11:14AM (#12901399)
That's an interesting idea, but since we have to manually add each network and then it's automatically parsed from that list, at least on my end it wouldn't make any difference at all. Also one of the main features is that you can mix different networks and different threads per network, so that would be really confusing: what does this mean?

    <comment-box network="hackernews reddit" items="11850599 11850500 11859454"></comment-box>
For the Edit: I searched this thorough, custom elements cannot be self-closing. And the closest thing that I found indicates that, even if they could be self-closing (void elements), then they cannot have anything inside (which is also not what I wanted).

See example:

https://jsfiddle.net/franciscop/eo5v6ghc/

Re:Show HN: Embed HN comments in your website by bambax on Tuesday November 08, 2016 @12:13PM (#12901993)
> on my end it wouldn't make any difference at all

Sure, but attribute (or tag) names refer the the structure of the document whereas values refer to each special case; structurally (essentially) those two are the same:

    <comment-box hackernews="1">
    <comment-box reddit="4">
but you can't tell because they have different attributes.

Okay, so in order to write (current solution):

    <comment-box hackernews="11850599" reddit="11850500 11859454"></comment-box>
you could do:

    <comment-box network="hackernews" items="11850599"></comment-box>
    <comment-box network="reddit" items="11850500 11859454"></comment-box>
which would work just the same, you just have to group consecutive comment-box into one; or you could even do this:

    <comment-box sources="hackernews: 11850599; reddit: 11850500 11859454"></comment-box>
(inline css style).
Re:Show HN: Embed HN comments in your website by bambax on Tuesday November 08, 2016 @12:23PM (#12902088)
The last example of my previous comment is a little ugly; in "real" XML we would write:

    <comment-box>
      <source name="hackernews" items="12"/>
      <source name="reddit" items="24 27"/>
      </comment-box>
which would be very readable; but since we don't have self-closing tags and we need to use hyphens in tag names, it's probably defensible to try to limit the number of tags and put as much information as possible inside attributes...
Re:Show HN: Embed HN comments in your website by franciscop on Tuesday November 08, 2016 @12:52PM (#12902367)
Totally agree about your conclusion (:

I think that's the same as with the modern <picture> and <video>. I recently tried something similar but in "traditional" html structure, but also found it a bit too verbose for my taste:

https://medium.com/@fpresencia/leveraging-modern-apis-a13fa6...

Re:Show HN: Embed HN comments in your website by jffry on Tuesday November 08, 2016 @08:26AM (#12900000)
I'm not sure that you can have self-closing custom tags in HTML5. Per [1],

  ...if the element is one of the void elements,
  or if the element is a foreign element, then
  there may be a single U+002F SOLIDUS
  character (/). This character has no effect
  on void elements, but on foreign elements
  it marks the start tag as self-closing.
The list of element types [2] is fairly short, so I think if you attempted to self-close a custom tag, behavior might depend on how the parser's error recovery treats custom elements.

[1] http://w3c.github.io/html/syntax.html#start-tags

[2] http://w3c.github.io/html/syntax.html#writing-html-documents...

Re:Show HN: Embed HN comments in your website by bambax on Tuesday November 08, 2016 @08:36AM (#12900066)
You're right it seems! I have edited my comment to reflect this.

(Why would HTML5 have both self-closing and non-self closing tags though?? It's just a syntax shortcut, they should either take it or leave it, but create a special class of "empty tags" seems crazy to me).

Re:Show HN: Embed HN comments in your website by andrewstuart2 on Tuesday November 08, 2016 @09:46AM (#12900618)
Except that the whole promise of XML and DTD is that you can have validated serialization of your objects. If the network is switched to an attribute name with a string value, it can no longer be validated that you've chosen a valid network, unless you use an enumeration (in which case you've still changed the DTD).
Re:Show HN: Embed HN comments in your website by bambax on Tuesday November 08, 2016 @12:16PM (#12902017)
Yes, if you use an enumeration you do change the DTD each time you add a network, but not the structure of the element. It's not the same error and it doesn't tell you the same thing.

It's obviously not very important... I can't seem to be able to put into words why it bothers me so much! ;-)

Re:Show HN: Embed HN comments in your website by Navarr on Tuesday November 08, 2016 @08:54AM (#12900205)
I think keeping the network as an attribute name would allow it to do multiple networks in one box in the future.
Re:Show HN: Embed HN comments in your website by franciscop on Tuesday November 08, 2016 @11:17AM (#12901433)
Not future, you can already do it:

https://jsfiddle.net/franciscop/eo5v6ghc/