Skip to content

Commit

Permalink
Add support for the <wpt> element
Browse files Browse the repository at this point in the history
This change adds initial support for the `<wpt>` element, as documented
at https://tabatkins.github.io/bikeshed/#wpt-element) and discussed at
speced/bikeshed#1116.

This change causes lists of tests in `<wpt>` elements from the source to
generate TESTS sections in the spec output, with links to corresponding
https://github.com/web-platform-tests/wpt, http://web-platform-tests.live,
and https://wpt.fyi URLs for the listed tests.

The change doesn’t provide the following `<wpt>`-related features:

  - Doesn’t yet verify that each test listed in a `<wpt>` element
    actually exists in https://github.com/web-platform-tests/wpt/

  - Doesn’t yet verify that every single test file that exists in the
    https://github.com/web-platform-tests/wpt/html tree is listed in a
    `<wpt>` element somewhere in the spec source.

Fixes #87
  • Loading branch information
sideshowbarker committed Aug 26, 2018
1 parent 179af60 commit 2807eff
Showing 1 changed file with 70 additions and 0 deletions.
70 changes: 70 additions & 0 deletions src/wattsi.pas
Original file line number Diff line number Diff line change
Expand Up @@ -1848,6 +1848,38 @@ procedure Save(const Document: TDocument; const FileName: AnsiString; const InSp
Write(F, HTMLFragment);
end;

procedure InsertWPTTestsBlock(const WPTContents: String);
var
WPTPaths, WPTOutput: TStrings;
WPTPath, WPTSubPath, WPTFilename: String;
const
kWPTPathPrefix = '/html/';
begin
if (InSplit) then
exit;
WPTOutput := TStringList.Create;
WPTOutput.Add('<ul class=wpt-tests-block>');
WPTPaths := TStringList.Create;
WPTPaths.Text := WPTContents;
for WPTSubPath in WPTPaths do
begin
if (Trim(WPTSubPath) = '') then
continue;
WPTPath := kWPTPathPrefix + Trim(WPTSubPath);
WPTFilename := ExtractFileName(WPTPath);
WPTOutput.Add('<li class=wpt-test>');
WPTOutput.Add('<a href="https://wpt.fyi/results'
+ WPTPath + '">' + WPTFilename + '</a>');
WPTOutput.Add('<a href="http://web-platform-tests.live'
+ WPTPath + '"><small>(live test)</small></a>');
WPTOutput.Add('<a href="https://github.com/web-platform-tests/wpt/blob/master/'
+ WPTPath + '"><small>(source)</small></a>');
WPTOutput.Add('</li>');
end;
WPTOutput.Add('</ul>');
Write(F, WPTOutput.Text);
end;

procedure WalkIn(const Element: TElement);
var
IsExcluder, Skip, NotFirstAttribute: Boolean;
Expand Down Expand Up @@ -1940,6 +1972,8 @@ procedure Save(const Document: TDocument; const FileName: AnsiString; const InSp
// behind the (now-empty) pre parents of the <code class="idl"> elements.
if Element.IsIdentity(nsHTML, ePre) and (Element.TextContent.AsString = '') then
exit;
if (Element.LocalName.AsString = 'wpt') then
exit;
if (InSplit and Element.HasAttribute(kExcludingAttribute[vSplit])) then
exit;
IsExcluder := DetermineIsExcluder(Element, AttributeCount);
Expand Down Expand Up @@ -1994,6 +2028,7 @@ procedure Save(const Document: TDocument; const FileName: AnsiString; const InSp
Current: TNode;
ClassValue: String = '';
Element: TElement;
Style: TElement;
begin
Assign(F, FileName);
Rewrite(F);
Expand All @@ -2015,6 +2050,41 @@ procedure Save(const Document: TDocument; const FileName: AnsiString; const InSp
if (Current is TElement) then
begin
Element := TElement(Current);
// TODO: Move the styles below to https://resources.whatwg.org/spec.css or
// https://resources.whatwg.org/standard.css and remove the following
// before merging this patch.
if (Element.IsIdentity(nsHTML, eHead)) then
begin
Style := E(eStyle,
[T(
'.wpt-tests-block {'
+ ' list-style: none;'
+ ' border-left: .5em solid hsl(290, 70%, 60%);'
+ ' background: hsl(290, 70%, 95%);'
+ ' margin: 1em auto;'
+ ' padding: .5em;'
+ ' display: grid;'
+ ' grid-template-columns: 1fr auto auto;'
+ ' grid-column-gap: .5em;'
+ '}'
+ '.wpt-tests-block::before {'
+ ' content: "Tests";'
+ ' grid-column: 1/-1;'
+ ' color: hsl(290, 70%, 30%);'
+ ' text-transform: uppercase;'
+ '}'
+ '.wpt-test {'
+ ' display: contents;'
+ '}'
)]);
Element.AppendChild(Style);
end;
if (Element.LocalName.AsString = 'wpt') then
begin
InsertWPTTestsBlock(Element.TextContent.AsString);
WalkToNextSkippingChildren(Current, Document, @WalkOut);
continue;
end;
if (Element.HasAttribute('class')) then
ClassValue := Element.GetAttribute('class').AsString;
if (IsHighlighterTarget(Element, ClassValue)) then
Expand Down

0 comments on commit 2807eff

Please sign in to comment.