From b6a7eea5edacb73af77a457055bab81d6e93387c Mon Sep 17 00:00:00 2001 From: "Michael[tm] Smith" Date: Sat, 29 Aug 2020 19:20:57 +0900 Subject: [PATCH] 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));