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/tree/master/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 05e77f9
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Currently:
* Strip out unused references
* Spec splitting
* Add caniuse.com annotations
* Add output for `<wpt>` elements
* Add syntax-highlighting markup to `<pre>` contents

## Wattsi Syntax
Expand Down
71 changes: 71 additions & 0 deletions src/wattsi.pas
Original file line number Diff line number Diff line change
Expand Up @@ -1848,6 +1848,39 @@ procedure Save(const Document: TDocument; const FileName: AnsiString; const InSp
Write(F, HTMLFragment);
end;

procedure InsertWPTTestsBlock(const Element: TElement);
var
WPTPaths, WPTOutput: TStrings;
WPTPath, WPTSubPath, WPTFilename: String;
WPTPathPrefix: String = '/html/';
begin
if (InSplit) then
exit;
if (Element.HasAttribute('pathprefix')) then
WPTPathPrefix := Trim(Element.GetAttribute('pathprefix').AsString);
WPTOutput := TStringList.Create;
WPTOutput.Add('<ul class=wpt-tests-block>');
WPTPaths := TStringList.Create;
WPTPaths.Text := Element.TextContent.AsString;
for WPTSubPath in WPTPaths do
begin
if (Trim(WPTSubPath) = '') then
continue;
WPTPath := WPTPathPrefix + 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 +1973,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 +2029,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 +2051,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);
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 05e77f9

Please sign in to comment.