aboutsummaryrefslogtreecommitdiff
path: root/Compiler/src
diff options
context:
space:
mode:
Diffstat (limited to 'Compiler/src')
-rw-r--r--Compiler/src/compiler.cpp28
1 files changed, 28 insertions, 0 deletions
diff --git a/Compiler/src/compiler.cpp b/Compiler/src/compiler.cpp
index 7571fc2..89d06cd 100644
--- a/Compiler/src/compiler.cpp
+++ b/Compiler/src/compiler.cpp
@@ -11,3 +11,31 @@ static const std::regex REGEXES[] = {
static const char *REPLACEMENTS[] = {"<strong>$1</strong>", "<i>$1</i>",
"<u>$1</u>", "<s>$1</s>"};
+std::string compile_line(const char *raw)
+{
+ std::string result;
+ char *r;
+
+ if (raw[0] == '#')
+ {
+ // Get depth of header
+ int depth;
+ for (depth = 0; (*(raw + depth)) == '#'; ++depth);
+
+ asprintf(&r, "<h%d>%s</h%d>", depth, raw + depth, depth);
+ return r;
+ }
+ else if (raw[0] == '-')
+ {
+ asprintf(&r, "<li>%s</li>", raw + 1);
+ return r;
+ }
+
+ result = raw;
+ for (int i = 0; i < N_ITEMS; ++i)
+ {
+ result = std::regex_replace(result, REGEXES[i], REPLACEMENTS[i]);
+ }
+
+ return result;
+}