thoth-markup-lang 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +12 -0
- package/test.html +52 -0
- package/test.thoth +41 -0
- package/thoth.js +87 -0
package/package.json
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "thoth-markup-lang",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "The Pythonic Architect of the Web - HTML alternative",
|
|
5
|
+
"main": "thoth.js",
|
|
6
|
+
"bin": {
|
|
7
|
+
"thoth": "./thoth.js"
|
|
8
|
+
},
|
|
9
|
+
"keywords": ["html", "markup", "pythonic", "thoth", "parser"],
|
|
10
|
+
"author": "Abdelfatah Abdelhamed",
|
|
11
|
+
"license": "MIT"
|
|
12
|
+
}
|
package/test.html
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8">
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
6
|
+
<title>THOTH Output</title>
|
|
7
|
+
</head>
|
|
8
|
+
<body>
|
|
9
|
+
<h1 style="color>#d4af37; text-align: center;": Welcome to THOTH V2</h1>
|
|
10
|
+
<p>Now supporting EVERY HTML element with attributes!</p>
|
|
11
|
+
<div style="border>2px dashed #d4af37; padding: 20px; border-radius: 8px;":</div>
|
|
12
|
+
<h2>1. Full Form Support</h2>
|
|
13
|
+
<form>
|
|
14
|
+
<label>Enter your Name:</label>
|
|
15
|
+
<input type="text" placeholder="John Doe">
|
|
16
|
+
<br>
|
|
17
|
+
<label>Choose an option:</label>
|
|
18
|
+
<select>
|
|
19
|
+
<option value="1">Option A</option>
|
|
20
|
+
<option value="2">Option B</option>
|
|
21
|
+
</select>
|
|
22
|
+
<br>
|
|
23
|
+
<button type="button">Submit Data</button>
|
|
24
|
+
</form>
|
|
25
|
+
<hr>
|
|
26
|
+
<h2>2. Tables and Data</h2>
|
|
27
|
+
<table>
|
|
28
|
+
<tr>
|
|
29
|
+
<th>ID</th>
|
|
30
|
+
<th>Name</th>
|
|
31
|
+
<th>Role</th>
|
|
32
|
+
</tr>
|
|
33
|
+
<tr>
|
|
34
|
+
<td>1</td>
|
|
35
|
+
<td>Thoth</td>
|
|
36
|
+
<td>Scribe</td>
|
|
37
|
+
</tr>
|
|
38
|
+
<tr>
|
|
39
|
+
<td>2</td>
|
|
40
|
+
<td>Horus</td>
|
|
41
|
+
<td>Guardian</td>
|
|
42
|
+
</tr>
|
|
43
|
+
</table>
|
|
44
|
+
<hr>
|
|
45
|
+
<h2>3. Lists</h2>
|
|
46
|
+
<ol>
|
|
47
|
+
<li>Clean Syntax</li>
|
|
48
|
+
<li>Python-like Indentation</li>
|
|
49
|
+
<li>Ultimate Power</li>
|
|
50
|
+
</ol>
|
|
51
|
+
</body>
|
|
52
|
+
</html>
|
package/test.thoth
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
Title style="color: #d4af37; text-align: center;": Welcome to THOTH V2
|
|
2
|
+
Text: Now supporting EVERY HTML element with attributes!
|
|
3
|
+
|
|
4
|
+
Box style="border: 2px dashed #d4af37; padding: 20px; border-radius: 8px;":
|
|
5
|
+
Sub: 1. Full Form Support
|
|
6
|
+
Form:
|
|
7
|
+
Label: Enter your Name:
|
|
8
|
+
Input type="text" placeholder="John Doe":
|
|
9
|
+
Break:
|
|
10
|
+
Label: Choose an option:
|
|
11
|
+
Select:
|
|
12
|
+
Option value="1": Option A
|
|
13
|
+
Option value="2": Option B
|
|
14
|
+
Break:
|
|
15
|
+
Button type="button": Submit Data
|
|
16
|
+
|
|
17
|
+
Line:
|
|
18
|
+
|
|
19
|
+
Sub: 2. Tables and Data
|
|
20
|
+
Table:
|
|
21
|
+
Row:
|
|
22
|
+
Head: ID
|
|
23
|
+
Head: Name
|
|
24
|
+
Head: Role
|
|
25
|
+
Row:
|
|
26
|
+
Data: 1
|
|
27
|
+
Data: Thoth
|
|
28
|
+
Data: Scribe
|
|
29
|
+
Row:
|
|
30
|
+
Data: 2
|
|
31
|
+
Data: Horus
|
|
32
|
+
Data: Guardian
|
|
33
|
+
|
|
34
|
+
Line:
|
|
35
|
+
|
|
36
|
+
Sub: 3. Lists
|
|
37
|
+
OrderedList:
|
|
38
|
+
Item: Clean Syntax
|
|
39
|
+
Item: Python-like Indentation
|
|
40
|
+
Item: Ultimate Power
|
|
41
|
+
|
package/thoth.js
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const fs = require('fs');
|
|
4
|
+
const path = require('path');
|
|
5
|
+
|
|
6
|
+
// 1. استقبال اسم الملف من سطر الأوامر
|
|
7
|
+
const inputFile = process.argv[2];
|
|
8
|
+
|
|
9
|
+
if (!inputFile || path.extname(inputFile) !== '.thoth') {
|
|
10
|
+
console.error('❌ Error: Please provide a valid .thoth file.');
|
|
11
|
+
console.log('💡 Usage: thoth filename.thoth');
|
|
12
|
+
process.exit(1);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
// 2. القواميس (دعم الكلمات المختصرة وكل تاجات HTML)
|
|
16
|
+
const tagAliases = {
|
|
17
|
+
'Title': 'h1', 'Sub': 'h2', 'Text': 'p', 'Bold': 'strong', 'Italic': 'em',
|
|
18
|
+
'Box': 'div', 'Link': 'a', 'Image': 'img', 'List': 'ul', 'OrderedList': 'ol',
|
|
19
|
+
'Item': 'li', 'Row': 'tr', 'Head': 'th', 'Data': 'td', 'Quote': 'blockquote',
|
|
20
|
+
'Line': 'hr', 'Break': 'br'
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
// التاجات التي لا تحتاج إغلاق
|
|
24
|
+
const voidTags = ['img', 'br', 'hr', 'input', 'meta', 'link', 'source'];
|
|
25
|
+
|
|
26
|
+
// 3. قراءة ملف الـ THOTH
|
|
27
|
+
const code = fs.readFileSync(inputFile, 'utf8');
|
|
28
|
+
const lines = code.split('\n');
|
|
29
|
+
|
|
30
|
+
// تجهيز هيكل ملف الـ HTML الأساسي
|
|
31
|
+
let html = `<!DOCTYPE html>
|
|
32
|
+
<html lang="en">
|
|
33
|
+
<head>
|
|
34
|
+
<meta charset="UTF-8">
|
|
35
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
36
|
+
<title>THOTH Output</title>
|
|
37
|
+
</head>
|
|
38
|
+
<body>
|
|
39
|
+
`;
|
|
40
|
+
let stack = [];
|
|
41
|
+
|
|
42
|
+
// 4. عملية التحليل (الـ Parsing)
|
|
43
|
+
lines.forEach(line => {
|
|
44
|
+
if (line.trim() === '') return;
|
|
45
|
+
|
|
46
|
+
const indent = line.search(/\S/);
|
|
47
|
+
const contentRaw = line.trim();
|
|
48
|
+
|
|
49
|
+
// فصل الأمر، الخصائص، والمحتوى
|
|
50
|
+
const match = contentRaw.match(/^([A-Za-z0-9]+)([^:]*):?(.*)$/);
|
|
51
|
+
if (!match) return;
|
|
52
|
+
|
|
53
|
+
let command = match[1].trim();
|
|
54
|
+
let attributes = match[2].trim();
|
|
55
|
+
let content = match[3].trim();
|
|
56
|
+
|
|
57
|
+
let htmlTag = tagAliases[command] || command.toLowerCase();
|
|
58
|
+
|
|
59
|
+
// إغلاق التاجات المفتوحة إذا قلت المسافات
|
|
60
|
+
while (stack.length > 0 && stack[stack.length - 1].indent >= indent) {
|
|
61
|
+
html += ' '.repeat(stack[stack.length - 1].indent) + `</${stack.pop().name}>\n`;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
let openTag = `<${htmlTag}${attributes ? ' ' + attributes : ''}>`;
|
|
65
|
+
|
|
66
|
+
if (voidTags.includes(htmlTag)) {
|
|
67
|
+
html += ' '.repeat(indent) + openTag + '\n';
|
|
68
|
+
} else if (content) {
|
|
69
|
+
html += ' '.repeat(indent) + openTag + content + `</${htmlTag}>\n`;
|
|
70
|
+
} else {
|
|
71
|
+
html += ' '.repeat(indent) + openTag + '\n';
|
|
72
|
+
stack.push({ name: htmlTag, indent: indent });
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
// إغلاق أي تاجات متبقية
|
|
77
|
+
while (stack.length > 0) {
|
|
78
|
+
html += ' '.repeat(stack[stack.length - 1].indent) + `</${stack.pop().name}>\n`;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
html += '</body>\n</html>';
|
|
82
|
+
|
|
83
|
+
// 5. كتابة ملف الـ HTML الجديد
|
|
84
|
+
const outputFile = inputFile.replace('.thoth', '.html');
|
|
85
|
+
fs.writeFileSync(outputFile, html);
|
|
86
|
+
|
|
87
|
+
console.log(`✅ Success! Compiled ${inputFile} -> ${outputFile}`);
|