-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathawesome_chatgpt_prompts.cpp
79 lines (67 loc) · 2.31 KB
/
awesome_chatgpt_prompts.cpp
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
#include "awesome_chatgpt_prompts.h"
AwesomeChatGptPrompts::AwesomeChatGptPrompts(QObject *parent)
: QObject(parent)
{
}
AwesomeChatGptPrompts::~AwesomeChatGptPrompts()
{
}
// TODO
struct MarkdownContent {
QString title;
QString author;
QString referenceUrl;
QString codeBlock;
};
void parseMarkdownFile(QString filePath)
{
QFile file(filePath);
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
return;
QTextStream in(&file);
QString line;
bool startParsing = false;
MarkdownContent content;
while (!in.atEnd()) {
line = in.readLine();
if (line.startsWith("# Prompts")) {
startParsing = true;
continue;
}
if (startParsing) {
if (line.startsWith("## ")) {
// found a new section, save the previous content
if (!content.title.isEmpty()) {
// do something with the extracted content
qDebug() << "Title:" << content.title;
qDebug() << "Author:" << content.author;
qDebug() << "Reference URL:" << content.referenceUrl;
qDebug() << "Code Block:" << content.codeBlock;
}
// start a new content section
content = MarkdownContent();
content.title = line.mid(3);
} else if (line.startsWith("Contributed by:")) {
content.author = line.mid(16, line.indexOf("]") - 16);
content.referenceUrl = line.mid(line.indexOf("(") + 1, line.indexOf(")") - line.indexOf("(") - 1);
} else if (line.startsWith("```")) {
// found a code block, extract the content
while (!in.atEnd()) {
line = in.readLine();
if (line.startsWith("```"))
break;
content.codeBlock += line + "\n";
}
}
}
}
// save the last content section
if (!content.title.isEmpty()) {
// do something with the extracted content
qDebug() << "Title:" << content.title;
qDebug() << "Author:" << content.author;
qDebug() << "Reference URL:" << content.referenceUrl;
qDebug() << "Code Block:" << content.codeBlock;
}
file.close();
}