Support the <slot> tag (#848)

* Support the <slot> tag

<slot> was added to the WHATWG HTML5 Living Standard on April 20, 2016.

* Also support the slot= attribute

Given that the <slot> tag by itself is not too useful, this commit also
introduces support for the global slot attribute.

* Using ParseBlock for <slot>

This is still suboptimal since ParseBlock will make it so that <slot>
always expects "Flow content", whereas the spec says that it should
have a Transparent content model.

In practice, it should allow all the cases that the spec allows for, but
it will also allow some cases that the spec does not allow. Notably, if
a <slot> tag is found in a Phrasing content (an inline context in
libtidy lingo), it will wrongly let Flow content (block tags in libtidy
lingo), whereas it shouldn't. But all in all, it's a good compromise.
This commit is contained in:
lhchavez 2020-11-21 07:31:28 -08:00 committed by GitHub
parent 188988022d
commit e51cd17c2d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 19 additions and 0 deletions

View File

@ -988,6 +988,7 @@ typedef enum
TidyTag_OUTPUT, /**< OUTPUT */
TidyTag_PROGRESS, /**< PROGRESS */
TidyTag_SECTION, /**< SECTION */
TidyTag_SLOT, /**< SLOT */
TidyTag_SOURCE, /**< SOURCE */
TidyTag_SUMMARY, /**< SUMMARY */
TidyTag_TEMPLATE, /**< TEMPLATE */
@ -1143,6 +1144,7 @@ typedef enum
TidyAttr_SHOWGRIDX, /**< SHOWGRIDX= */
TidyAttr_SHOWGRIDY, /**< SHOWGRIDY= */
TidyAttr_SIZE, /**< SIZE= */
TidyAttr_SLOT, /**< SLOT= */
TidyAttr_SPAN, /**< SPAN= */
TidyAttr_SRC, /**< SRC= */
TidyAttr_SRCSET, /**< SRCSET= (HTML5) */

View File

@ -95,6 +95,7 @@
{ TidyAttr_IS, xxxx|xxxx|xxxx|xxxx|xxxx|xxxx|xxxx|xxxx|xxxx|xxxx|xxxx|xxxx|xxxx|HT50|XH50 }, \
{ TidyAttr_LANG, xxxx|xxxx|xxxx|xxxx|xxxx|xxxx|xxxx|xxxx|xxxx|xxxx|xxxx|xxxx|xxxx|HT50|XH50 }, \
{ TidyAttr_ROLE, xxxx|xxxx|xxxx|xxxx|xxxx|xxxx|xxxx|xxxx|xxxx|xxxx|xxxx|xxxx|xxxx|HT50|XH50 }, \
{ TidyAttr_SLOT, xxxx|xxxx|xxxx|xxxx|xxxx|xxxx|xxxx|xxxx|xxxx|xxxx|xxxx|xxxx|xxxx|HT50|XH50 }, \
{ TidyAttr_SPELLCHECK, xxxx|xxxx|xxxx|xxxx|xxxx|xxxx|xxxx|xxxx|xxxx|xxxx|xxxx|xxxx|xxxx|HT50|XH50 }, \
{ TidyAttr_STYLE, xxxx|xxxx|xxxx|xxxx|xxxx|xxxx|xxxx|xxxx|xxxx|xxxx|xxxx|xxxx|xxxx|HT50|XH50 }, \
{ TidyAttr_TABINDEX, xxxx|xxxx|xxxx|xxxx|xxxx|xxxx|xxxx|xxxx|xxxx|xxxx|xxxx|xxxx|xxxx|HT50|XH50 }, \
@ -2880,6 +2881,17 @@ const AttrVersion TY_(W3CAttrsFor_SMALL)[] =
{ TidyAttr_UNKNOWN, 0 },
};
const AttrVersion TY_(W3CAttrsFor_SLOT)[] =
{
INCLUDE_ARIA
INCLUDE_MICRODATA
{ TidyAttr_NAME, xxxx|xxxx|xxxx|xxxx|xxxx|xxxx|xxxx|xxxx|xxxx|xxxx|xxxx|xxxx|xxxx|HT50|XH50 },
INCLUDE_CORE_ATTRIBS
INCLUDE_CORE_EVENTS
INCLUDE_RDFA
{ TidyAttr_UNKNOWN, 0 },
};
const AttrVersion TY_(W3CAttrsFor_SOURCE)[] =
{
INCLUDE_ARIA

View File

@ -142,6 +142,7 @@ extern const AttrVersion TY_(W3CAttrsFor_OUTPUT)[];
extern const AttrVersion TY_(W3CAttrsFor_MENUITEM)[];
extern const AttrVersion TY_(W3CAttrsFor_METER)[];
extern const AttrVersion TY_(W3CAttrsFor_PROGRESS)[];
extern const AttrVersion TY_(W3CAttrsFor_SLOT)[];
extern const AttrVersion TY_(W3CAttrsFor_TEMPLATE)[];
extern const AttrVersion TY_(W3CAttrsFor_TIME)[];
extern const AttrVersion TY_(W3CAttrsFor_DATA)[];

View File

@ -238,6 +238,7 @@ static const Attribute attribute_defs [] =
{ TidyAttr_SHOWGRIDX, "showgridx", CH_BOOL }, /* TABLE Adobe golive*/
{ TidyAttr_SHOWGRIDY, "showgridy", CH_BOOL }, /* TABLE Adobe golive*/
{ TidyAttr_SIZE, "size", CH_NUMBER }, /* HR, FONT, BASEFONT, SELECT */
{ TidyAttr_SLOT, "slot", CH_PCDATA },
{ TidyAttr_SPAN, "span", CH_NUMBER }, /* COL, COLGROUP */
{ TidyAttr_SRC, "src", CH_URL }, /* IMG, FRAME, IFRAME */
{ TidyAttr_SRCSET, "srcset", CH_PCDATA }, /* IMG (HTML5) */

View File

@ -315,6 +315,7 @@ Bool TY_(AttributeIsMismatched)(Node* node, AttVal* attval, TidyDocImpl* doc);
#define attrIsSHOWGRIDX(av) AttrIsId( av, TidyAttr_SHOWGRIDX )
#define attrIsSHOWGRIDY(av) AttrIsId( av, TidyAttr_SHOWGRIDY )
#define attrIsSIZE(av) AttrIsId( av, TidyAttr_SIZE )
#define attrIsSLOT(av) AttrIsId( av, TidyAttr_SLOT )
#define attrIsSPAN(av) AttrIsId( av, TidyAttr_SPAN )
#define attrIsSRC(av) AttrIsId( av, TidyAttr_SRC )
#define attrIsSTANDBY(av) AttrIsId( av, TidyAttr_STANDBY )

View File

@ -151,6 +151,7 @@ static CheckAttribs CheckHTML;
#define VERS_ELEM_OUTPUT (xxxx|xxxx|xxxx|xxxx|xxxx|xxxx|xxxx|xxxx|xxxx|xxxx|xxxx|xxxx|xxxx|HT50|XH50)
#define VERS_ELEM_PROGRESS (xxxx|xxxx|xxxx|xxxx|xxxx|xxxx|xxxx|xxxx|xxxx|xxxx|xxxx|xxxx|xxxx|HT50|XH50)
#define VERS_ELEM_SECTION (xxxx|xxxx|xxxx|xxxx|xxxx|xxxx|xxxx|xxxx|xxxx|xxxx|xxxx|xxxx|xxxx|HT50|XH50)
#define VERS_ELEM_SLOT (xxxx|xxxx|xxxx|xxxx|xxxx|xxxx|xxxx|xxxx|xxxx|xxxx|xxxx|xxxx|xxxx|HT50|XH50)
#define VERS_ELEM_SOURCE (xxxx|xxxx|xxxx|xxxx|xxxx|xxxx|xxxx|xxxx|xxxx|xxxx|xxxx|xxxx|xxxx|HT50|XH50)
#define VERS_ELEM_SUMMARY (xxxx|xxxx|xxxx|xxxx|xxxx|xxxx|xxxx|xxxx|xxxx|xxxx|xxxx|xxxx|xxxx|HT50|XH50)
#define VERS_ELEM_TEMPLATE (xxxx|xxxx|xxxx|xxxx|xxxx|xxxx|xxxx|xxxx|xxxx|xxxx|xxxx|xxxx|xxxx|HT50|XH50)
@ -321,6 +322,7 @@ static Dict tag_defs[] =
{ TidyTag_OUTPUT, "output", VERS_ELEM_OUTPUT, &TY_(W3CAttrsFor_OUTPUT)[0], (CM_INLINE), TY_(ParseInline), NULL },
{ TidyTag_PROGRESS, "progress", VERS_ELEM_PROGRESS, &TY_(W3CAttrsFor_PROGRESS)[0], (CM_INLINE), TY_(ParseInline), NULL },
{ TidyTag_SECTION, "section", VERS_ELEM_SECTION, &TY_(W3CAttrsFor_SECTION)[0], (CM_BLOCK), TY_(ParseBlock), NULL },
{ TidyTag_SLOT, "slot", VERS_ELEM_SLOT, &TY_(W3CAttrsFor_SLOT)[0], (CM_BLOCK|CM_INLINE|CM_MIXED), TY_(ParseBlock), NULL },
{ TidyTag_SOURCE, "source", VERS_ELEM_SOURCE, &TY_(W3CAttrsFor_SOURCE)[0], (CM_BLOCK|CM_INLINE|CM_EMPTY), TY_(ParseBlock), NULL },
{ TidyTag_SUMMARY, "summary", VERS_ELEM_SUMMARY, &TY_(W3CAttrsFor_SUMMARY)[0], (CM_BLOCK), TY_(ParseBlock), NULL }, /* Is. #895 */
{ TidyTag_TEMPLATE, "template", VERS_ELEM_TEMPLATE, &TY_(W3CAttrsFor_TEMPLATE)[0], (CM_BLOCK), TY_(ParseBlock), NULL },