Skip to content

Commit

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

Specifically, 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, https://wpt.fyi and https://web-platform-tests.live URLs for the listed tests.

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

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

- Doesn’t 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 authored and domenic committed Oct 21, 2018
1 parent 9101e2c commit 1512df5
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Currently:
* Check for missing references
* Spec splitting
* Add caniuse.com annotations
* Add output for `<wpt>` elements
* Add syntax-highlighting markup to `<pre>` contents

## Wattsi Syntax
Expand Down
50 changes: 50 additions & 0 deletions src/wattsi.pas
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@

var
HighlighterOutputByJSONContents: TStringMap;
CurrentVariant: TAllVariants;

const
kSuffixes: array[TVariants] of UTF8String = ('html', 'dev', 'snap', 'review');
Expand Down Expand Up @@ -1862,6 +1863,46 @@ 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, WPTLiveURLScheme, WPTFilename: String;
WPTPathPrefix: String = '/html/';
begin
if ((CurrentVariant = vDev) or (CurrentVariant = vReview)) then
exit;
if (Element.HasAttribute('pathprefix')) then
WPTPathPrefix := Trim(Element.GetAttribute('pathprefix').AsString);
WPTOutput := TStringList.Create;
WPTOutput.Add('<div class=wpt-tests-margin>');
WPTOutput.Add('<input onclick="toggleStatus(this)" value="⋰" type="button">');
WPTOutput.Add('<dl>');
WPTPaths := TStringList.Create;
WPTPaths.Text := Element.TextContent.AsString;
for WPTSubPath in WPTPaths do
begin
WPTLiveURLScheme := 'http';
if (Trim(WPTSubPath) = '') then
continue;
WPTPath := WPTPathPrefix + Trim(WPTSubPath);
WPTFilename := ExtractFileName(WPTPath);
if (AnsiContainsStr(WPTFilename, '.https.')
or AnsiContainsStr(WPTFilename, '.serviceworker.')) then
WPTLiveURLScheme := 'https';
WPTOutput.Add('<dt>');
WPTOutput.Add('<a title="' + WPTFilename + '"'
+ ' href="https://wpt.fyi/results'
+ WPTPath + '">' + WPTFilename + '</a></dt>');
WPTOutput.Add('<dd><a href="' + WPTLiveURLScheme + '://web-platform-tests.live'
+ WPTPath + '">(live test)</a>');
WPTOutput.Add(' <a href="https://github.com/web-platform-tests/wpt/blob/master'
+ WPTPath + '">(source)</a></dd>');
end;
WPTOutput.Add('</dl>');
WPTOutput.Add('</div>');
Write(F, WPTOutput.Text);
end;

procedure WalkIn(const Element: TElement);
var
IsExcluder, Skip, NotFirstAttribute: Boolean;
Expand Down Expand Up @@ -1954,6 +1995,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 @@ -2029,6 +2072,12 @@ procedure Save(const Document: TDocument; const FileName: AnsiString; const InSp
if (Current is TElement) then
begin
Element := TElement(Current);
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 Expand Up @@ -2684,6 +2733,7 @@ function Main(): Boolean;
begin
for Variant in TVariants do
begin
CurrentVariant := Variant;
if (Variant = vReview) then
begin
continue;
Expand Down

0 comments on commit 1512df5

Please sign in to comment.