-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconvert.js
More file actions
27 lines (19 loc) · 1.04 KB
/
Copy pathconvert.js
File metadata and controls
27 lines (19 loc) · 1.04 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
const fs = require('fs');
function convertHtmlToJsx(htmlFile, outputFile) {
let html = fs.readFileSync(htmlFile, 'utf8');
// Extract body content
const bodyMatch = html.match(/<body[^>]*>([\s\S]*?)<\/body>/i);
if (!bodyMatch) return;
let jsx = bodyMatch[1];
// Convert attributes
jsx = jsx.replace(/class="/g, 'className="');
jsx = jsx.replace(/for="/g, 'htmlFor="');
jsx = jsx.replace(/<!--[\s\S]*?-->/g, ''); // Remove comments
// Close self-closing tags
jsx = jsx.replace(/<(img|input|hr|br|meta|link)([^>]*?)(?!\/)> /g, '<$1$2 />');
jsx = jsx.replace(/<(img|input|hr|br|meta|link)([^>]*?)(?!\/)(?=\s*>)/g, '<$1$2 />');
// Fix style strings if any (we probably don't have inline styles but just in case)
// jsx = jsx.replace(/style="([^"]*)"/g, "style={{}}");
fs.writeFileSync(outputFile, jsx);
}
convertHtmlToJsx('c:\\Users\\sinha\\storygen\\ai-story-generator-1\\.stitch\\designs\\landing.html', 'c:\\Users\\sinha\\storygen\\ai-story-generator-1\\.stitch\\designs\\landing.jsx');