Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support dfn types short syntax, "for", (no)export #134

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 78 additions & 0 deletions src/wattsi.pas
Original file line number Diff line number Diff line change
Expand Up @@ -1091,6 +1091,55 @@ TCrossReferences = record
const
CommitSnapshotBaseURL: AnsiString = '/commit-snapshots/';
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';
// 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;
Expand All @@ -1104,6 +1153,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 +1449,34 @@ 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;
if (Element.HasAttribute(kNoExport)) then
begin
Element.SetAttribute(kDataNoExport, '');
Element.RemoveAttribute(kNoExport);
end;
for DFNType in kDFNTypes do
if (Element.HasAttribute(DFnType)) then
begin
Element.SetAttribute(kDataDFNType, DFNType);
Element.RemoveAttribute(DFnType);
end;
if (Element.HasAttribute(kDataDFNType)
and Element.HasAttribute(kDataExport)) then
begin
Fail('<dfn> found with dfn type name and redundant'
+ ' export attribute; dfn is ' + Describe(Element));
end;
CrossReferenceName := GetTopicIdentifier(Element);
if (Assigned(InDFN)) then
Fail('Nested <dfn>: ' + Describe(Element));
Expand Down