jgm / djot.js

JavaScript implementation of djot
MIT License
146 stars 16 forks source link

more precise type for DefinitionListItem #8

Closed matklad closed 1 year ago

matklad commented 1 year ago

It seems like the following should also in principle work:

interface Table extends HasAttributes {
  tag: "table";
  children: [Caption, ...Row[]];
}

Though, that'll require us to add an empty caption in the parser, like we already do for definition lists.

Alternatively, we can use

interface Table extends HasAttributes {
  tag: "table";
  children: [Caption?, ...Row[]];
}

Counter-intuitively, this doesn't mean that the array can start with ethire Row or Caption. Rather, it means that the first element is either Caption or underfined. This would violate the invariant that children: AstNode[], so this one definitely seems like a no-go.

jgm commented 1 year ago

Thanks, I didn't know you could do that in ts! (I guess this ts's version of a tuple type?)

I think the Row/Caption idea you suggest is probably a good idea. We could have the renderer omit the <caption> tag when the caption is empty. No harm in it showing up as a node in the AST. Do you want to do a separate PR for that?

matklad commented 1 year ago

Yeah, will look into caption later today!