Implement verbatim

This commit is contained in:
bʰedoh₂ swé 2024-06-11 18:00:16 +05:00
parent c543c00a9c
commit c8189f5ec1

View File

@ -13,6 +13,31 @@ void string_append(char** string, char* append) {
}
void string_append_char(char** string, char append) {
int len = strlen(*string);
*string = realloc(*string, len + 2 * sizeof(char));
string[0][len] = append;
string[0][len + 1] = '\0';
}
char* string_unescape(char* string) {
char* tmp = calloc(1,sizeof(char));
size_t len = strlen(string);
for (size_t i = 0; i < len; i++) {
if (string[i] == '\\')
i++;
string_append_char(&tmp, string[i]);
}
return tmp;
}
void string_append_free(char** string, char* append) {
string_append(string, append);
free(append);
@ -342,6 +367,22 @@ char* compile(tSyntaxElement* syntaxtree) {
}
} else if (strcmp(token->content.string, "verbatim") == 0) {
compile_enter_tag(&result);
string_append(&result, "verbatim");
compile_exit_tag(&result);
for(tSyntaxElement* i = token->next; i != NULL; i = i->next) {
string_append_free(&result,string_unescape(i->content.string));
}
compile_enter_tag(&result);
string_append(&result, " endverbatim");
compile_exit_tag(&result);
} else {
string_append(&result, "{#");