Skip to content

Commit

Permalink
Support dfn types short syntax, "for", (no)export
Browse files Browse the repository at this point in the history
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 whatwg/html#5694
  • Loading branch information
sideshowbarker committed Sep 15, 2020
1 parent f2fd135 commit b6a7eea
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/wattsi.pas
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -1399,6 +1413,23 @@ TCrossReferences = record
begin
if (Element.HasAttribute(kLTAttribute)) then
Fail('<dfn> 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 <dfn>: ' + Describe(Element));
Expand Down

0 comments on commit b6a7eea

Please sign in to comment.