Refactor.

This commit is contained in:
2025-01-27 19:06:59 +01:00
parent 91598ce1ef
commit 35b53a586a
10 changed files with 235 additions and 291 deletions
+7 -8
View File
@@ -1,6 +1,6 @@
// Written by retoor@molodetz.nl
// This program provides functionality to highlight keywords in source code with ANSI color formatting and to convert Markdown syntax into ANSI-colored text output.
// This program provides functionality to highlight the keywords in source code using ANSI color formatting and convert Markdown syntax into ANSI-colored text output.
// Uses standard C libraries: <stdio.h>, <string.h>. Also utilizes ANSI escape codes for text formatting.
@@ -98,7 +98,7 @@ void parse_markdown_to_ansi(const char *markdown) {
while (*ptr && *ptr != '`') {
code_buffer[index++] = *ptr++;
if(*ptr == '\n' || *ptr == ' ' || *ptr == '\t' || *ptr == '.'){
if (*ptr == '\n' || *ptr == ' ' || *ptr == '\t' || *ptr == '.') {
code_buffer[index++] = 0;
highlight_code(code_buffer);
index = 0;
@@ -106,8 +106,9 @@ void parse_markdown_to_ansi(const char *markdown) {
}
}
code_buffer[index] = 0;
if(index)
if (index) {
highlight_code(code_buffer);
}
} else {
if (strncmp(ptr, "**", 2) == 0) {
printf(BOLD);
@@ -115,15 +116,13 @@ void parse_markdown_to_ansi(const char *markdown) {
while (*ptr && strncmp(ptr, "**", 2) != 0) putchar(*ptr++);
if (*ptr == '*' && *(ptr + 1) == '*') ptr += 2;
printf(RESET);
}
else if (*ptr == '*' && (ptr == markdown || *(ptr - 1) != '*')) {
} else if (*ptr == '*' && (ptr == markdown || *(ptr - 1) != '*')) {
printf(ITALIC);
ptr++;
while (*ptr && *ptr != '*') putchar(*ptr++);
if (*ptr == '*') ptr++;
printf(RESET);
}
else if (strncmp(ptr, "### ", 4) == 0) {
} else if (strncmp(ptr, "### ", 4) == 0) {
printf(BOLD FG_YELLOW);
ptr += 4;
while (*ptr && *ptr != '\n') putchar(*ptr++);
@@ -144,4 +143,4 @@ void parse_markdown_to_ansi(const char *markdown) {
}
}
}
}
}