diff options
author | dx <aryadevchavali1@gmail.com> | 2020-05-06 01:22:38 +0100 |
---|---|---|
committer | dx <aryadevchavali1@gmail.com> | 2020-05-06 01:40:12 +0100 |
commit | ed3a856000cd1a5d51e7046b635df41e0ead9c5a (patch) | |
tree | bc9a583a30a4065cded6b215e950f33be7379ae9 /Converter | |
parent | fd3923897595f2f6480dc4c11cca3f2238c91980 (diff) | |
download | mdhtml-ed3a856000cd1a5d51e7046b635df41e0ead9c5a.tar.gz mdhtml-ed3a856000cd1a5d51e7046b635df41e0ead9c5a.tar.bz2 mdhtml-ed3a856000cd1a5d51e7046b635df41e0ead9c5a.zip |
+compile_line function, can turn '#' -> <h1>
compile_line is the main function which compiles a single line in C.
Similar to the stage of compilation in the python program.
Currently supports header tags
Diffstat (limited to 'Converter')
-rw-r--r-- | Converter/src/main.c | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/Converter/src/main.c b/Converter/src/main.c index 765469b..b512929 100644 --- a/Converter/src/main.c +++ b/Converter/src/main.c @@ -1,7 +1,34 @@ +#include <malloc.h> #include <stdio.h> +#include <string.h> typedef char *string; +string compile_line(string line, size_t size_of_line) +{ + string compiled_line; + if (line[0] == '#') + { + // title + // allocate buffer with extra 9 characters for the tags + compiled_line = malloc(sizeof(*compiled_line) * (size_of_line + 9)); + // write h1 to start of compiled_line + strncpy(compiled_line, "<h1>", 4); + // write the rest of the line to the compiled_line + strncpy(compiled_line + 4, line + 1, size_of_line - 1); + // write the end tags + strncpy(compiled_line + size_of_line + 3, "</h1>", 5); + } + + else + { + compiled_line = malloc(sizeof(*compiled_line) * size_of_line); + strncpy(compiled_line, line, size_of_line); + } + + return compiled_line; +} + int main() { return 0; |