thoth-markup-lang 3.0.0 → 4.1.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/.htaccess +7 -1
- package/engine.php +138 -0
- package/package.json +35 -5
- package/thoth.js +112 -28
- package/thoth-server.php +0 -8
package/.htaccess
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
# THOTH Server Configuration
|
|
1
2
|
RewriteEngine On
|
|
3
|
+
|
|
4
|
+
# توجيه أي طلب لملف ينتهي بـ .thoth إلى محرك المهندس عبد الفتاح
|
|
2
5
|
RewriteCond %{REQUEST_FILENAME} !-f
|
|
3
|
-
RewriteRule ^(.*)$ engine.php?file=$1.thoth [L,QSA]
|
|
6
|
+
RewriteRule ^(.*)\.thoth$ engine.php?file=$1.thoth [L,QSA]
|
|
7
|
+
|
|
8
|
+
# جعل index.thoth هو الملف الرئيسي للموقع
|
|
9
|
+
DirectoryIndex index.thoth
|
package/engine.php
ADDED
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
<?php
|
|
2
|
+
/**
|
|
3
|
+
* THOTH Sovereign Runtime Engine v7.0
|
|
4
|
+
* Developed by: Engineer Abdelfatah Abdelhamed 🇪🇬
|
|
5
|
+
* * هذا المحرك يقوم بتشغيل ملفات .thoth مباشرة كبيئة مستقلة.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
class ThothEngine {
|
|
9
|
+
private $tagMap = [
|
|
10
|
+
'Title' => 'h1', 'Sub' => 'h2', 'Heading' => 'h3', 'Text' => 'p',
|
|
11
|
+
'Box' => 'div', 'Container' => 'section', 'Nav' => 'nav',
|
|
12
|
+
'Header' => 'header', 'Footer' => 'footer', 'Bold' => 'strong',
|
|
13
|
+
'Italic' => 'em', 'Link' => 'a', 'Image' => 'img', 'List' => 'ul',
|
|
14
|
+
'Item' => 'li', 'Button' => 'button', 'Input' => 'input',
|
|
15
|
+
'Break' => 'br', 'Line' => 'hr'
|
|
16
|
+
];
|
|
17
|
+
|
|
18
|
+
private $voidTags = ['img', 'br', 'hr', 'input', 'meta', 'link'];
|
|
19
|
+
|
|
20
|
+
public function render($filePath) {
|
|
21
|
+
if (!file_exists($filePath)) {
|
|
22
|
+
header("HTTP/1.0 404 Not Found");
|
|
23
|
+
return "<h1 style='font-family:sans-serif; text-align:center; margin-top:20%'>404 | THOTH File Not Found</h1>";
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
$code = file_get_contents($filePath);
|
|
27
|
+
$lines = explode("\n", $code);
|
|
28
|
+
|
|
29
|
+
$htmlBody = "";
|
|
30
|
+
$stack = [];
|
|
31
|
+
$inRawMode = false;
|
|
32
|
+
$rawType = '';
|
|
33
|
+
$rawIndent = 0;
|
|
34
|
+
|
|
35
|
+
foreach ($lines as $line) {
|
|
36
|
+
$trimmed = trim($line);
|
|
37
|
+
|
|
38
|
+
// 1. تجاهل الأسطر الفارغة والتعليقات (تم حل مشكلة ظهور الكومنت)
|
|
39
|
+
if ($trimmed === "" || strpos($trimmed, '#') === 0) continue;
|
|
40
|
+
|
|
41
|
+
$indent = strlen($line) - strlen(ltrim($line));
|
|
42
|
+
|
|
43
|
+
// 2. معالجة الـ Raw Mode (StyleSheet / Scripting)
|
|
44
|
+
if ($inRawMode) {
|
|
45
|
+
if ($indent <= $rawIndent && !empty($trimmed)) {
|
|
46
|
+
$inRawMode = false;
|
|
47
|
+
$htmlBody .= "</$rawType>\n";
|
|
48
|
+
} else {
|
|
49
|
+
$htmlBody .= $line . "\n";
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// 3. تحليل السطر وفصل الأوامر عن المحتوى
|
|
55
|
+
// نستخدم خوارزمية البحث عن أول ":" خارج علامات التنصيص
|
|
56
|
+
$sep = -1;
|
|
57
|
+
$inQuotes = false;
|
|
58
|
+
for ($i = 0; $i < strlen($trimmed); $i++) {
|
|
59
|
+
if ($trimmed[$i] === '"') $inQuotes = !$inQuotes;
|
|
60
|
+
if ($trimmed[$i] === ':' && !$inQuotes) {
|
|
61
|
+
$sep = $i;
|
|
62
|
+
break;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
if ($sep !== -1) {
|
|
67
|
+
$cmdPart = trim(substr($trimmed, 0, $sep));
|
|
68
|
+
$val = trim(substr($trimmed, $sep + 1));
|
|
69
|
+
} else {
|
|
70
|
+
$cmdPart = $trimmed;
|
|
71
|
+
$val = "";
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// فصل اسم التاج عن الخصائص (Attributes)
|
|
75
|
+
$spacePos = strpos($cmdPart, ' ');
|
|
76
|
+
if ($spacePos !== false) {
|
|
77
|
+
$cmd = substr($cmdPart, 0, $spacePos);
|
|
78
|
+
$attrs = trim(substr($cmdPart, $spacePos));
|
|
79
|
+
} else {
|
|
80
|
+
$cmd = $cmdPart;
|
|
81
|
+
$attrs = "";
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// 4. الدخول في الـ Raw Mode للأكواد المدمجة
|
|
85
|
+
if ($cmd === "StyleSheet" || $cmd === "Scripting") {
|
|
86
|
+
$inRawMode = true;
|
|
87
|
+
$rawType = ($cmd === "StyleSheet") ? "style" : "script";
|
|
88
|
+
$rawIndent = $indent;
|
|
89
|
+
$htmlBody .= "<$rawType>\n";
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// 5. إغلاق التاجات السابقة بناءً على مستوى المسافات
|
|
94
|
+
while (count($stack) > 0 && $stack[count($stack) - 1]['indent'] >= $indent) {
|
|
95
|
+
$closedTag = array_pop($stack);
|
|
96
|
+
$htmlBody .= "</" . $closedTag['tag'] . ">\n";
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
$tag = isset($this->tagMap[$cmd]) ? $this->tagMap[$cmd] : strtolower($cmd);
|
|
100
|
+
$openingTag = "<$tag" . ($attrs ? " $attrs" : "") . ">";
|
|
101
|
+
|
|
102
|
+
// 6. بناء هيكل الـ HTML النهائي
|
|
103
|
+
if (in_array($tag, $this->voidTags)) {
|
|
104
|
+
$htmlBody .= str_repeat(" ", $indent) . $openingTag . "\n";
|
|
105
|
+
} elseif ($val !== "") {
|
|
106
|
+
$htmlBody .= str_repeat(" ", $indent) . $openingTag . $val . "</$tag>\n";
|
|
107
|
+
} else {
|
|
108
|
+
$htmlBody .= str_repeat(" ", $indent) . $openingTag . "\n";
|
|
109
|
+
$stack[] = ['tag' => $tag, 'indent' => $indent];
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// إغلاق أي تاجات متبقية في نهاية الملف
|
|
114
|
+
while ($closedTag = array_pop($stack)) {
|
|
115
|
+
$htmlBody .= "</" . $closedTag['tag'] . ">\n";
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
return $this->generateFullHTML($htmlBody);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
private function generateFullHTML($body) {
|
|
122
|
+
// بناء الهيكل النهائي المتوافق مع محركات البحث (SEO)
|
|
123
|
+
return "<!DOCTYPE html>\n<html lang='ar' dir='rtl'>\n<head>\n" .
|
|
124
|
+
" <meta charset='UTF-8'>\n" .
|
|
125
|
+
" <meta name='viewport' content='width=device-width, initial-scale=1.0'>\n" .
|
|
126
|
+
" <meta name='generator' content='THOTH Sovereign Engine 7.0'>\n" .
|
|
127
|
+
" <meta name='author' content='Abdelfatah Abdelhamed'>\n" .
|
|
128
|
+
"</head>\n<body>\n$body\n</body>\n</html>";
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// تشغيل المحرك ومعالجة الطلبات
|
|
133
|
+
$engine = new ThothEngine();
|
|
134
|
+
$fileRequested = isset($_GET['file']) ? $_GET['file'] : 'index.thoth';
|
|
135
|
+
|
|
136
|
+
// منع الوصول لملفات خارج النظام للأمان
|
|
137
|
+
$safeFile = basename($fileRequested);
|
|
138
|
+
echo $engine->render($safeFile);
|
package/package.json
CHANGED
|
@@ -1,12 +1,42 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "thoth-markup-lang",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "4.1.0",
|
|
4
|
+
"description": "THOTH is a sovereign, high-performance indentation-based markup language and runtime engine. Built by Engineer Abdelfatah Abdelhamed to redefine web architecture with pure, bracket-less logic and 100% HTML5 semantic compliance.",
|
|
5
5
|
"main": "thoth.js",
|
|
6
6
|
"bin": {
|
|
7
7
|
"thoth": "./thoth.js"
|
|
8
8
|
},
|
|
9
|
-
"
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
"scripts": {
|
|
10
|
+
"start": "node thoth.js",
|
|
11
|
+
"build": "thoth"
|
|
12
|
+
},
|
|
13
|
+
"keywords": [
|
|
14
|
+
"thoth",
|
|
15
|
+
"thoth-lang",
|
|
16
|
+
"thoth-runtime",
|
|
17
|
+
"markup-language",
|
|
18
|
+
"indentation-based",
|
|
19
|
+
"pythonic-markup",
|
|
20
|
+
"clean-code-web",
|
|
21
|
+
"sovereign-engine",
|
|
22
|
+
"pure-markup",
|
|
23
|
+
"egyptian-engineering",
|
|
24
|
+
"abdelfatah-abdelhamed",
|
|
25
|
+
"zero-brackets",
|
|
26
|
+
"web-architect",
|
|
27
|
+
"performance-markup",
|
|
28
|
+
"minimalist-code",
|
|
29
|
+
"html5-generator",
|
|
30
|
+
"smart-indent",
|
|
31
|
+
"native-thoth"
|
|
32
|
+
],
|
|
33
|
+
"author": "Abdelfatah Abdelhamed <abdelfatahabdelhamed.kfs@gmail.com>",
|
|
34
|
+
"license": "MIT",
|
|
35
|
+
"engines": {
|
|
36
|
+
"node": ">=14.0.0"
|
|
37
|
+
},
|
|
38
|
+
"preferGlobal": true,
|
|
39
|
+
"publishConfig": {
|
|
40
|
+
"access": "public"
|
|
41
|
+
}
|
|
12
42
|
}
|
package/thoth.js
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
|
|
2
3
|
/**
|
|
3
|
-
* THOTH Engine
|
|
4
|
-
*
|
|
4
|
+
* THOTH Engine v4.1.0 - "The Sovereign Architect"
|
|
5
|
+
* Developed by: Engineer Abdelfatah Abdelhamed 🇪🇬
|
|
6
|
+
* --------------------------------------------------
|
|
7
|
+
* Pure Indentation-Based Markup Language & Runtime
|
|
5
8
|
*/
|
|
6
9
|
|
|
7
10
|
const fs = require('fs');
|
|
@@ -10,24 +13,37 @@ const path = require('path');
|
|
|
10
13
|
const command = process.argv[2];
|
|
11
14
|
const file = process.argv[3];
|
|
12
15
|
|
|
16
|
+
// تنسيق رسالة الاستخدام في حالة الخطأ
|
|
13
17
|
if (!command || (command !== 'build' && !command.endsWith('.thoth'))) {
|
|
14
|
-
console.log('\x1b[33m%s\x1b[0m', '
|
|
18
|
+
console.log('\x1b[33m%s\x1b[0m', '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━');
|
|
19
|
+
console.log('\x1b[1m\x1b[32m 𓅓 THOTH ENGINE v4.1.0 \x1b[0m');
|
|
20
|
+
console.log('\x1b[33m%s\x1b[0m', ' Developed by Engineer Abdelfatah Abdelhamed');
|
|
21
|
+
console.log('\x1b[33m%s\x1b[0m', '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━');
|
|
22
|
+
console.log(' Usage:');
|
|
23
|
+
console.log(' thoth build file.thoth \x1b[90m(Create a standalone HTML5 file)\x1b[0m');
|
|
24
|
+
console.log(' thoth file.thoth \x1b[90m(Fast Internal Compilation)\x1b[0m');
|
|
15
25
|
process.exit(1);
|
|
16
26
|
}
|
|
17
27
|
|
|
18
28
|
const targetFile = command === 'build' ? file : command;
|
|
19
29
|
|
|
20
|
-
// القاموس الشامل
|
|
30
|
+
// القاموس الهندسي الشامل لجميع وسوم HTML5
|
|
21
31
|
const MAP = {
|
|
22
|
-
'Title': 'h1', 'Sub': 'h2', '
|
|
23
|
-
'
|
|
32
|
+
'Title': 'h1', 'Sub': 'h2', 'Heading': 'h3', 'Text': 'p', 'Bold': 'strong',
|
|
33
|
+
'Italic': 'em', 'Box': 'div', 'Container': 'section', 'Nav': 'nav',
|
|
34
|
+
'Header': 'header', 'Footer': 'footer', 'Article': 'article', 'Aside': 'aside',
|
|
24
35
|
'Link': 'a', 'Image': 'img', 'Button': 'button', 'List': 'ul', 'Item': 'li',
|
|
25
|
-
'Input': 'input', 'Form': 'form', 'Label': 'label', 'Break': 'br'
|
|
36
|
+
'Input': 'input', 'Form': 'form', 'Label': 'label', 'Break': 'br', 'Line': 'hr'
|
|
26
37
|
};
|
|
27
38
|
|
|
28
|
-
const
|
|
39
|
+
const VOID_TAGS = ['img', 'br', 'hr', 'input', 'meta', 'link'];
|
|
29
40
|
|
|
30
41
|
function compile(filePath) {
|
|
42
|
+
if (!fs.existsSync(filePath)) {
|
|
43
|
+
console.error('\x1b[31m%s\x1b[0m', `❌ Error: File "${filePath}" not found.`);
|
|
44
|
+
process.exit(1);
|
|
45
|
+
}
|
|
46
|
+
|
|
31
47
|
const code = fs.readFileSync(filePath, 'utf8');
|
|
32
48
|
const lines = code.split(/\r?\n/);
|
|
33
49
|
let htmlBody = "";
|
|
@@ -35,41 +51,109 @@ function compile(filePath) {
|
|
|
35
51
|
let inRaw = false, rawType = '', rawIndent = 0;
|
|
36
52
|
|
|
37
53
|
lines.forEach(line => {
|
|
38
|
-
|
|
54
|
+
const trimmed = line.trim();
|
|
55
|
+
|
|
56
|
+
// 1. تجاهل الأسطر الفارغة والتعليقات تماماً
|
|
57
|
+
if (!trimmed || trimmed.startsWith('#')) return;
|
|
58
|
+
|
|
39
59
|
const indent = line.search(/\S/);
|
|
40
|
-
const clean = line.trim();
|
|
41
60
|
|
|
61
|
+
// 2. نظام الـ Raw Mode للأكواد المدمجة (CSS/JS)
|
|
42
62
|
if (inRaw) {
|
|
43
|
-
if (indent <= rawIndent &&
|
|
44
|
-
|
|
63
|
+
if (indent <= rawIndent && trimmed !== "") {
|
|
64
|
+
inRaw = false;
|
|
65
|
+
htmlBody += `</${rawType}>\n`;
|
|
66
|
+
} else {
|
|
67
|
+
htmlBody += line + '\n';
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// 3. خوارزمية الفصل الذكية (لحل مشكلة النقطتين داخل الـ Styles)
|
|
73
|
+
let sepIndex = -1;
|
|
74
|
+
let inQuotes = false;
|
|
75
|
+
for (let i = 0; i < trimmed.length; i++) {
|
|
76
|
+
if (trimmed[i] === '"') inQuotes = !inQuotes;
|
|
77
|
+
if (trimmed[i] === ':' && !inQuotes) {
|
|
78
|
+
sepIndex = i;
|
|
79
|
+
break;
|
|
80
|
+
}
|
|
45
81
|
}
|
|
46
82
|
|
|
47
|
-
|
|
48
|
-
if (
|
|
49
|
-
|
|
83
|
+
let cmdPart, val;
|
|
84
|
+
if (sepIndex !== -1) {
|
|
85
|
+
cmdPart = trimmed.substring(0, sepIndex).trim();
|
|
86
|
+
val = trimmed.substring(sepIndex + 1).trim();
|
|
87
|
+
} else {
|
|
88
|
+
cmdPart = trimmed;
|
|
89
|
+
val = "";
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// فصل اسم التاج عن الخصائص (Attributes)
|
|
93
|
+
const spacePos = cmdPart.indexOf(' ');
|
|
94
|
+
let cmd = spacePos !== -1 ? cmdPart.substring(0, spacePos) : cmdPart;
|
|
95
|
+
let attrs = spacePos !== -1 ? cmdPart.substring(spacePos).trim() : "";
|
|
50
96
|
|
|
97
|
+
// 4. الدخول في الـ Raw Mode
|
|
51
98
|
if (cmd === "StyleSheet" || cmd === "Scripting") {
|
|
52
|
-
inRaw = true;
|
|
53
|
-
|
|
99
|
+
inRaw = true;
|
|
100
|
+
rawType = (cmd === "StyleSheet") ? "style" : "script";
|
|
101
|
+
rawIndent = indent;
|
|
102
|
+
htmlBody += `<${rawType}>\n`;
|
|
103
|
+
return;
|
|
54
104
|
}
|
|
55
105
|
|
|
106
|
+
// 5. إدارة قفل التاجات حسب مستوى المسافات
|
|
56
107
|
while (stack.length > 0 && stack[stack.length - 1].indent >= indent) {
|
|
57
108
|
htmlBody += `</${stack.pop().name}>\n`;
|
|
58
109
|
}
|
|
59
110
|
|
|
60
111
|
let tag = MAP[cmd] || cmd.toLowerCase();
|
|
61
|
-
let
|
|
62
|
-
|
|
63
|
-
if (
|
|
64
|
-
|
|
65
|
-
else
|
|
112
|
+
let openTag = `<${tag}${attrs ? ' ' + attrs : ''}>`;
|
|
113
|
+
|
|
114
|
+
if (VOID_TAGS.includes(tag)) {
|
|
115
|
+
htmlBody += openTag + '\n';
|
|
116
|
+
} else if (val) {
|
|
117
|
+
htmlBody += `${openTag}${val}</${tag}>\n`;
|
|
118
|
+
} else {
|
|
119
|
+
htmlBody += openTag + '\n';
|
|
120
|
+
stack.push({ name: tag, indent: indent });
|
|
121
|
+
}
|
|
66
122
|
});
|
|
67
123
|
|
|
68
|
-
|
|
69
|
-
|
|
124
|
+
// إغلاق أي تاجات متبقية
|
|
125
|
+
while (stack.length > 0) {
|
|
126
|
+
htmlBody += `</${stack.pop().name}>\n`;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// بناء الهيكل النهائي مع تحسينات SEO
|
|
130
|
+
return `<!DOCTYPE html>
|
|
131
|
+
<html lang="ar" dir="rtl">
|
|
132
|
+
<head>
|
|
133
|
+
<meta charset="UTF-8">
|
|
134
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
135
|
+
<meta name="generator" content="THOTH Sovereign Engine v4.1.0">
|
|
136
|
+
<meta name="author" content="Abdelfatah Abdelhamed">
|
|
137
|
+
<title>Compiled by THOTH</title>
|
|
138
|
+
</head>
|
|
139
|
+
<body>
|
|
140
|
+
${htmlBody}
|
|
141
|
+
</body>
|
|
142
|
+
</html>`;
|
|
70
143
|
}
|
|
71
144
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
145
|
+
// تنفيذ عملية التجميع
|
|
146
|
+
try {
|
|
147
|
+
const result = compile(targetFile);
|
|
148
|
+
const output = targetFile.replace('.thoth', '.html');
|
|
149
|
+
fs.writeFileSync(output, result);
|
|
150
|
+
|
|
151
|
+
console.log('\x1b[32m%s\x1b[0m', `──────────────────────────────────────────`);
|
|
152
|
+
console.log('\x1b[1m\x1b[32m ✔ SUCCESS: \x1b[0m THOTH Engine has spoken.');
|
|
153
|
+
console.log('\x1b[37m Output:\x1b[0m', output);
|
|
154
|
+
console.log('\x1b[37m Author:\x1b[0m Engineer Abdelfatah Abdelhamed 🇪🇬');
|
|
155
|
+
console.log('\x1b[32m%s\x1b[0m', `──────────────────────────────────────────`);
|
|
156
|
+
} catch (err) {
|
|
157
|
+
console.error('\x1b[31m%s\x1b[0m', `❌ Compilation Error: ${err.message}`);
|
|
158
|
+
process.exit(1);
|
|
159
|
+
}
|