-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate-docs.js
More file actions
56 lines (43 loc) · 1.5 KB
/
generate-docs.js
File metadata and controls
56 lines (43 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
const fs = require("fs");
// Path to your CSS file
const cssFilePath = "./css/flexistyles.css";
// Read the CSS file synchronously
try {
const cssText = fs.readFileSync(cssFilePath, "utf8");
const classes = extractCSSClasses(cssText);
classes.sort((a, b) => a.className.localeCompare(b.className));
const markdownTable = generateMarkdownTable(classes);
// Write the Markdown table to the output file
fs.writeFileSync("./list-of-classes.md", markdownTable, "utf8");
console.log(`Markdown table written to ${outputFilePath}`);
} catch (error) {
console.error("Error reading CSS file:", error.message);
}
function extractCSSClasses(cssText) {
const classes = [];
// Regular expression to match CSS class names and their properties
const classRegex = /\.([^\s{]+)\s*{([^}]*)}/g;
let match;
while ((match = classRegex.exec(cssText)) !== null) {
const className = match[1].trim();
const classProperties = match[2]
.split(";")
.map((property) => property.trim())
.filter(Boolean);
classes.push({
className: className,
content: classProperties,
});
}
return classes;
}
function generateMarkdownTable(classes) {
let markdownTable = "| Class Name | Class Contents |\n";
markdownTable += "|------------|----------------|\n";
for (const classData of classes) {
const className = classData.className;
const classContents = classData.content.join("<br>");
markdownTable += `| ${className} | ${classContents} |\n`;
}
return markdownTable;
}