Stdin support

This commit is contained in:
2025-01-25 14:19:01 +01:00
parent d0697da15e
commit c0f5be662a
2 changed files with 42 additions and 14 deletions
+19 -7
View File
@@ -46,15 +46,15 @@ int is_keyword(const char *word) {
void highlight_code(const char *code) {
const char *ptr = code;
char buffer[256];
char buffer[4096];
size_t index = 0;
buffer[index] = 0;
while (*ptr) {
if ((*ptr >= 'a' && *ptr <= 'z') || (*ptr >= 'A' && *ptr <= 'Z') || (*ptr == '_')) {
while ((*ptr >= 'a' && *ptr <= 'z') || (*ptr >= 'A' && *ptr <= 'Z') || (*ptr >= '0' && *ptr <= '9') || (*ptr == '_')) {
buffer[index++] = *ptr++;
}
buffer[index] = '\0';
buffer[index] = 0;
if (is_keyword(buffer)) {
printf(FG_BLUE "%s" RESET, buffer);
@@ -66,7 +66,7 @@ void highlight_code(const char *code) {
while (*ptr >= '0' && *ptr <= '9') {
buffer[index++] = *ptr++;
}
buffer[index] = '\0';
buffer[index] = 0;
printf(FG_CYAN "%s" RESET, buffer);
index = 0;
} else {
@@ -93,14 +93,26 @@ void parse_markdown_to_ansi(const char *markdown) {
}
if (inside_code) {
char code_buffer[256];
char code_buffer[4096];
size_t index = 0;
while (*ptr && *ptr != '`') {
code_buffer[index++] = *ptr++;
if(*ptr == '\n' || *ptr == ' ' || *ptr == '\t' || *ptr == '.'){
code_buffer[index++] = 0;
highlight_code(code_buffer);
index = 0;
code_buffer[index] = 0;
}
}
code_buffer[index] = '\0';
highlight_code(code_buffer);
if(index > 0){
highlight_code(code_buffer);
index = 0;
code_buffer[index] = 0;
}
//code_buffer[index] = 0;
//highlight_code(code_buffer);
} else {
if (strncmp(ptr, "**", 2) == 0) {
printf(BOLD);