-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a Specifications macro and extract a special specification sectio…
…n to the Document (mdn#3518) * Prototype spec section from BCD spec_urls * Address some feedback, mostly rename things * Branch out building special sections in their own functions per Ryuno-Ki * Add a KumaScript test * Add extraction test * Add browser-specs data; update tests; update renderer * feedback on pr 3518 * Remove log calls, fix tests * Rename SpecificationTable to SpecificationSection/Specifications * Update browser-specs to latest * Add specfications to makeTOC * Move spec-section to ingredients * Remove comment Co-authored-by: Peter Bengtsson <[email protected]>
- Loading branch information
Showing
10 changed files
with
365 additions
and
95 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { DisplayH2, DisplayH3 } from "./utils"; | ||
|
||
export function SpecificationSection({ | ||
id, | ||
title, | ||
isH3, | ||
specifications, | ||
query, | ||
}: { | ||
id: string; | ||
title: string; | ||
isH3: boolean; | ||
specifications: Array<{ | ||
title: string; | ||
bcdSpecificationURL: string; | ||
shortTitle: string; | ||
}>; | ||
query: string; | ||
}) { | ||
return ( | ||
<> | ||
{title && !isH3 && <DisplayH2 id={id} title={title} />} | ||
{title && isH3 && <DisplayH3 id={id} title={title} />} | ||
|
||
{specifications.length > 0 ? ( | ||
<table className="standard-table"> | ||
<thead> | ||
<tr> | ||
<th scope="col">Specification</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
{specifications.map((spec) => ( | ||
<tr key={spec.bcdSpecificationURL}> | ||
<td> | ||
<a href={spec.bcdSpecificationURL}> | ||
{spec.title} ({spec.shortTitle}) | ||
<br />{" "} | ||
<small>#{spec.bcdSpecificationURL.split("#")[1]}</small> | ||
</a> | ||
</td> | ||
</tr> | ||
))} | ||
</tbody> | ||
</table> | ||
) : ( | ||
<div className="notecard warning"> | ||
<h4>No specification found</h4> | ||
<p> | ||
No specification data found for <code>{query}</code>.<br /> | ||
<a href="#on-github">Check for problems with this page</a> or | ||
contribute a missing <code>spec_url</code> to{" "} | ||
<a href="https://github.com/mdn/browser-compat-data"> | ||
mdn/browser-compat-data | ||
</a> | ||
. Also make sure the specification is included in{" "} | ||
<a href="https://github.com/w3c/browser-specs">w3c/browser-specs</a> | ||
. | ||
</p> | ||
</div> | ||
)} | ||
</> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<% | ||
/* | ||
Placeholder to render a specification section with spec_urls from BCD | ||
Parameters | ||
$0 – A query string indicating for which feature to retrieve specification URLs for. | ||
Example calls | ||
{{Specifications}} | ||
{{Specifications("html.element.abbr")}} | ||
*/ | ||
var query = $0 || env['browser-compat']; | ||
if (!query) { | ||
throw new Error("No first query argument or 'browser-compat' front-matter value passed"); | ||
} | ||
var output = `<div class="bc-specs" data-bcd-query="${query}"> | ||
If you're able to see this, something went wrong on this page. | ||
</div>`; | ||
%> | ||
|
||
<%-output%> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
const { assert, itMacro, describeMacro, lintHTML } = require("./utils"); | ||
|
||
const jsdom = require("jsdom"); | ||
const { JSDOM } = jsdom; | ||
|
||
describeMacro("Specifications", function () { | ||
itMacro("Outputs a simple div tag", async (macro) => { | ||
const result = await macro.call("api.feature"); | ||
const dom = JSDOM.fragment(result); | ||
assert.equal( | ||
dom.querySelector("div.bc-specs").dataset.bcdQuery, | ||
"api.feature" | ||
); | ||
assert.equal( | ||
dom.querySelector("div.bc-specs").textContent.trim(), | ||
"If you're able to see this, something went wrong on this page." | ||
); | ||
}); | ||
|
||
itMacro("Outputs valid HTML", async (macro) => { | ||
const result = await macro.call("api.feature"); | ||
expect(lintHTML(result)).toBeFalsy(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
testing/content/files/en-us/web/spec_section_extraction/index.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
--- | ||
title: Spec section extraction | ||
browser-compat: javascript.builtins.Array.toLocaleString | ||
slug: Web/Spec_Section_Extraction | ||
--- | ||
|
||
<h2>Intro</h2> | ||
<p>Text in Intro</p> | ||
|
||
<h2 id="Specifications">Specifications</h2> | ||
|
||
<p>{{Specifications}}</p> | ||
|
||
<h2 id="Browser_compatibility">Browser compatibility</h2> | ||
|
||
<p>{{Compat}}</p> | ||
|
||
<h2 id="See_also">See also</h2> | ||
|
||
<p>More stuff</p> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters