Skip to content

Commit

Permalink
Clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
tolyo committed Nov 21, 2023
1 parent 921bd57 commit 5242e9c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 32 deletions.
14 changes: 0 additions & 14 deletions generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,9 @@ const fs = require("fs");
"wbr",
];

// Launch the Chromium browser
const browser = await chromium.launch();

// Create a new browser context
const context = await browser.newContext();

// Create an array to store the extracted elements
const extractedElements = [];

// Create a page and navigate to the URL
const page = await context.newPage();
await page.goto("https://html.spec.whatwg.org/multipage/indices.html");

Expand All @@ -37,13 +30,9 @@ const fs = require("fs");

if (rows.length > 0) {
console.log("Number of rows in the table:", rows.length);

// You can iterate through each row if needed
for (const row of rows) {
// Select the first <code> element within the row's <th>
const codeElements = await row.$$("th code a");
if (codeElements.length > 0) {
// Loop through each code element and extract its text content
for (const codeElement of codeElements) {
const elementText = await codeElement.textContent();
console.log("Element in the row:", elementText);
Expand All @@ -56,10 +45,7 @@ const fs = require("fs");
} else {
console.log("No rows found in the table.");
}

// Write the extracted elements to a text file
const outputFilePath = "lib/nitroux/html_tags.ex";
// Wrap the element with some text (e.g., "Element: ")
const wrappedElement = `
defmodule Nitroux.HtmlTags do
Expand Down
23 changes: 5 additions & 18 deletions generator/global-attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,23 @@
const fs = require("fs");

/**
* Represents global attribute.
* @typedef {Object} GlobalAttribute
* @property {string} name - The name of the attribute ('translate').
* @property {string} description - A description of the attribute's purpose and usage.
* @property {string} ty - Bool or String.
*/

// Specify the path to your JSON file
const filePath = "html/resources/manual/global_attributes.json";

/**
* @type {GlobalAttribute[]}
*/
let attributeList = [];

// Read the JSON file
fs.readFile(filePath, "utf8", (err, data) => {
if (err) {
console.error(`Error reading file: ${err}`);
return;
}
try {
attributeList = JSON.parse(data);
// Write the extracted elements to a text file
const outputFilePath = "lib/nitroux/types/global_attributes.ex";
// Wrap the element with some text (e.g., "Element: ")
const wrappedElement = `
fs.readFile(filePath, "utf8", (_err, data) => {
attributeList = JSON.parse(data);
const outputFilePath = "lib/nitroux/types/global_attributes.ex";
const wrappedElement = `
defmodule Nitroux.Types.GlobalAttributes do
# AUTO GENERATED DO NOT EDIT
Expand All @@ -55,8 +45,5 @@ fs.readFile(filePath, "utf8", (err, data) => {
.join("\n")}
end
`;
fs.writeFileSync(outputFilePath, wrappedElement);
} catch (error) {
console.error(`Error parsing JSON: ${error}`);
}
fs.writeFileSync(outputFilePath, wrappedElement);
});

0 comments on commit 5242e9c

Please sign in to comment.