From 05e77f93b45d0929baca3e60fc89cd6a6b59f4c3 Mon Sep 17 00:00:00 2001 From: "Michael[tm] Smith" Date: Sun, 26 Aug 2018 18:36:48 +0900 Subject: [PATCH] Add support for the element MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This change adds initial support for the `` element, as documented at https://tabatkins.github.io/bikeshed/#wpt-element) and discussed at https://github.com/tabatkins/bikeshed/issues/1116. This change causes lists of tests in `` 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 ``-related features: - Doesn’t yet verify that each test listed in a `` 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 `` element somewhere in the spec source. Fixes https://github.com/whatwg/wattsi/issues/87 --- README.md | 1 + src/wattsi.pas | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+) diff --git a/README.md b/README.md index 4ba71b2..68663fd 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,7 @@ Currently: * Strip out unused references * Spec splitting * Add caniuse.com annotations + * Add output for `` elements * Add syntax-highlighting markup to `
` contents
 
 ## Wattsi Syntax
diff --git a/src/wattsi.pas b/src/wattsi.pas
index 16f053e..3913671 100644
--- a/src/wattsi.pas
+++ b/src/wattsi.pas
@@ -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('
    '); + 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('
  • '); + WPTOutput.Add('' + WPTFilename + ''); + WPTOutput.Add('(live test)'); + WPTOutput.Add('(source)'); + WPTOutput.Add('
  • '); + end; + WPTOutput.Add('
'); + Write(F, WPTOutput.Text); + end; + procedure WalkIn(const Element: TElement); var IsExcluder, Skip, NotFirstAttribute: Boolean; @@ -1940,6 +1973,8 @@ procedure Save(const Document: TDocument; const FileName: AnsiString; const InSp // behind the (now-empty) pre parents of the 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); @@ -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); @@ -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