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

Commit

Permalink
Merge pull request #174 from plotly/moz-update-jan-2021
Browse files Browse the repository at this point in the history
Update component gen process for recent MDN changes
  • Loading branch information
alexcjohnson committed Jan 7, 2021
2 parents 2b9df15 + 08c4ce1 commit b02c657
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
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.
// 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

0 comments on commit b02c657

Please sign in to comment.