Skip to content

Commit bd86cdc

Browse files
authored
Update and rename Ta.cpp to Math Note Build HTML.cpp
1 parent fdde55c commit bd86cdc

2 files changed

Lines changed: 160 additions & 213 deletions

File tree

Math Note Build HTML.cpp

Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
#include <iostream>
2+
#include <fstream>
3+
#include <string>
4+
5+
using namespace std;
6+
7+
const string FONT_LINK = R"(
8+
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;600&family=Merriweather:wght@400;700&display=swap" rel="stylesheet">
9+
)";
10+
11+
const string CSS_STYLE = R"(
12+
<style>
13+
* {
14+
margin: 0;
15+
padding: 0;
16+
box-sizing: border-box;
17+
}
18+
19+
body {
20+
background: linear-gradient(135deg, #f8f9ff 0%, #e6f0ff 100%);
21+
min-height: 100vh;
22+
font-family: 'Inter', sans-serif;
23+
color: #2c3e50;
24+
line-height: 1.8;
25+
padding: 2rem;
26+
}
27+
28+
#write {
29+
max-width: 800px;
30+
margin: 0 auto;
31+
padding: 2rem;
32+
background: rgba(255, 255, 255, 0.95);
33+
border-radius: 16px;
34+
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
35+
backdrop-filter: blur(8px);
36+
border: 1px solid rgba(255, 255, 255, 0.3);
37+
}
38+
39+
h1, h2, h3 {
40+
font-family: 'Merriweather', serif;
41+
margin-top: 2rem;
42+
margin-bottom: 1.5rem;
43+
position: relative;
44+
padding-bottom: 0.5rem;
45+
}
46+
47+
h1 { font-size: 2.5rem; border-bottom: 2px solid #4a90e2; }
48+
h2 { font-size: 2rem; border-bottom: 1px solid #dfe6e9; }
49+
h3 { font-size: 1.5rem; color: #4a5568; }
50+
51+
p {
52+
margin: 1.2rem 0;
53+
font-size: 1.1rem;
54+
color: #4a5568;
55+
}
56+
57+
.Button {
58+
background: linear-gradient(135deg, #4a90e2 0%, #6c5ce7 100%);
59+
border: none;
60+
border-radius: 12px;
61+
color: white;
62+
padding: 15px 32px;
63+
text-align: center;
64+
text-decoration: none;
65+
display: inline-block;
66+
font-size: 16px;
67+
margin: 2rem 0;
68+
cursor: pointer;
69+
transition: all 0.3s ease;
70+
box-shadow: 0 4px 6px rgba(74, 144, 226, 0.2);
71+
}
72+
73+
.Button:hover {
74+
transform: translateY(-2px);
75+
box-shadow: 0 7px 14px rgba(74, 144, 226, 0.3);
76+
}
77+
78+
@media (max-width: 768px) {
79+
body { padding: 1rem; }
80+
#write { padding: 1.5rem; }
81+
h1 { font-size: 2rem; }
82+
h2 { font-size: 1.5rem; }
83+
h3 { font-size: 1.2rem; }
84+
p { font-size: 1rem; }
85+
}
86+
87+
@keyframes fadeIn {
88+
from { opacity: 0; transform: translateY(20px); }
89+
to { opacity: 1; transform: translateY(0); }
90+
}
91+
#write { animation: fadeIn 0.8s ease-out; }
92+
</style>
93+
)";
94+
95+
string read_file(const string& path) {
96+
ifstream f(path);
97+
return string((istreambuf_iterator<char>(f)),
98+
istreambuf_iterator<char>());
99+
}
100+
101+
void write_file(const string& path, const string& content) {
102+
ofstream f(path);
103+
f << content;
104+
}
105+
106+
void beautify_html(string& html) {
107+
// Insert fonts and styles
108+
size_t head_end = html.find("</head>");
109+
if (head_end != string::npos) {
110+
html.insert(head_end, FONT_LINK + CSS_STYLE);
111+
}
112+
113+
// Check if the content is already wrapped in <div id="write">
114+
size_t write_div_start = html.find("<div id=\"write\">");
115+
size_t write_div_end = html.find("</div>", write_div_start);
116+
117+
if (write_div_start == string::npos) {
118+
// If not wrapped, wrap the content
119+
size_t body_start = html.find("<body");
120+
if (body_start != string::npos) {
121+
size_t body_end = html.find(">", body_start);
122+
size_t content_start = body_end + 1;
123+
size_t content_end = html.find("</body>", content_start);
124+
125+
string new_body = string(html.begin() + body_start, html.begin() + content_start)
126+
+ html.substr(content_start, content_end - content_start)
127+
+ "</div>\n<div style=\"text-align:center\">"
128+
"<a href=\"javascript:history.back()\">"
129+
"<button class=\"Button\">Back to the Previous Page</button></a></div>"
130+
+ html.substr(content_end);
131+
132+
html.replace(body_start, content_end - body_start + 7, new_body);
133+
}
134+
} else {
135+
// If already wrapped, check if there is a nested <div id="write">
136+
size_t inner_write_start = html.find("<div id=\"write\">", write_div_end);
137+
if (inner_write_start != string::npos) {
138+
// Extract the inner content
139+
size_t inner_write_end = html.find("</div>", inner_write_start);
140+
string inner_content = html.substr(inner_write_start + 16, inner_write_end - inner_write_start - 16);
141+
142+
// Replace the outer <div id="write"> with the inner content
143+
html.replace(write_div_start, write_div_end - write_div_start + 6, inner_content);
144+
}
145+
}
146+
}
147+
148+
int main(int argc, char* argv[]) {
149+
if (argc != 3) {
150+
cout << "Usage: " << argv[0] << " <input.html> <output.html>\n";
151+
return 1;
152+
}
153+
154+
string html = read_file(argv[1]);
155+
beautify_html(html);
156+
write_file(argv[2], html);
157+
158+
cout << "HTML beautified successfully!\n";
159+
return 0;
160+
}

Ta.cpp

Lines changed: 0 additions & 213 deletions
This file was deleted.

0 commit comments

Comments
 (0)