From 9accf9d74c0228bc476c1c2a4683b74e07bbe01c Mon Sep 17 00:00:00 2001 From: "Michael[tm] Smith" Date: Sat, 29 Aug 2020 19:20:57 +0900 Subject: [PATCH 1/4] Support dfn types short syntax, "for", (no)export This change adds support for doing the following with attributes of dfn elements: * recognize attributes with names that are known dfn types (currently, 'element', 'element-attr', 'event', 'interface', 'extended-attribute', 'method', 'attribute', 'enum-value', and 'http-header'), and replace them with data-dfn-type=element, etc., attributes in output * for any dfn element that has an attribute named "for", replace it in output with an attribute named "data-dfn-for" * for any dfn element with an attribute named "export" or "noexport", replace it with one named "data-export" or "data-noexport" Relates to https://github.com/whatwg/html/pull/5694/ --- src/wattsi.pas | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/wattsi.pas b/src/wattsi.pas index db68c8a..533ac1a 100644 --- a/src/wattsi.pas +++ b/src/wattsi.pas @@ -1091,6 +1091,19 @@ TCrossReferences = record const CommitSnapshotBaseURL: AnsiString = '/commit-snapshots/'; SourceGitBaseURL: AnsiString = 'https://github.com/whatwg/html/commit/'; + kExport = 'export'; + kDataExport = 'data-export'; + kFor = 'for'; + kDataDFNFor = 'data-dfn-for'; + kDataDFNType = 'data-dfn-type'; + // NOTE: The following array has the subset of dfn types we actually use + // in HTML currently. The full set of ~40 supported dfn types is at + // https://github.com/tabatkins/bikeshed/blob/master/bikeshed/config/dfnTypes.py#L7 + // So if we ever start using any types other than the following in HTML, + // then at that time we will also need to update this array. + kDFNTypes: array[1..9] of UTF8String = + ('element', 'element-attr', 'event', 'interface', 'extended-attribute', + 'method', 'attribute', 'enum-value', 'http-header'); var CandidateChild, SelectedForTransfer: TNode; CurrentHeadingRank: THeadingRank; @@ -1104,6 +1117,7 @@ TCrossReferences = record DFNEntry: TDFNEntry; ID, HeadingText, ParentHeadingText, SectionNumber, ParentSectionNumber: UTF8String; ClassValue: String = ''; + DFNType: UTF8String = ''; begin Result := True; if (Node is TElement) then @@ -1399,6 +1413,23 @@ TCrossReferences = record begin if (Element.HasAttribute(kLTAttribute)) then Fail(' with lt="" found, use data-x="" instead; dfn is ' + Describe(Element)); + if (Element.HasAttribute(kFor)) then + begin + ExtractedData := Element.GetAttribute(kFor); + Element.SetAttributeDestructively(kDataDFNFor, ExtractedData); + Element.RemoveAttribute(kFor); + end; + if (Element.HasAttribute(kExport)) then + begin + Element.SetAttribute(kDataExport, ''); + Element.RemoveAttribute(kExport); + end; + for DFNType in kDFNTypes do + if (Element.HasAttribute(DFnType)) then + begin + Element.SetAttribute(kDataDFNType, DFNType); + Element.RemoveAttribute(DFnType); + end; CrossReferenceName := GetTopicIdentifier(Element); if (Assigned(InDFN)) then Fail('Nested : ' + Describe(Element)); From 31418945df840bfa333f12a38c9dd8e84c068f39 Mon Sep 17 00:00:00 2001 From: "Michael[tm] Smith" Date: Mon, 7 Sep 2020 16:38:05 +0900 Subject: [PATCH 2/4] Actually replace "data-noexport" with "noexport" ...because this got overlooked in the previous commit. --- src/wattsi.pas | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/wattsi.pas b/src/wattsi.pas index 533ac1a..7ed78b7 100644 --- a/src/wattsi.pas +++ b/src/wattsi.pas @@ -1093,6 +1093,8 @@ TCrossReferences = record SourceGitBaseURL: AnsiString = 'https://github.com/whatwg/html/commit/'; kExport = 'export'; kDataExport = 'data-export'; + kNoExport = 'noexport'; + kDataNoExport = 'data-noexport'; kFor = 'for'; kDataDFNFor = 'data-dfn-for'; kDataDFNType = 'data-dfn-type'; @@ -1424,6 +1426,11 @@ TCrossReferences = record Element.SetAttribute(kDataExport, ''); Element.RemoveAttribute(kExport); end; + if (Element.HasAttribute(kNoExport)) then + begin + Element.SetAttribute(kDataNoExport, ''); + Element.RemoveAttribute(kNoExport); + end; for DFNType in kDFNTypes do if (Element.HasAttribute(DFnType)) then begin From cb15645bb3eda4fb23c2ad522b2c8dac61efdf4c Mon Sep 17 00:00:00 2001 From: "Michael[tm] Smith" Date: Mon, 7 Sep 2020 16:39:07 +0900 Subject: [PATCH 3/4] Fail with an error if export used w/ dfn type This change causes Wattsi to fail with an error message if a dfn that has a type name is found to also have an export attribute. --- src/wattsi.pas | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/wattsi.pas b/src/wattsi.pas index 7ed78b7..cb2bde0 100644 --- a/src/wattsi.pas +++ b/src/wattsi.pas @@ -1437,6 +1437,12 @@ TCrossReferences = record Element.SetAttribute(kDataDFNType, DFNType); Element.RemoveAttribute(DFnType); end; + if (Element.HasAttribute(kDataDFNType) + and Element.HasAttribute(kDataExport)) then + begin + Fail(' found with dfn type name and redundant' + + ' export attribute; dfn is ' + Describe(Element)); + end; CrossReferenceName := GetTopicIdentifier(Element); if (Assigned(InDFN)) then Fail('Nested : ' + Describe(Element)); From 385c4e048ce02819a1bf0e4b5dba19836ce4e41e Mon Sep 17 00:00:00 2001 From: "Michael[tm] Smith" Date: Mon, 7 Sep 2020 18:37:14 +0900 Subject: [PATCH 4/4] Recognize all dfn types (not just a subset) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This change makes Wattsi recognize the full set of 40 dfn types from https://github.com/tabatkins/bikeshed/blob/master/bikeshed/config/dfnTypes.py#L7 — rather than just the subset of 9 types the initial code recognized. Two dfn types that are used in HTML but that weren’t part of that initial subset (and that therefore weren’t getting converted as expected) are “attr-value” and “constructor”. --- src/wattsi.pas | 50 ++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 42 insertions(+), 8 deletions(-) diff --git a/src/wattsi.pas b/src/wattsi.pas index cb2bde0..07ccf9e 100644 --- a/src/wattsi.pas +++ b/src/wattsi.pas @@ -1098,14 +1098,48 @@ TCrossReferences = record kFor = 'for'; kDataDFNFor = 'data-dfn-for'; kDataDFNType = 'data-dfn-type'; - // NOTE: The following array has the subset of dfn types we actually use - // in HTML currently. The full set of ~40 supported dfn types is at - // https://github.com/tabatkins/bikeshed/blob/master/bikeshed/config/dfnTypes.py#L7 - // So if we ever start using any types other than the following in HTML, - // then at that time we will also need to update this array. - kDFNTypes: array[1..9] of UTF8String = - ('element', 'element-attr', 'event', 'interface', 'extended-attribute', - 'method', 'attribute', 'enum-value', 'http-header'); + // From https://github.com/tabatkins/bikeshed/blob/master/bikeshed/config/dfnTypes.py#L7 + kDFNTypes: array[1..40] of UTF8String = + ('abstract-op', + 'property', + 'value', + 'at-rule', + 'descriptor', + 'type', + 'function', + 'selector', + 'element', + 'element-attr', + 'attr-value', + 'element-state', + 'event', + 'interface', + 'namespace', + 'extended-attribute', + 'constructor', + 'method', + 'argument', + 'attribute', + 'callback', + 'dictionary', + 'dict-member', + 'enum', + 'enum-value', + 'exception', + 'const', + 'typedef', + 'stringifier', + 'serializer', + 'iterator', + 'maplike', + 'setlike', + 'grammar', + 'scheme', + 'state', + 'mode', + 'context', + 'facet', + 'http-header'); var CandidateChild, SelectedForTransfer: TNode; CurrentHeadingRank: THeadingRank;