-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmdhtml_s.cpp
More file actions
executable file
·67 lines (63 loc) · 1.89 KB
/
Copy pathmdhtml_s.cpp
File metadata and controls
executable file
·67 lines (63 loc) · 1.89 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
57
58
59
60
61
62
63
64
65
66
67
#include <algorithm>
#include <iostream>
void make_h(std::string &code, std::string &result) {
auto i = std::ranges::find(code, '#');
auto j = std::ranges::find(code, ';');
auto c = std::count(i, j, '#');
result += "<h" + std::string(1, c + '0') + ">" + std::string(i + c, j) +
"</h" + std::string(1, c + '0') + ">";
code.erase(i, j + 1);
}
void make_(std::string &code, std::string &result, const char s,
const std::string &p, const std::string &a) {
auto i = std::ranges::find(code, s);
auto j = std::ranges::find(code, ';');
result += p + std::string(i + 1, j) + a;
code.erase(i, j + 1);
}
void make_p(std::string &code, std::string &result) {
make_(code, result, '@', "<p>", "</p>");
}
void make_style(std::string &code, std::string &result) {
make_(code, result, '!', "<link rel=\"stylesheet\" href=\"", "\">");
}
void make_title(std::string &code, std::string &result) {
make_(code, result, '$', "<title>", "</title>");
}
void make_img(std::string &code, std::string &result) {
make_(code, result, '*', "<img src=\"", "\">");
}
void make_html(const std::string &code, std::string &result) {
result = "<!DOCTYPE html><html><head><meta charset=\"utf-8\">";
std::string cstr = code;
if (cstr.contains('!'))
make_style(cstr, result);
if (cstr.contains('$'))
make_title(cstr, result);
result += "</meta><body>";
while (!cstr.empty()) {
switch (cstr.front()) {
case '#':
make_h(cstr, result);
break;
case '@':
make_p(cstr, result);
break;
case '*':
make_img(cstr, result);
break;
default:
if (cstr.front() == ' ')
cstr.erase(0, 1);
break;
}
}
result += "</body></html>";
}
int main() {
std::string r = ""; // result string
std::string c = ""; // code goes here
make_html(c, r);
std::cout << r;
return 0;
}