Mercurial
annotate markdown_converter/markdown_to_html.c @ 216:e82b80b24012 default tip
[MrJuneJune] Make webp translate background job.
| author | June Park <parkjune1995@gmail.com> |
|---|---|
| date | Sat, 28 Feb 2026 21:04:43 -0800 |
| parents | a2725419f988 |
| children |
| rev | line source |
|---|---|
|
154
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
1 #include <string.h> |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
2 #include <stdlib.h> |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
3 #include <stdio.h> |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
4 #include <ctype.h> |
|
158
1c0878eb17de
[MrJuneJune] Readme file gets compiled in server side.
June Park <parkjune1995@gmail.com>
parents:
156
diff
changeset
|
5 #include "markdown_converter/markdown_to_html.h" |
|
154
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
6 |
|
184
8c74204fd362
[MD to HTML] Updated so it can be used through readme to html
MrJuneJune <me@mrjunejune.com>
parents:
158
diff
changeset
|
7 // JavaScript needs this to free the memory later |
|
8c74204fd362
[MD to HTML] Updated so it can be used through readme to html
MrJuneJune <me@mrjunejune.com>
parents:
158
diff
changeset
|
8 MDAPI void *wasm_alloc(size_t size) { |
|
8c74204fd362
[MD to HTML] Updated so it can be used through readme to html
MrJuneJune <me@mrjunejune.com>
parents:
158
diff
changeset
|
9 return malloc(size); |
|
8c74204fd362
[MD to HTML] Updated so it can be used through readme to html
MrJuneJune <me@mrjunejune.com>
parents:
158
diff
changeset
|
10 } |
|
8c74204fd362
[MD to HTML] Updated so it can be used through readme to html
MrJuneJune <me@mrjunejune.com>
parents:
158
diff
changeset
|
11 |
|
8c74204fd362
[MD to HTML] Updated so it can be used through readme to html
MrJuneJune <me@mrjunejune.com>
parents:
158
diff
changeset
|
12 MDAPI void wasm_free(void* ptr) { |
|
8c74204fd362
[MD to HTML] Updated so it can be used through readme to html
MrJuneJune <me@mrjunejune.com>
parents:
158
diff
changeset
|
13 free(ptr); |
|
8c74204fd362
[MD to HTML] Updated so it can be used through readme to html
MrJuneJune <me@mrjunejune.com>
parents:
158
diff
changeset
|
14 } |
|
8c74204fd362
[MD to HTML] Updated so it can be used through readme to html
MrJuneJune <me@mrjunejune.com>
parents:
158
diff
changeset
|
15 |
|
158
1c0878eb17de
[MrJuneJune] Readme file gets compiled in server side.
June Park <parkjune1995@gmail.com>
parents:
156
diff
changeset
|
16 #define INITIAL_BUFFER_SIZE 1024 * 1024 // 1MB |
|
154
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
17 |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
18 // String buffer for building HTML output |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
19 typedef struct { |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
20 char *data; |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
21 size_t length; |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
22 size_t capacity; |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
23 } StringBuffer; |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
24 |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
25 static StringBuffer *buffer_create(size_t initial_capacity) |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
26 { |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
27 StringBuffer *buf = (StringBuffer *)malloc(sizeof(StringBuffer)); |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
28 if (!buf) return NULL; |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
29 |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
30 buf->data = (char *)malloc(initial_capacity); |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
31 if (!buf->data) { |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
32 free(buf); |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
33 return NULL; |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
34 } |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
35 buf->data[0] = '\0'; |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
36 buf->length = 0; |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
37 buf->capacity = initial_capacity; |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
38 return buf; |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
39 } |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
40 |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
41 static void buffer_grow(StringBuffer *buf, size_t needed) |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
42 { |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
43 if (buf->length + needed + 1 > buf->capacity) { |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
44 size_t new_capacity = buf->capacity * 2; |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
45 while (new_capacity < buf->length + needed + 1) |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
46 new_capacity *= 2; |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
47 |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
48 char *new_data = (char *)realloc(buf->data, new_capacity); |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
49 if (new_data) { |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
50 buf->data = new_data; |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
51 buf->capacity = new_capacity; |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
52 } |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
53 } |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
54 } |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
55 |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
56 static void buffer_append(StringBuffer *buf, const char *str) |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
57 { |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
58 size_t len = strlen(str); |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
59 buffer_grow(buf, len); |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
60 memcpy(buf->data + buf->length, str, len + 1); |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
61 buf->length += len; |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
62 } |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
63 |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
64 static void buffer_append_n(StringBuffer *buf, const char *str, size_t n) |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
65 { |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
66 buffer_grow(buf, n); |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
67 memcpy(buf->data + buf->length, str, n); |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
68 buf->length += n; |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
69 buf->data[buf->length] = '\0'; |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
70 } |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
71 |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
72 static void buffer_append_char(StringBuffer *buf, char c) |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
73 { |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
74 buffer_grow(buf, 1); |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
75 buf->data[buf->length++] = c; |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
76 buf->data[buf->length] = '\0'; |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
77 } |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
78 |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
79 static void buffer_free(StringBuffer *buf) |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
80 { |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
81 if (buf) { |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
82 free(buf->data); |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
83 free(buf); |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
84 } |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
85 } |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
86 |
|
190
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
87 // Forward declaration |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
88 static void process_inline(StringBuffer *buf, const char *text, size_t len); |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
89 |
|
154
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
90 // Check if line starts with pattern (after trimming whitespace) |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
91 static int starts_with(const char *line, const char *pattern) |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
92 { |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
93 while (*line && isspace((unsigned char)*line)) line++; |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
94 return strncmp(line, pattern, strlen(pattern)) == 0; |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
95 } |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
96 |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
97 // Count leading # characters |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
98 static int count_heading_level(const char *line) |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
99 { |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
100 int count = 0; |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
101 while (*line && isspace((unsigned char)*line)) line++; |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
102 while (line[count] == '#' && count < 6) count++; |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
103 if (count > 0 && line[count] == ' ') return count; |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
104 return 0; |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
105 } |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
106 |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
107 // Skip whitespace |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
108 static const char *skip_whitespace(const char *str) |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
109 { |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
110 while (*str && isspace((unsigned char)*str)) str++; |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
111 return str; |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
112 } |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
113 |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
114 // Check if line is empty (only whitespace) |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
115 static int is_empty_line(const char *line) |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
116 { |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
117 while (*line) { |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
118 if (!isspace((unsigned char)*line)) return 0; |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
119 line++; |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
120 } |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
121 return 1; |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
122 } |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
123 |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
124 // Check if line is horizontal rule (---, ***, ___) |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
125 static int is_horizontal_rule(const char *line) |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
126 { |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
127 line = skip_whitespace(line); |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
128 char first = *line; |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
129 if (first != '-' && first != '*' && first != '_') return 0; |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
130 |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
131 int count = 0; |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
132 while (*line) { |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
133 if (*line == first) count++; |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
134 else if (!isspace((unsigned char)*line)) return 0; |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
135 line++; |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
136 } |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
137 return count >= 3; |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
138 } |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
139 |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
140 // Check if line is unordered list item |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
141 static int is_unordered_list(const char *line) |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
142 { |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
143 line = skip_whitespace(line); |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
144 return (*line == '-' || *line == '*' || *line == '+') && line[1] == ' '; |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
145 } |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
146 |
|
184
8c74204fd362
[MD to HTML] Updated so it can be used through readme to html
MrJuneJune <me@mrjunejune.com>
parents:
158
diff
changeset
|
147 // Check if line starts with an HTML tag |
|
8c74204fd362
[MD to HTML] Updated so it can be used through readme to html
MrJuneJune <me@mrjunejune.com>
parents:
158
diff
changeset
|
148 static int is_html_block_start(const char *line) |
|
8c74204fd362
[MD to HTML] Updated so it can be used through readme to html
MrJuneJune <me@mrjunejune.com>
parents:
158
diff
changeset
|
149 { |
|
8c74204fd362
[MD to HTML] Updated so it can be used through readme to html
MrJuneJune <me@mrjunejune.com>
parents:
158
diff
changeset
|
150 line = skip_whitespace(line); |
|
8c74204fd362
[MD to HTML] Updated so it can be used through readme to html
MrJuneJune <me@mrjunejune.com>
parents:
158
diff
changeset
|
151 if (*line != '<') return 0; |
|
8c74204fd362
[MD to HTML] Updated so it can be used through readme to html
MrJuneJune <me@mrjunejune.com>
parents:
158
diff
changeset
|
152 line++; |
|
8c74204fd362
[MD to HTML] Updated so it can be used through readme to html
MrJuneJune <me@mrjunejune.com>
parents:
158
diff
changeset
|
153 |
|
8c74204fd362
[MD to HTML] Updated so it can be used through readme to html
MrJuneJune <me@mrjunejune.com>
parents:
158
diff
changeset
|
154 // Check for closing tag or comment |
|
8c74204fd362
[MD to HTML] Updated so it can be used through readme to html
MrJuneJune <me@mrjunejune.com>
parents:
158
diff
changeset
|
155 if (*line == '/' || *line == '!') return 1; |
|
8c74204fd362
[MD to HTML] Updated so it can be used through readme to html
MrJuneJune <me@mrjunejune.com>
parents:
158
diff
changeset
|
156 |
|
8c74204fd362
[MD to HTML] Updated so it can be used through readme to html
MrJuneJune <me@mrjunejune.com>
parents:
158
diff
changeset
|
157 // Check for valid tag name (letter followed by alphanumeric) |
|
8c74204fd362
[MD to HTML] Updated so it can be used through readme to html
MrJuneJune <me@mrjunejune.com>
parents:
158
diff
changeset
|
158 if (!isalpha((unsigned char)*line)) return 0; |
|
8c74204fd362
[MD to HTML] Updated so it can be used through readme to html
MrJuneJune <me@mrjunejune.com>
parents:
158
diff
changeset
|
159 |
|
8c74204fd362
[MD to HTML] Updated so it can be used through readme to html
MrJuneJune <me@mrjunejune.com>
parents:
158
diff
changeset
|
160 return 1; |
|
8c74204fd362
[MD to HTML] Updated so it can be used through readme to html
MrJuneJune <me@mrjunejune.com>
parents:
158
diff
changeset
|
161 } |
|
8c74204fd362
[MD to HTML] Updated so it can be used through readme to html
MrJuneJune <me@mrjunejune.com>
parents:
158
diff
changeset
|
162 |
|
8c74204fd362
[MD to HTML] Updated so it can be used through readme to html
MrJuneJune <me@mrjunejune.com>
parents:
158
diff
changeset
|
163 // Check if line starts with a specific HTML tag (e.g., "script", "style") |
|
8c74204fd362
[MD to HTML] Updated so it can be used through readme to html
MrJuneJune <me@mrjunejune.com>
parents:
158
diff
changeset
|
164 static int is_html_tag(const char *line, const char *tag) |
|
8c74204fd362
[MD to HTML] Updated so it can be used through readme to html
MrJuneJune <me@mrjunejune.com>
parents:
158
diff
changeset
|
165 { |
|
8c74204fd362
[MD to HTML] Updated so it can be used through readme to html
MrJuneJune <me@mrjunejune.com>
parents:
158
diff
changeset
|
166 line = skip_whitespace(line); |
|
8c74204fd362
[MD to HTML] Updated so it can be used through readme to html
MrJuneJune <me@mrjunejune.com>
parents:
158
diff
changeset
|
167 if (*line != '<') return 0; |
|
8c74204fd362
[MD to HTML] Updated so it can be used through readme to html
MrJuneJune <me@mrjunejune.com>
parents:
158
diff
changeset
|
168 line++; |
|
8c74204fd362
[MD to HTML] Updated so it can be used through readme to html
MrJuneJune <me@mrjunejune.com>
parents:
158
diff
changeset
|
169 |
|
8c74204fd362
[MD to HTML] Updated so it can be used through readme to html
MrJuneJune <me@mrjunejune.com>
parents:
158
diff
changeset
|
170 // Skip optional / |
|
8c74204fd362
[MD to HTML] Updated so it can be used through readme to html
MrJuneJune <me@mrjunejune.com>
parents:
158
diff
changeset
|
171 int is_closing = 0; |
|
8c74204fd362
[MD to HTML] Updated so it can be used through readme to html
MrJuneJune <me@mrjunejune.com>
parents:
158
diff
changeset
|
172 if (*line == '/') { |
|
8c74204fd362
[MD to HTML] Updated so it can be used through readme to html
MrJuneJune <me@mrjunejune.com>
parents:
158
diff
changeset
|
173 is_closing = 1; |
|
8c74204fd362
[MD to HTML] Updated so it can be used through readme to html
MrJuneJune <me@mrjunejune.com>
parents:
158
diff
changeset
|
174 line++; |
|
8c74204fd362
[MD to HTML] Updated so it can be used through readme to html
MrJuneJune <me@mrjunejune.com>
parents:
158
diff
changeset
|
175 } |
|
8c74204fd362
[MD to HTML] Updated so it can be used through readme to html
MrJuneJune <me@mrjunejune.com>
parents:
158
diff
changeset
|
176 |
|
8c74204fd362
[MD to HTML] Updated so it can be used through readme to html
MrJuneJune <me@mrjunejune.com>
parents:
158
diff
changeset
|
177 size_t tag_len = strlen(tag); |
|
8c74204fd362
[MD to HTML] Updated so it can be used through readme to html
MrJuneJune <me@mrjunejune.com>
parents:
158
diff
changeset
|
178 if (strncasecmp(line, tag, tag_len) != 0) return 0; |
|
8c74204fd362
[MD to HTML] Updated so it can be used through readme to html
MrJuneJune <me@mrjunejune.com>
parents:
158
diff
changeset
|
179 |
|
8c74204fd362
[MD to HTML] Updated so it can be used through readme to html
MrJuneJune <me@mrjunejune.com>
parents:
158
diff
changeset
|
180 char next = line[tag_len]; |
|
8c74204fd362
[MD to HTML] Updated so it can be used through readme to html
MrJuneJune <me@mrjunejune.com>
parents:
158
diff
changeset
|
181 // Tag must be followed by space, >, or end for closing tags |
|
8c74204fd362
[MD to HTML] Updated so it can be used through readme to html
MrJuneJune <me@mrjunejune.com>
parents:
158
diff
changeset
|
182 return next == '>' || next == ' ' || next == '\t' || next == '\n' || next == '\0'; |
|
8c74204fd362
[MD to HTML] Updated so it can be used through readme to html
MrJuneJune <me@mrjunejune.com>
parents:
158
diff
changeset
|
183 } |
|
8c74204fd362
[MD to HTML] Updated so it can be used through readme to html
MrJuneJune <me@mrjunejune.com>
parents:
158
diff
changeset
|
184 |
|
154
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
185 // Check if line is ordered list item |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
186 static int is_ordered_list(const char *line) |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
187 { |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
188 line = skip_whitespace(line); |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
189 while (*line && isdigit((unsigned char)*line)) line++; |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
190 return *line == '.' && line[1] == ' '; |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
191 } |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
192 |
|
190
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
193 // Check if line could be a table row (contains |) |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
194 static int is_table_row(const char *line) |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
195 { |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
196 line = skip_whitespace(line); |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
197 // Must contain at least one | |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
198 return strchr(line, '|') != NULL; |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
199 } |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
200 |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
201 // Check if line is a table separator (|---|---|) |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
202 static int is_table_separator(const char *line) |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
203 { |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
204 line = skip_whitespace(line); |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
205 int has_dash = 0; |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
206 int has_pipe = 0; |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
207 |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
208 while (*line) { |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
209 char c = *line; |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
210 if (c == '|') has_pipe = 1; |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
211 else if (c == '-') has_dash = 1; |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
212 else if (c == ':') ; // alignment marker, allowed |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
213 else if (isspace((unsigned char)c)) ; // whitespace allowed |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
214 else return 0; // invalid character for separator |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
215 line++; |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
216 } |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
217 |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
218 return has_dash && has_pipe; |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
219 } |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
220 |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
221 // Parse alignment from separator cell (e.g., ":---:", "---:", ":---") |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
222 // Returns: 0 = left (default), 1 = center, 2 = right |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
223 static int parse_alignment(const char *cell, size_t len) |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
224 { |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
225 // Trim whitespace |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
226 while (len > 0 && isspace((unsigned char)*cell)) { cell++; len--; } |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
227 while (len > 0 && isspace((unsigned char)cell[len-1])) { len--; } |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
228 |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
229 if (len == 0) return 0; |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
230 |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
231 int left_colon = (cell[0] == ':'); |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
232 int right_colon = (len > 0 && cell[len-1] == ':'); |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
233 |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
234 if (left_colon && right_colon) return 1; // center |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
235 if (right_colon) return 2; // right |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
236 return 0; // left (default) |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
237 } |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
238 |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
239 // Count columns in a table row |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
240 static int count_table_columns(const char *line) |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
241 { |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
242 int count = 0; |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
243 int in_cell = 0; |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
244 line = skip_whitespace(line); |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
245 |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
246 // Skip leading | |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
247 if (*line == '|') line++; |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
248 |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
249 while (*line) { |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
250 if (*line == '|') { |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
251 count++; |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
252 in_cell = 0; |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
253 } else if (!isspace((unsigned char)*line)) { |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
254 in_cell = 1; |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
255 } |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
256 line++; |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
257 } |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
258 |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
259 // Count last cell if there was content after last | |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
260 if (in_cell) count++; |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
261 |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
262 return count > 0 ? count : 1; |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
263 } |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
264 |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
265 // Parse table cells and call callback for each |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
266 typedef void (*cell_callback)(StringBuffer *buf, const char *cell, size_t len, int align, int is_header); |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
267 |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
268 static void parse_table_row(StringBuffer *buf, const char *line, int *alignments, int num_cols, int is_header, cell_callback cb) |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
269 { |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
270 line = skip_whitespace(line); |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
271 |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
272 // Skip leading | |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
273 if (*line == '|') line++; |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
274 |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
275 int col = 0; |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
276 const char *cell_start = line; |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
277 |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
278 while (*line && col < num_cols) { |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
279 if (*line == '|' || *(line + 1) == '\0') { |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
280 // End of cell |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
281 size_t cell_len = line - cell_start; |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
282 if (*line != '|') cell_len++; // include last char if no trailing | |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
283 |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
284 // Trim whitespace from cell |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
285 while (cell_len > 0 && isspace((unsigned char)*cell_start)) { cell_start++; cell_len--; } |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
286 while (cell_len > 0 && isspace((unsigned char)cell_start[cell_len-1])) { cell_len--; } |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
287 |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
288 int align = (alignments && col < num_cols) ? alignments[col] : 0; |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
289 cb(buf, cell_start, cell_len, align, is_header); |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
290 |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
291 col++; |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
292 cell_start = line + 1; |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
293 } |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
294 line++; |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
295 } |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
296 |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
297 // Fill remaining columns with empty cells |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
298 while (col < num_cols) { |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
299 cb(buf, "", 0, alignments ? alignments[col] : 0, is_header); |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
300 col++; |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
301 } |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
302 } |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
303 |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
304 static void emit_table_cell(StringBuffer *buf, const char *cell, size_t len, int align, int is_header) |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
305 { |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
306 const char *tag = is_header ? "th" : "td"; |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
307 const char *align_attr = ""; |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
308 |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
309 if (align == 1) align_attr = " style=\"text-align:center\""; |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
310 else if (align == 2) align_attr = " style=\"text-align:right\""; |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
311 |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
312 buffer_append(buf, "<"); |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
313 buffer_append(buf, tag); |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
314 buffer_append(buf, align_attr); |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
315 buffer_append(buf, ">"); |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
316 process_inline(buf, cell, len); |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
317 buffer_append(buf, "</"); |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
318 buffer_append(buf, tag); |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
319 buffer_append(buf, ">"); |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
320 } |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
321 |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
322 // Parse alignments from separator row |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
323 static void parse_alignments(const char *line, int *alignments, int num_cols) |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
324 { |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
325 line = skip_whitespace(line); |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
326 if (*line == '|') line++; |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
327 |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
328 int col = 0; |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
329 const char *cell_start = line; |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
330 |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
331 while (*line && col < num_cols) { |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
332 if (*line == '|' || *(line + 1) == '\0') { |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
333 size_t cell_len = line - cell_start; |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
334 if (*line != '|') cell_len++; |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
335 |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
336 alignments[col] = parse_alignment(cell_start, cell_len); |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
337 col++; |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
338 cell_start = line + 1; |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
339 } |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
340 line++; |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
341 } |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
342 } |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
343 |
|
154
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
344 // Process inline markdown (bold, italic, code, links, strikethrough) |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
345 static void process_inline(StringBuffer *buf, const char *text, size_t len) |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
346 { |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
347 size_t i = 0; |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
348 |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
349 while (i < len) { |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
350 // Links: [text](url) |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
351 if (text[i] == '[') { |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
352 size_t link_start = i + 1; |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
353 size_t link_end = link_start; |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
354 while (link_end < len && text[link_end] != ']') link_end++; |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
355 |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
356 if (link_end < len && link_end + 1 < len && text[link_end + 1] == '(') { |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
357 size_t url_start = link_end + 2; |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
358 size_t url_end = url_start; |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
359 while (url_end < len && text[url_end] != ')') url_end++; |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
360 |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
361 if (url_end < len) { |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
362 buffer_append(buf, "<a href=\""); |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
363 buffer_append_n(buf, text + url_start, url_end - url_start); |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
364 buffer_append(buf, "\">"); |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
365 buffer_append_n(buf, text + link_start, link_end - link_start); |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
366 buffer_append(buf, "</a>"); |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
367 i = url_end + 1; |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
368 continue; |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
369 } |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
370 } |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
371 } |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
372 |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
373 // Images:  |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
374 if (text[i] == '!' && i + 1 < len && text[i + 1] == '[') { |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
375 size_t alt_start = i + 2; |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
376 size_t alt_end = alt_start; |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
377 while (alt_end < len && text[alt_end] != ']') alt_end++; |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
378 |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
379 if (alt_end < len && alt_end + 1 < len && text[alt_end + 1] == '(') { |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
380 size_t url_start = alt_end + 2; |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
381 size_t url_end = url_start; |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
382 while (url_end < len && text[url_end] != ')') url_end++; |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
383 |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
384 if (url_end < len) { |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
385 buffer_append(buf, "<img src=\""); |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
386 buffer_append_n(buf, text + url_start, url_end - url_start); |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
387 buffer_append(buf, "\" alt=\""); |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
388 buffer_append_n(buf, text + alt_start, alt_end - alt_start); |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
389 buffer_append(buf, "\">"); |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
390 i = url_end + 1; |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
391 continue; |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
392 } |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
393 } |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
394 } |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
395 |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
396 // Bold: **text** or __text__ |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
397 if ((text[i] == '*' && i + 1 < len && text[i + 1] == '*') || |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
398 (text[i] == '_' && i + 1 < len && text[i + 1] == '_')) { |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
399 char marker = text[i]; |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
400 size_t start = i + 2; |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
401 size_t end = start; |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
402 while (end + 1 < len && !(text[end] == marker && text[end + 1] == marker)) end++; |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
403 |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
404 if (end + 1 < len) { |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
405 buffer_append(buf, "<strong>"); |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
406 process_inline(buf, text + start, end - start); |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
407 buffer_append(buf, "</strong>"); |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
408 i = end + 2; |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
409 continue; |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
410 } |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
411 } |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
412 |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
413 // Strikethrough: ~~text~~ |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
414 if (text[i] == '~' && i + 1 < len && text[i + 1] == '~') { |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
415 size_t start = i + 2; |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
416 size_t end = start; |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
417 while (end + 1 < len && !(text[end] == '~' && text[end + 1] == '~')) end++; |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
418 |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
419 if (end + 1 < len) { |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
420 buffer_append(buf, "<del>"); |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
421 process_inline(buf, text + start, end - start); |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
422 buffer_append(buf, "</del>"); |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
423 i = end + 2; |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
424 continue; |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
425 } |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
426 } |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
427 |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
428 // Italic: *text* or _text_ |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
429 if ((text[i] == '*' || text[i] == '_') && i + 1 < len && !isspace((unsigned char)text[i + 1])) { |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
430 char marker = text[i]; |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
431 size_t start = i + 1; |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
432 size_t end = start; |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
433 while (end < len && text[end] != marker) end++; |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
434 |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
435 if (end < len && end > start) { |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
436 buffer_append(buf, "<em>"); |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
437 process_inline(buf, text + start, end - start); |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
438 buffer_append(buf, "</em>"); |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
439 i = end + 1; |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
440 continue; |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
441 } |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
442 } |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
443 |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
444 // Inline code: `code` |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
445 if (text[i] == '`') { |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
446 size_t start = i + 1; |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
447 size_t end = start; |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
448 while (end < len && text[end] != '`') end++; |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
449 |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
450 if (end < len) { |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
451 buffer_append(buf, "<code>"); |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
452 buffer_append_n(buf, text + start, end - start); |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
453 buffer_append(buf, "</code>"); |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
454 i = end + 1; |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
455 continue; |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
456 } |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
457 } |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
458 |
|
158
1c0878eb17de
[MrJuneJune] Readme file gets compiled in server side.
June Park <parkjune1995@gmail.com>
parents:
156
diff
changeset
|
459 // This might not be needed for now. |
|
154
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
460 // HTML escape special characters |
|
158
1c0878eb17de
[MrJuneJune] Readme file gets compiled in server side.
June Park <parkjune1995@gmail.com>
parents:
156
diff
changeset
|
461 // if (text[i] == '<') { |
|
1c0878eb17de
[MrJuneJune] Readme file gets compiled in server side.
June Park <parkjune1995@gmail.com>
parents:
156
diff
changeset
|
462 // buffer_append(buf, "<"); |
|
1c0878eb17de
[MrJuneJune] Readme file gets compiled in server side.
June Park <parkjune1995@gmail.com>
parents:
156
diff
changeset
|
463 // } else if (text[i] == '>') { |
|
1c0878eb17de
[MrJuneJune] Readme file gets compiled in server side.
June Park <parkjune1995@gmail.com>
parents:
156
diff
changeset
|
464 // buffer_append(buf, ">"); |
|
1c0878eb17de
[MrJuneJune] Readme file gets compiled in server side.
June Park <parkjune1995@gmail.com>
parents:
156
diff
changeset
|
465 // } else if (text[i] == '&') { |
|
1c0878eb17de
[MrJuneJune] Readme file gets compiled in server side.
June Park <parkjune1995@gmail.com>
parents:
156
diff
changeset
|
466 // buffer_append(buf, "&"); |
|
1c0878eb17de
[MrJuneJune] Readme file gets compiled in server side.
June Park <parkjune1995@gmail.com>
parents:
156
diff
changeset
|
467 // } else { |
|
1c0878eb17de
[MrJuneJune] Readme file gets compiled in server side.
June Park <parkjune1995@gmail.com>
parents:
156
diff
changeset
|
468 // buffer_append_char(buf, text[i]); |
|
1c0878eb17de
[MrJuneJune] Readme file gets compiled in server side.
June Park <parkjune1995@gmail.com>
parents:
156
diff
changeset
|
469 // } |
|
1c0878eb17de
[MrJuneJune] Readme file gets compiled in server side.
June Park <parkjune1995@gmail.com>
parents:
156
diff
changeset
|
470 buffer_append_char(buf, text[i]); |
|
154
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
471 i++; |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
472 } |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
473 } |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
474 |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
475 // Convert markdown to HTML |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
476 MDAPI char *markdown_to_html(const char *markdown) |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
477 { |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
478 if (!markdown) return NULL; |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
479 |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
480 StringBuffer *buf = buffer_create(INITIAL_BUFFER_SIZE); |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
481 if (!buf) return NULL; |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
482 |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
483 const char *ptr = markdown; |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
484 const char *line_start; |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
485 |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
486 while (*ptr) { |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
487 line_start = ptr; |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
488 |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
489 // Find end of line |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
490 while (*ptr && *ptr != '\n') ptr++; |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
491 size_t line_len = ptr - line_start; |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
492 |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
493 // Create null-terminated line copy |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
494 char *line = (char *)malloc(line_len + 1); |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
495 if (!line) { |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
496 buffer_free(buf); |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
497 return NULL; |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
498 } |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
499 memcpy(line, line_start, line_len); |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
500 line[line_len] = '\0'; |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
501 |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
502 // Skip empty lines |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
503 if (is_empty_line(line)) { |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
504 free(line); |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
505 if (*ptr == '\n') ptr++; |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
506 continue; |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
507 } |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
508 |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
509 // Headings: # H1, ## H2, etc. |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
510 int heading_level = count_heading_level(line); |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
511 if (heading_level > 0) { |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
512 const char *content = skip_whitespace(line); |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
513 while (*content == '#') content++; |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
514 content = skip_whitespace(content); |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
515 |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
516 char tag[8]; |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
517 snprintf(tag, sizeof(tag), "<h%d>", heading_level); |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
518 buffer_append(buf, tag); |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
519 process_inline(buf, content, strlen(content)); |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
520 snprintf(tag, sizeof(tag), "</h%d>", heading_level); |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
521 buffer_append(buf, tag); |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
522 |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
523 free(line); |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
524 if (*ptr == '\n') ptr++; |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
525 continue; |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
526 } |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
527 |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
528 // Code block: ``` |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
529 if (starts_with(line, "```")) { |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
530 buffer_append(buf, "<pre><code>"); |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
531 free(line); |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
532 if (*ptr == '\n') ptr++; |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
533 |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
534 // Collect code content |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
535 while (*ptr) { |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
536 line_start = ptr; |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
537 while (*ptr && *ptr != '\n') ptr++; |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
538 line_len = ptr - line_start; |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
539 |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
540 line = (char *)malloc(line_len + 1); |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
541 if (!line) break; |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
542 memcpy(line, line_start, line_len); |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
543 line[line_len] = '\0'; |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
544 |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
545 if (starts_with(line, "```")) { |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
546 free(line); |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
547 if (*ptr == '\n') ptr++; |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
548 break; |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
549 } |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
550 |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
551 // Escape HTML in code blocks |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
552 for (size_t i = 0; i < line_len; i++) { |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
553 if (line[i] == '<') buffer_append(buf, "<"); |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
554 else if (line[i] == '>') buffer_append(buf, ">"); |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
555 else if (line[i] == '&') buffer_append(buf, "&"); |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
556 else buffer_append_char(buf, line[i]); |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
557 } |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
558 buffer_append_char(buf, '\n'); |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
559 |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
560 free(line); |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
561 if (*ptr == '\n') ptr++; |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
562 } |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
563 |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
564 buffer_append(buf, "</code></pre>"); |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
565 continue; |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
566 } |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
567 |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
568 // Blockquote: > |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
569 if (starts_with(line, ">")) { |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
570 buffer_append(buf, "<blockquote>"); |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
571 |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
572 while (1) { |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
573 const char *content = skip_whitespace(line); |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
574 if (*content == '>') content++; |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
575 content = skip_whitespace(content); |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
576 process_inline(buf, content, strlen(content)); |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
577 buffer_append_char(buf, ' '); |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
578 |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
579 free(line); |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
580 if (*ptr == '\n') ptr++; |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
581 |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
582 // Check next line |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
583 if (!*ptr) break; |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
584 line_start = ptr; |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
585 while (*ptr && *ptr != '\n') ptr++; |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
586 line_len = ptr - line_start; |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
587 |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
588 line = (char *)malloc(line_len + 1); |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
589 if (!line) break; |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
590 memcpy(line, line_start, line_len); |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
591 line[line_len] = '\0'; |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
592 |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
593 if (!starts_with(line, ">")) { |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
594 // Put back the line pointer |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
595 ptr = line_start; |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
596 free(line); |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
597 break; |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
598 } |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
599 } |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
600 |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
601 buffer_append(buf, "</blockquote>"); |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
602 continue; |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
603 } |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
604 |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
605 // Horizontal rule |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
606 if (is_horizontal_rule(line)) { |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
607 buffer_append(buf, "<hr>"); |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
608 free(line); |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
609 if (*ptr == '\n') ptr++; |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
610 continue; |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
611 } |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
612 |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
613 // Unordered list |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
614 if (is_unordered_list(line)) { |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
615 buffer_append(buf, "<ul>"); |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
616 |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
617 while (1) { |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
618 const char *content = skip_whitespace(line); |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
619 content += 2; // Skip "- " or "* " or "+ " |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
620 |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
621 buffer_append(buf, "<li>"); |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
622 process_inline(buf, content, strlen(content)); |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
623 buffer_append(buf, "</li>"); |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
624 |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
625 free(line); |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
626 if (*ptr == '\n') ptr++; |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
627 |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
628 // Check next line |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
629 if (!*ptr) break; |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
630 line_start = ptr; |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
631 while (*ptr && *ptr != '\n') ptr++; |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
632 line_len = ptr - line_start; |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
633 |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
634 line = (char *)malloc(line_len + 1); |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
635 if (!line) break; |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
636 memcpy(line, line_start, line_len); |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
637 line[line_len] = '\0'; |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
638 |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
639 if (!is_unordered_list(line)) { |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
640 ptr = line_start; |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
641 free(line); |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
642 break; |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
643 } |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
644 } |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
645 |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
646 buffer_append(buf, "</ul>"); |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
647 continue; |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
648 } |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
649 |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
650 // Ordered list |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
651 if (is_ordered_list(line)) { |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
652 buffer_append(buf, "<ol>"); |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
653 |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
654 while (1) { |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
655 const char *content = skip_whitespace(line); |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
656 while (*content && isdigit((unsigned char)*content)) content++; |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
657 if (*content == '.') content++; |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
658 content = skip_whitespace(content); |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
659 |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
660 buffer_append(buf, "<li>"); |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
661 process_inline(buf, content, strlen(content)); |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
662 buffer_append(buf, "</li>"); |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
663 |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
664 free(line); |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
665 if (*ptr == '\n') ptr++; |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
666 |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
667 // Check next line |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
668 if (!*ptr) break; |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
669 line_start = ptr; |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
670 while (*ptr && *ptr != '\n') ptr++; |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
671 line_len = ptr - line_start; |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
672 |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
673 line = (char *)malloc(line_len + 1); |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
674 if (!line) break; |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
675 memcpy(line, line_start, line_len); |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
676 line[line_len] = '\0'; |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
677 |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
678 if (!is_ordered_list(line)) { |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
679 ptr = line_start; |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
680 free(line); |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
681 break; |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
682 } |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
683 } |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
684 |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
685 buffer_append(buf, "</ol>"); |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
686 continue; |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
687 } |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
688 |
|
190
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
689 // Table: | col1 | col2 | followed by |---|---| |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
690 if (is_table_row(line)) { |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
691 // Peek at next line to see if it's a separator |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
692 const char *peek_ptr = ptr; |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
693 if (*peek_ptr == '\n') peek_ptr++; |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
694 |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
695 const char *next_line_start = peek_ptr; |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
696 while (*peek_ptr && *peek_ptr != '\n') peek_ptr++; |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
697 size_t next_line_len = peek_ptr - next_line_start; |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
698 |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
699 char *next_line = (char *)malloc(next_line_len + 1); |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
700 if (next_line) { |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
701 memcpy(next_line, next_line_start, next_line_len); |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
702 next_line[next_line_len] = '\0'; |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
703 |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
704 if (is_table_separator(next_line)) { |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
705 // It's a table! |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
706 int num_cols = count_table_columns(line); |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
707 int *alignments = (int *)calloc(num_cols, sizeof(int)); |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
708 |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
709 buffer_append(buf, "<table>"); |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
710 |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
711 // Header row |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
712 buffer_append(buf, "<thead><tr>"); |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
713 parse_table_row(buf, line, NULL, num_cols, 1, emit_table_cell); |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
714 buffer_append(buf, "</tr></thead>"); |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
715 |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
716 free(line); |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
717 if (*ptr == '\n') ptr++; |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
718 |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
719 // Parse alignments from separator |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
720 parse_alignments(next_line, alignments, num_cols); |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
721 free(next_line); |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
722 |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
723 // Skip separator line |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
724 ptr = peek_ptr; |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
725 if (*ptr == '\n') ptr++; |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
726 |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
727 // Body rows |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
728 buffer_append(buf, "<tbody>"); |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
729 |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
730 while (*ptr) { |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
731 line_start = ptr; |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
732 while (*ptr && *ptr != '\n') ptr++; |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
733 line_len = ptr - line_start; |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
734 |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
735 line = (char *)malloc(line_len + 1); |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
736 if (!line) break; |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
737 memcpy(line, line_start, line_len); |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
738 line[line_len] = '\0'; |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
739 |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
740 if (!is_table_row(line) || is_empty_line(line)) { |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
741 ptr = line_start; |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
742 free(line); |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
743 break; |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
744 } |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
745 |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
746 buffer_append(buf, "<tr>"); |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
747 parse_table_row(buf, line, alignments, num_cols, 0, emit_table_cell); |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
748 buffer_append(buf, "</tr>"); |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
749 |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
750 free(line); |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
751 if (*ptr == '\n') ptr++; |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
752 } |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
753 |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
754 buffer_append(buf, "</tbody></table>"); |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
755 free(alignments); |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
756 continue; |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
757 } |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
758 free(next_line); |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
759 } |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
760 } |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
761 |
|
184
8c74204fd362
[MD to HTML] Updated so it can be used through readme to html
MrJuneJune <me@mrjunejune.com>
parents:
158
diff
changeset
|
762 // HTML block - pass through unchanged |
|
8c74204fd362
[MD to HTML] Updated so it can be used through readme to html
MrJuneJune <me@mrjunejune.com>
parents:
158
diff
changeset
|
763 if (is_html_block_start(line)) { |
|
8c74204fd362
[MD to HTML] Updated so it can be used through readme to html
MrJuneJune <me@mrjunejune.com>
parents:
158
diff
changeset
|
764 // Check if it's a script or style tag that needs special handling |
|
8c74204fd362
[MD to HTML] Updated so it can be used through readme to html
MrJuneJune <me@mrjunejune.com>
parents:
158
diff
changeset
|
765 int is_script = is_html_tag(line, "script"); |
|
8c74204fd362
[MD to HTML] Updated so it can be used through readme to html
MrJuneJune <me@mrjunejune.com>
parents:
158
diff
changeset
|
766 int is_style = is_html_tag(line, "style"); |
|
8c74204fd362
[MD to HTML] Updated so it can be used through readme to html
MrJuneJune <me@mrjunejune.com>
parents:
158
diff
changeset
|
767 |
|
8c74204fd362
[MD to HTML] Updated so it can be used through readme to html
MrJuneJune <me@mrjunejune.com>
parents:
158
diff
changeset
|
768 if (is_script || is_style) { |
|
8c74204fd362
[MD to HTML] Updated so it can be used through readme to html
MrJuneJune <me@mrjunejune.com>
parents:
158
diff
changeset
|
769 const char *end_tag = is_script ? "</script>" : "</style>"; |
|
8c74204fd362
[MD to HTML] Updated so it can be used through readme to html
MrJuneJune <me@mrjunejune.com>
parents:
158
diff
changeset
|
770 |
|
8c74204fd362
[MD to HTML] Updated so it can be used through readme to html
MrJuneJune <me@mrjunejune.com>
parents:
158
diff
changeset
|
771 // Output the opening line |
|
8c74204fd362
[MD to HTML] Updated so it can be used through readme to html
MrJuneJune <me@mrjunejune.com>
parents:
158
diff
changeset
|
772 buffer_append(buf, line); |
|
8c74204fd362
[MD to HTML] Updated so it can be used through readme to html
MrJuneJune <me@mrjunejune.com>
parents:
158
diff
changeset
|
773 buffer_append_char(buf, '\n'); |
|
8c74204fd362
[MD to HTML] Updated so it can be used through readme to html
MrJuneJune <me@mrjunejune.com>
parents:
158
diff
changeset
|
774 |
|
8c74204fd362
[MD to HTML] Updated so it can be used through readme to html
MrJuneJune <me@mrjunejune.com>
parents:
158
diff
changeset
|
775 free(line); |
|
8c74204fd362
[MD to HTML] Updated so it can be used through readme to html
MrJuneJune <me@mrjunejune.com>
parents:
158
diff
changeset
|
776 if (*ptr == '\n') ptr++; |
|
8c74204fd362
[MD to HTML] Updated so it can be used through readme to html
MrJuneJune <me@mrjunejune.com>
parents:
158
diff
changeset
|
777 |
|
8c74204fd362
[MD to HTML] Updated so it can be used through readme to html
MrJuneJune <me@mrjunejune.com>
parents:
158
diff
changeset
|
778 // Collect content until closing tag |
|
8c74204fd362
[MD to HTML] Updated so it can be used through readme to html
MrJuneJune <me@mrjunejune.com>
parents:
158
diff
changeset
|
779 while (*ptr) { |
|
8c74204fd362
[MD to HTML] Updated so it can be used through readme to html
MrJuneJune <me@mrjunejune.com>
parents:
158
diff
changeset
|
780 line_start = ptr; |
|
8c74204fd362
[MD to HTML] Updated so it can be used through readme to html
MrJuneJune <me@mrjunejune.com>
parents:
158
diff
changeset
|
781 while (*ptr && *ptr != '\n') ptr++; |
|
8c74204fd362
[MD to HTML] Updated so it can be used through readme to html
MrJuneJune <me@mrjunejune.com>
parents:
158
diff
changeset
|
782 line_len = ptr - line_start; |
|
8c74204fd362
[MD to HTML] Updated so it can be used through readme to html
MrJuneJune <me@mrjunejune.com>
parents:
158
diff
changeset
|
783 |
|
8c74204fd362
[MD to HTML] Updated so it can be used through readme to html
MrJuneJune <me@mrjunejune.com>
parents:
158
diff
changeset
|
784 line = (char *)malloc(line_len + 1); |
|
8c74204fd362
[MD to HTML] Updated so it can be used through readme to html
MrJuneJune <me@mrjunejune.com>
parents:
158
diff
changeset
|
785 if (!line) break; |
|
8c74204fd362
[MD to HTML] Updated so it can be used through readme to html
MrJuneJune <me@mrjunejune.com>
parents:
158
diff
changeset
|
786 memcpy(line, line_start, line_len); |
|
8c74204fd362
[MD to HTML] Updated so it can be used through readme to html
MrJuneJune <me@mrjunejune.com>
parents:
158
diff
changeset
|
787 line[line_len] = '\0'; |
|
8c74204fd362
[MD to HTML] Updated so it can be used through readme to html
MrJuneJune <me@mrjunejune.com>
parents:
158
diff
changeset
|
788 |
|
8c74204fd362
[MD to HTML] Updated so it can be used through readme to html
MrJuneJune <me@mrjunejune.com>
parents:
158
diff
changeset
|
789 buffer_append(buf, line); |
|
8c74204fd362
[MD to HTML] Updated so it can be used through readme to html
MrJuneJune <me@mrjunejune.com>
parents:
158
diff
changeset
|
790 buffer_append_char(buf, '\n'); |
|
8c74204fd362
[MD to HTML] Updated so it can be used through readme to html
MrJuneJune <me@mrjunejune.com>
parents:
158
diff
changeset
|
791 |
|
8c74204fd362
[MD to HTML] Updated so it can be used through readme to html
MrJuneJune <me@mrjunejune.com>
parents:
158
diff
changeset
|
792 int found_end = (strstr(line, end_tag) != NULL); |
|
8c74204fd362
[MD to HTML] Updated so it can be used through readme to html
MrJuneJune <me@mrjunejune.com>
parents:
158
diff
changeset
|
793 free(line); |
|
8c74204fd362
[MD to HTML] Updated so it can be used through readme to html
MrJuneJune <me@mrjunejune.com>
parents:
158
diff
changeset
|
794 if (*ptr == '\n') ptr++; |
|
8c74204fd362
[MD to HTML] Updated so it can be used through readme to html
MrJuneJune <me@mrjunejune.com>
parents:
158
diff
changeset
|
795 |
|
8c74204fd362
[MD to HTML] Updated so it can be used through readme to html
MrJuneJune <me@mrjunejune.com>
parents:
158
diff
changeset
|
796 if (found_end) break; |
|
8c74204fd362
[MD to HTML] Updated so it can be used through readme to html
MrJuneJune <me@mrjunejune.com>
parents:
158
diff
changeset
|
797 } |
|
8c74204fd362
[MD to HTML] Updated so it can be used through readme to html
MrJuneJune <me@mrjunejune.com>
parents:
158
diff
changeset
|
798 continue; |
|
8c74204fd362
[MD to HTML] Updated so it can be used through readme to html
MrJuneJune <me@mrjunejune.com>
parents:
158
diff
changeset
|
799 } |
|
8c74204fd362
[MD to HTML] Updated so it can be used through readme to html
MrJuneJune <me@mrjunejune.com>
parents:
158
diff
changeset
|
800 |
|
8c74204fd362
[MD to HTML] Updated so it can be used through readme to html
MrJuneJune <me@mrjunejune.com>
parents:
158
diff
changeset
|
801 // Regular HTML tag - just pass through the line |
|
8c74204fd362
[MD to HTML] Updated so it can be used through readme to html
MrJuneJune <me@mrjunejune.com>
parents:
158
diff
changeset
|
802 buffer_append(buf, line); |
|
8c74204fd362
[MD to HTML] Updated so it can be used through readme to html
MrJuneJune <me@mrjunejune.com>
parents:
158
diff
changeset
|
803 buffer_append_char(buf, '\n'); |
|
8c74204fd362
[MD to HTML] Updated so it can be used through readme to html
MrJuneJune <me@mrjunejune.com>
parents:
158
diff
changeset
|
804 free(line); |
|
8c74204fd362
[MD to HTML] Updated so it can be used through readme to html
MrJuneJune <me@mrjunejune.com>
parents:
158
diff
changeset
|
805 if (*ptr == '\n') ptr++; |
|
8c74204fd362
[MD to HTML] Updated so it can be used through readme to html
MrJuneJune <me@mrjunejune.com>
parents:
158
diff
changeset
|
806 continue; |
|
8c74204fd362
[MD to HTML] Updated so it can be used through readme to html
MrJuneJune <me@mrjunejune.com>
parents:
158
diff
changeset
|
807 } |
|
8c74204fd362
[MD to HTML] Updated so it can be used through readme to html
MrJuneJune <me@mrjunejune.com>
parents:
158
diff
changeset
|
808 |
|
154
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
809 // Regular paragraph |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
810 buffer_append(buf, "<p>"); |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
811 |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
812 while (1) { |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
813 const char *content = skip_whitespace(line); |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
814 process_inline(buf, content, strlen(content)); |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
815 |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
816 free(line); |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
817 if (*ptr == '\n') ptr++; |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
818 |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
819 // Check next line - continue paragraph if not special |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
820 if (!*ptr) break; |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
821 line_start = ptr; |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
822 while (*ptr && *ptr != '\n') ptr++; |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
823 line_len = ptr - line_start; |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
824 |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
825 line = (char *)malloc(line_len + 1); |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
826 if (!line) break; |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
827 memcpy(line, line_start, line_len); |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
828 line[line_len] = '\0'; |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
829 |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
830 if (is_empty_line(line) || |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
831 count_heading_level(line) > 0 || |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
832 starts_with(line, "```") || |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
833 starts_with(line, ">") || |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
834 is_horizontal_rule(line) || |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
835 is_unordered_list(line) || |
|
184
8c74204fd362
[MD to HTML] Updated so it can be used through readme to html
MrJuneJune <me@mrjunejune.com>
parents:
158
diff
changeset
|
836 is_ordered_list(line) || |
|
190
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
837 is_table_row(line) || |
|
184
8c74204fd362
[MD to HTML] Updated so it can be used through readme to html
MrJuneJune <me@mrjunejune.com>
parents:
158
diff
changeset
|
838 is_html_block_start(line)) { |
|
154
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
839 ptr = line_start; |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
840 free(line); |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
841 break; |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
842 } |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
843 |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
844 buffer_append_char(buf, ' '); |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
845 } |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
846 |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
847 buffer_append(buf, "</p>"); |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
848 } |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
849 |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
850 char *result = buf->data; |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
851 free(buf); // Free struct but not data |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
852 return result; |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
853 } |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
854 |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
855 // Free the returned HTML string |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
856 MDAPI void markdown_free(char *html) |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
857 { |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
858 free(html); |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
859 } |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
860 |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
861 // Get length of HTML string (for WASM memory allocation) |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
862 MDAPI size_t markdown_get_length(const char *html) |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
863 { |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
864 return html ? strlen(html) : 0; |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
865 } |