diff --git a/src/gemparse.c b/src/gemparse.c index 1373993..768f29a 100644 --- a/src/gemparse.c +++ b/src/gemparse.c @@ -9,6 +9,7 @@ void addH1 (const char *line); void addH2 (const char *line); void addH3 (const char *line); void addLink (const char *url, const char *text); +void addCode (const char *meta, const char *code); // general functions @@ -104,6 +105,30 @@ parseFile (char *path) addLink (line + beginUrl, line + beginText); } } + else if (size > 3 && line[0] == '`' && line[1] == '`' && line[2] == '`') + { + char code[4096] = "", codeline[4096]; + + //Remove tailing '\n' for meta + line[size - 1] = '\0'; + + do + { + if (fgets(codeline, 4096, fileToParse) == NULL) + break; + + size = strlen(codeline); + if (size < 3 || codeline[0] != '`' || codeline[1] != '`' || codeline[2] != '`') + strcat(code, codeline); + } + while (codeline[0] != '`' || codeline[1] != '`' || codeline[2] != '`'); + + // Remove tailing '\n' for both meta and code + size = strlen(code); + code[size - 1] = '\0'; + + addCode (line + 3, code); + } else printf ("%s", line); } @@ -153,4 +178,13 @@ addLink (const char *url, printf ("link {\n%s\n%s\n}\n", url, text); } +void +addCode (const char *meta, + const char *code) +{ + int i = 0; + + printf ("code {\n%s\n%s\n}\n", meta, code); +} + #endif