-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
use named exports for source-html and provide hooks to run the script…
…s via npm run
- Loading branch information
Showing
123 changed files
with
1,728 additions
and
2,357 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
66 changes: 0 additions & 66 deletions
66
packages/@atjson/source-html/scripts/generate-annotation-names.js
This file was deleted.
Oops, something went wrong.
76 changes: 76 additions & 0 deletions
76
packages/@atjson/source-html/scripts/generate-annotation-names.ts
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,76 @@ | ||
import { writeFileSync } from "fs"; | ||
import { join } from "path"; | ||
import * as puppeteer from "puppeteer"; | ||
|
||
function classify(name: string) { | ||
return name[0].toUpperCase() + name.slice(1); | ||
} | ||
|
||
(async () => { | ||
const browser = await puppeteer.launch(); | ||
const page = await browser.newPage(); | ||
|
||
await page.goto("https://html.spec.whatwg.org/multipage/semantics.html"); | ||
|
||
let names: { [tagName: string]: string } = {}; | ||
|
||
while (true) { | ||
let sectionNumber = await page.$$eval(".secno", elements => { | ||
return elements[0] ? (elements[0] as HTMLSpanElement).innerText : "4"; | ||
}); | ||
if (!sectionNumber.match(/^4/)) break; | ||
|
||
let hasSections = (await page.$$("h4")).length > 0; | ||
if (!hasSections) { | ||
await page.$eval("nav a:last-child", link => | ||
(link as HTMLAnchorElement).click() | ||
); | ||
} | ||
|
||
// Grab all element definitions, and begin to | ||
// parse and create annotation definitions for each one | ||
let headings = await page.$$("h4"); | ||
|
||
for (let heading of headings) { | ||
let isElementDefinition = await heading.$("dfn code"); | ||
if (!isElementDefinition) continue; | ||
|
||
let id = await page.evaluate(element => element.id, heading); | ||
|
||
// Multiple HTML elements are sometimes defined per section, like `sub` and `sup`. | ||
let types = await heading.$$eval("dfn code", nodes => | ||
nodes.map(node => (node as HTMLElement).innerText) | ||
); | ||
|
||
// Find the Interface Definition Language class name for this element, | ||
// and use that if it's defined. | ||
let idlName = await page.evaluate(elementId => { | ||
let element = document.getElementById(elementId)!.nextElementSibling; | ||
let interfaceName = element | ||
? element.querySelector("code.idl dfn c-") | ||
: null; | ||
if (interfaceName) { | ||
let domClassName = (interfaceName as HTMLElement).innerText; | ||
return domClassName.replace(/^HTML(.*)Element$/, "$1"); | ||
} | ||
return null; | ||
}, id); | ||
|
||
types.forEach(type => { | ||
names[type] = idlName || classify(type); | ||
}); | ||
} | ||
|
||
// Next Section | ||
await page.$eval("nav a:last-child", link => | ||
(link as HTMLAnchorElement).click() | ||
); | ||
} | ||
|
||
writeFileSync( | ||
join(__dirname, "class-names-2.json"), | ||
JSON.stringify(names, null, 2) | ||
); | ||
|
||
browser.close(); | ||
})(); |
185 changes: 0 additions & 185 deletions
185
packages/@atjson/source-html/scripts/generate-annotations.js
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.