-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgemtxt.h
162 lines (157 loc) · 5.21 KB
/
gemtxt.h
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
/*
* pipette
* gemtxt.h
* created 11-14-21
-------------------
(C) Luminoso 2021/MIT License
* */
#ifndef PIPETTE_GEMTXT_H
#define PIPETTE_GEMTXT_H
#include <vector>
#include "util.h"
namespace gemtext{
struct GemLine{
std::string content;
int rendertype; //0 = plain, 1 = Heading, 2 = Semiheading, 3 = SemiSemi heading, 4 = Monospace, 5 = List, 6 = Quote, 7 = Link
std::string metadata;
};
std::vector<GemLine> introTextGen(){
std::vector<GemLine> gemlines;
gemlines.push_back(
GemLine{
"waiting for browse activity", 0, ""
}
);
gemlines.push_back(
GemLine{
"(ENTER to navigate, mousewheel to scroll, Up/Down arrow keys to zoom)", 0, ""
}
);
for (int i=0; i<14; i++){
gemlines.push_back(
GemLine{
"", 0, ""
}
);
}
gemlines.push_back(
GemLine{
"-------------------------------", 0, ""
}
);
gemlines.push_back(
GemLine{
"attribution", 7, "piper://$pipette/attribution"
}
);
gemlines.push_back(
GemLine{
"about", 7, "piper://$pipette/about"
}
);
return gemlines;
}
std::vector<GemLine> attributionTextGen(){
std::vector<GemLine> gemlines;
gemlines.push_back(
GemLine{
"Pipette is (C) Luminoso 2021 / MIT License", 0, ""
}
);
gemlines.push_back(
GemLine{
"Pipette uses the kissnet library, which is under the MIT license", 0, ""
}
);
gemlines.push_back(
GemLine{
"(https://github.com/Ybalrid/kissnet)", 6, ""
}
);
gemlines.push_back(
GemLine{
"Pipette uses the Raylib library, which is under the Zlib license", 0, ""
}
);
gemlines.push_back(
GemLine{
"(https://github.com/raysan5/raylib)", 6, ""
}
);
gemlines.push_back(
GemLine{
"Pipette uses the Cascadia Code font, which is under the OFL1.1 license", 0, ""
}
);
gemlines.push_back(
GemLine{
"(https://github.com/microsoft/cascadia-code)", 6, ""
}
);
return gemlines;
}
std::vector<GemLine> parse(std::string input,bool ignoreformatdirectives){
std::vector<std::string> lines = util::split(input,std::string("\n"));
std::vector<GemLine> gemlines;
bool monomode = false;
for (std::string line:lines){
if (line.find("\r") != std::string::npos) {
line = line.replace(line.find("\r"), sizeof("\r") - 1, "");
}
if (ignoreformatdirectives){
gemlines.push_back(GemLine{
line, 0,""
});
continue;
}
if (line.starts_with("```")){
monomode = !monomode;
continue;
}
if (monomode){
gemlines.push_back(GemLine{
line, 4,""
});
continue;
}
if (line.starts_with("# ")){
gemlines.push_back(GemLine{
line.replace(line.find("# "), sizeof("# ") - 1, ""), 1,""
});
} else if (line.starts_with("## ")){
gemlines.push_back(GemLine{
line.replace(line.find("## "), sizeof("## ") - 1, ""), 2,""
});
} else if (line.starts_with("### ")){
gemlines.push_back(GemLine{
line.replace(line.find("### "), sizeof("### ") - 1, ""), 3,""
});
} else if (line.starts_with("> ")){
gemlines.push_back(GemLine{
line.replace(line.find("> "), sizeof("> ") - 1, ""), 6,""
});
} else if (line.starts_with("=> ")){
line = line.replace(line.find("=> "), sizeof("=> ") - 1, "");
std::vector<std::string> parts = util::split(line," ");
if (parts.size() <= 1){
gemlines.push_back(GemLine{
parts[0], 7, parts[0]
});
} else {
std::string target = parts[0];
parts.erase(parts.begin());
std::string collected = util::join(parts, ' ');
gemlines.push_back(GemLine{
collected, 7, target
});
}
} else {
gemlines.push_back(GemLine{
line, 0,""
});
}
}
return gemlines;
}
}
#endif //PIPETTE_GEMTXT_H