Skip to content
This repository was archived by the owner on Jun 4, 2024. It is now read-only.

Update component gen process for recent MDN changes #174

Merged
merged 3 commits into from
Jan 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion scripts/extract-attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ const attributeMap = supportedAttributes.reduce((map, reactAttribute) => {
* descriptions and supported elements.
*/
function extractAttributes($) {
const $table = $('#Attribute_list').parent().find('table');
const $table = $('#Attribute_list,#attribute_list').parent().find('table');
if($table.length !== 1) {
throw new Error('page structure changed at ' + htmlURL);
}
Expand Down
11 changes: 11 additions & 0 deletions scripts/extract-elements.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,18 @@ const request = require('request');

const refUrl = 'https://developer.mozilla.org/en-US/docs/Web/HTML/Element';
const dataPath = './data/elements.txt';
const expectedElCount = 131;

/**
* From the MDN HTML elements reference, extract a list of elements.
*/
function extractElements($) {
const excludeElements = [
'html', 'head', 'body', 'style', 'h1–h6', 'input',
// out of scope, different namespaces - but Mozilla added these to the
// above reference page Jan 2021 so we need to exclude them now.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perhaps reference the MDN PR that changed this for posterity? mdn/content#410

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah nice, I didn't think to look for where this was introduced!

// see https://github.com/mdn/content/pull/410
'svg', 'math',
// obsolete, non-standard, or deprecated tags
'image', 'dir', 'tt', 'applet', 'noembed', 'bgsound', 'menu', 'menuitem',
'noframes'
Expand Down Expand Up @@ -56,6 +61,12 @@ request(refUrl, (error, response, html) => {
}
const $ = cheerio.load(html);
const elements = extractElements($);
if (elements.length !== expectedElCount) {
throw new Error(
'Unexpected number of elements extracted from ' + refUrl +
' Check the output and edit expectedElCount if this is intended.'
);
}
const out = elements.join('\n');

fs.writeFileSync(dataPath, out);
Expand Down