Mercurial
annotate markdown_converter/markdown_to_html.c @ 247:70f2a3dafc1c
[build] Bundle offline Tectonic runtime
Co-authored-by: Copilot <[email protected]>
| author | MrJuneJune <me@mrjunejune.com> |
|---|---|
| date | Mon, 03 Aug 2026 20:20:06 -0700 |
| parents | ce7f4400c2de |
| 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_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
|
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, 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
|
67 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
|
68 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
|
69 } |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule 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 |
|
221
ce7f4400c2de
[hg-web] Harden forge and add changeset UI
MrJuneJune <me@mrjunejune.com>
parents:
190
diff
changeset
|
71 static void buffer_append_html_escaped_n(StringBuffer *buf, const char *text, size_t len) |
|
ce7f4400c2de
[hg-web] Harden forge and add changeset UI
MrJuneJune <me@mrjunejune.com>
parents:
190
diff
changeset
|
72 { |
|
ce7f4400c2de
[hg-web] Harden forge and add changeset UI
MrJuneJune <me@mrjunejune.com>
parents:
190
diff
changeset
|
73 for (size_t i = 0; i < len; i++) { |
|
ce7f4400c2de
[hg-web] Harden forge and add changeset UI
MrJuneJune <me@mrjunejune.com>
parents:
190
diff
changeset
|
74 switch (text[i]) { |
|
ce7f4400c2de
[hg-web] Harden forge and add changeset UI
MrJuneJune <me@mrjunejune.com>
parents:
190
diff
changeset
|
75 case '&': buffer_append(buf, "&"); break; |
|
ce7f4400c2de
[hg-web] Harden forge and add changeset UI
MrJuneJune <me@mrjunejune.com>
parents:
190
diff
changeset
|
76 case '<': buffer_append(buf, "<"); break; |
|
ce7f4400c2de
[hg-web] Harden forge and add changeset UI
MrJuneJune <me@mrjunejune.com>
parents:
190
diff
changeset
|
77 case '>': buffer_append(buf, ">"); break; |
|
ce7f4400c2de
[hg-web] Harden forge and add changeset UI
MrJuneJune <me@mrjunejune.com>
parents:
190
diff
changeset
|
78 case '"': buffer_append(buf, """); break; |
|
ce7f4400c2de
[hg-web] Harden forge and add changeset UI
MrJuneJune <me@mrjunejune.com>
parents:
190
diff
changeset
|
79 case '\'': buffer_append(buf, "'"); break; |
|
ce7f4400c2de
[hg-web] Harden forge and add changeset UI
MrJuneJune <me@mrjunejune.com>
parents:
190
diff
changeset
|
80 default: buffer_append_char(buf, text[i]); break; |
|
ce7f4400c2de
[hg-web] Harden forge and add changeset UI
MrJuneJune <me@mrjunejune.com>
parents:
190
diff
changeset
|
81 } |
|
ce7f4400c2de
[hg-web] Harden forge and add changeset UI
MrJuneJune <me@mrjunejune.com>
parents:
190
diff
changeset
|
82 } |
|
ce7f4400c2de
[hg-web] Harden forge and add changeset UI
MrJuneJune <me@mrjunejune.com>
parents:
190
diff
changeset
|
83 } |
|
ce7f4400c2de
[hg-web] Harden forge and add changeset UI
MrJuneJune <me@mrjunejune.com>
parents:
190
diff
changeset
|
84 |
|
ce7f4400c2de
[hg-web] Harden forge and add changeset UI
MrJuneJune <me@mrjunejune.com>
parents:
190
diff
changeset
|
85 static int is_safe_url(const char *url, size_t len, int is_image) |
|
ce7f4400c2de
[hg-web] Harden forge and add changeset UI
MrJuneJune <me@mrjunejune.com>
parents:
190
diff
changeset
|
86 { |
|
ce7f4400c2de
[hg-web] Harden forge and add changeset UI
MrJuneJune <me@mrjunejune.com>
parents:
190
diff
changeset
|
87 if (len == 0) return 0; |
|
ce7f4400c2de
[hg-web] Harden forge and add changeset UI
MrJuneJune <me@mrjunejune.com>
parents:
190
diff
changeset
|
88 |
|
ce7f4400c2de
[hg-web] Harden forge and add changeset UI
MrJuneJune <me@mrjunejune.com>
parents:
190
diff
changeset
|
89 for (size_t i = 0; i < len; i++) { |
|
ce7f4400c2de
[hg-web] Harden forge and add changeset UI
MrJuneJune <me@mrjunejune.com>
parents:
190
diff
changeset
|
90 unsigned char c = (unsigned char)url[i]; |
|
ce7f4400c2de
[hg-web] Harden forge and add changeset UI
MrJuneJune <me@mrjunejune.com>
parents:
190
diff
changeset
|
91 if (iscntrl(c) || isspace(c)) return 0; |
|
ce7f4400c2de
[hg-web] Harden forge and add changeset UI
MrJuneJune <me@mrjunejune.com>
parents:
190
diff
changeset
|
92 } |
|
ce7f4400c2de
[hg-web] Harden forge and add changeset UI
MrJuneJune <me@mrjunejune.com>
parents:
190
diff
changeset
|
93 |
|
ce7f4400c2de
[hg-web] Harden forge and add changeset UI
MrJuneJune <me@mrjunejune.com>
parents:
190
diff
changeset
|
94 const char *colon = memchr(url, ':', len); |
|
ce7f4400c2de
[hg-web] Harden forge and add changeset UI
MrJuneJune <me@mrjunejune.com>
parents:
190
diff
changeset
|
95 if (!colon) return 1; |
|
ce7f4400c2de
[hg-web] Harden forge and add changeset UI
MrJuneJune <me@mrjunejune.com>
parents:
190
diff
changeset
|
96 |
|
ce7f4400c2de
[hg-web] Harden forge and add changeset UI
MrJuneJune <me@mrjunejune.com>
parents:
190
diff
changeset
|
97 size_t scheme_len = (size_t)(colon - url); |
|
ce7f4400c2de
[hg-web] Harden forge and add changeset UI
MrJuneJune <me@mrjunejune.com>
parents:
190
diff
changeset
|
98 if (scheme_len == 4 && strncasecmp(url, "http", scheme_len) == 0) return 1; |
|
ce7f4400c2de
[hg-web] Harden forge and add changeset UI
MrJuneJune <me@mrjunejune.com>
parents:
190
diff
changeset
|
99 if (scheme_len == 5 && strncasecmp(url, "https", scheme_len) == 0) return 1; |
|
ce7f4400c2de
[hg-web] Harden forge and add changeset UI
MrJuneJune <me@mrjunejune.com>
parents:
190
diff
changeset
|
100 if (!is_image && scheme_len == 6 && strncasecmp(url, "mailto", scheme_len) == 0) return 1; |
|
ce7f4400c2de
[hg-web] Harden forge and add changeset UI
MrJuneJune <me@mrjunejune.com>
parents:
190
diff
changeset
|
101 return 0; |
|
ce7f4400c2de
[hg-web] Harden forge and add changeset UI
MrJuneJune <me@mrjunejune.com>
parents:
190
diff
changeset
|
102 } |
|
ce7f4400c2de
[hg-web] Harden forge and add changeset UI
MrJuneJune <me@mrjunejune.com>
parents:
190
diff
changeset
|
103 |
|
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
|
104 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
|
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 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
|
107 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
|
108 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
|
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 } |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule 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 |
|
190
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
112 // Forward declaration |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
113 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
|
114 |
|
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
|
115 // 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
|
116 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
|
117 { |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule 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 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
|
119 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
|
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 |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule 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 // 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
|
123 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
|
124 { |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule 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 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
|
126 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
|
127 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
|
128 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
|
129 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 |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule 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 // 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
|
133 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
|
134 { |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule 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 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
|
136 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
|
137 } |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule 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 // 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
|
140 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
|
141 { |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule 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 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
|
143 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
|
144 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
|
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 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
|
147 } |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
148 |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
149 // 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
|
150 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
|
151 { |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
152 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
|
153 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
|
154 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
|
155 |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
156 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
|
157 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
|
158 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
|
159 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
|
160 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
|
161 } |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
162 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
|
163 } |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
164 |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
165 // 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
|
166 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
|
167 { |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
168 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
|
169 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
|
170 } |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
171 |
|
184
8c74204fd362
[MD to HTML] Updated so it can be used through readme to html
MrJuneJune <me@mrjunejune.com>
parents:
158
diff
changeset
|
172 // 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
|
173 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
|
174 { |
|
8c74204fd362
[MD to HTML] Updated so it can be used through readme to html
MrJuneJune <me@mrjunejune.com>
parents:
158
diff
changeset
|
175 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
|
176 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
|
177 line++; |
|
8c74204fd362
[MD to HTML] Updated so it can be used through readme to html
MrJuneJune <me@mrjunejune.com>
parents:
158
diff
changeset
|
178 |
|
8c74204fd362
[MD to HTML] Updated so it can be used through readme to html
MrJuneJune <me@mrjunejune.com>
parents:
158
diff
changeset
|
179 // 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
|
180 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
|
181 |
|
8c74204fd362
[MD to HTML] Updated so it can be used through readme to html
MrJuneJune <me@mrjunejune.com>
parents:
158
diff
changeset
|
182 // 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
|
183 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
|
184 |
|
8c74204fd362
[MD to HTML] Updated so it can be used through readme to html
MrJuneJune <me@mrjunejune.com>
parents:
158
diff
changeset
|
185 return 1; |
|
8c74204fd362
[MD to HTML] Updated so it can be used through readme to html
MrJuneJune <me@mrjunejune.com>
parents:
158
diff
changeset
|
186 } |
|
8c74204fd362
[MD to HTML] Updated so it can be used through readme to html
MrJuneJune <me@mrjunejune.com>
parents:
158
diff
changeset
|
187 |
|
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
|
188 // 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
|
189 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
|
190 { |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule 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 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
|
192 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
|
193 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
|
194 } |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
195 |
|
190
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
196 // 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
|
197 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
|
198 { |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
199 line = skip_whitespace(line); |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
200 // 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
|
201 return strchr(line, '|') != NULL; |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
202 } |
|
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 // 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
|
205 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
|
206 { |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
207 line = skip_whitespace(line); |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
208 int has_dash = 0; |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
209 int has_pipe = 0; |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
210 |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
211 while (*line) { |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
212 char c = *line; |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
213 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
|
214 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
|
215 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
|
216 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
|
217 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
|
218 line++; |
|
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 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
|
222 } |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
223 |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
224 // 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
|
225 // 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
|
226 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
|
227 { |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
228 // Trim whitespace |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
229 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
|
230 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
|
231 |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
232 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
|
233 |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
234 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
|
235 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
|
236 |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
237 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
|
238 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
|
239 return 0; // left (default) |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
240 } |
|
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 // 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
|
243 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
|
244 { |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
245 int count = 0; |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
246 int in_cell = 0; |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
247 line = skip_whitespace(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 // Skip leading | |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
250 if (*line == '|') line++; |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
251 |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
252 while (*line) { |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
253 if (*line == '|') { |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
254 count++; |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
255 in_cell = 0; |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
256 } 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
|
257 in_cell = 1; |
|
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 line++; |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
260 } |
|
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 // 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
|
263 if (in_cell) count++; |
|
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 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
|
266 } |
|
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 // 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
|
269 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
|
270 |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
271 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
|
272 { |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
273 line = skip_whitespace(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 // Skip leading | |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
276 if (*line == '|') 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 int col = 0; |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
279 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
|
280 |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
281 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
|
282 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
|
283 // End of cell |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
284 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
|
285 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
|
286 |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
287 // Trim whitespace from cell |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
288 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
|
289 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
|
290 |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
291 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
|
292 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
|
293 |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
294 col++; |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
295 cell_start = line + 1; |
|
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 line++; |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
298 } |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
299 |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
300 // 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
|
301 while (col < num_cols) { |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
302 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
|
303 col++; |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
304 } |
|
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 |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
307 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
|
308 { |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
309 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
|
310 const char *align_attr = ""; |
|
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 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
|
313 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
|
314 |
|
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 buffer_append(buf, tag); |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
317 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
|
318 buffer_append(buf, ">"); |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
319 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
|
320 buffer_append(buf, "</"); |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
321 buffer_append(buf, tag); |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
322 buffer_append(buf, ">"); |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
323 } |
|
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 // 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
|
326 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
|
327 { |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
328 line = skip_whitespace(line); |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
329 if (*line == '|') 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 int col = 0; |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
332 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
|
333 |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
334 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
|
335 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
|
336 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
|
337 if (*line != '|') cell_len++; |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
338 |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
339 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
|
340 col++; |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
341 cell_start = line + 1; |
|
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 line++; |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
344 } |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
345 } |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
346 |
|
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
|
347 // 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
|
348 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
|
349 { |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule 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 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
|
351 |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule 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 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
|
353 // 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
|
354 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
|
355 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
|
356 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
|
357 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
|
358 |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule 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 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
|
360 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
|
361 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
|
362 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
|
363 |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule 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 if (url_end < len) { |
|
221
ce7f4400c2de
[hg-web] Harden forge and add changeset UI
MrJuneJune <me@mrjunejune.com>
parents:
190
diff
changeset
|
365 size_t url_len = url_end - url_start; |
|
ce7f4400c2de
[hg-web] Harden forge and add changeset UI
MrJuneJune <me@mrjunejune.com>
parents:
190
diff
changeset
|
366 if (is_safe_url(text + url_start, url_len, 0)) { |
|
ce7f4400c2de
[hg-web] Harden forge and add changeset UI
MrJuneJune <me@mrjunejune.com>
parents:
190
diff
changeset
|
367 buffer_append(buf, "<a href=\""); |
|
ce7f4400c2de
[hg-web] Harden forge and add changeset UI
MrJuneJune <me@mrjunejune.com>
parents:
190
diff
changeset
|
368 buffer_append_html_escaped_n(buf, text + url_start, url_len); |
|
ce7f4400c2de
[hg-web] Harden forge and add changeset UI
MrJuneJune <me@mrjunejune.com>
parents:
190
diff
changeset
|
369 buffer_append(buf, "\">"); |
|
ce7f4400c2de
[hg-web] Harden forge and add changeset UI
MrJuneJune <me@mrjunejune.com>
parents:
190
diff
changeset
|
370 process_inline(buf, text + link_start, link_end - link_start); |
|
ce7f4400c2de
[hg-web] Harden forge and add changeset UI
MrJuneJune <me@mrjunejune.com>
parents:
190
diff
changeset
|
371 buffer_append(buf, "</a>"); |
|
ce7f4400c2de
[hg-web] Harden forge and add changeset UI
MrJuneJune <me@mrjunejune.com>
parents:
190
diff
changeset
|
372 } else { |
|
ce7f4400c2de
[hg-web] Harden forge and add changeset UI
MrJuneJune <me@mrjunejune.com>
parents:
190
diff
changeset
|
373 process_inline(buf, text + link_start, link_end - link_start); |
|
ce7f4400c2de
[hg-web] Harden forge and add changeset UI
MrJuneJune <me@mrjunejune.com>
parents:
190
diff
changeset
|
374 } |
|
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
|
375 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
|
376 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
|
377 } |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule 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 } |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule 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 |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule 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 // 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
|
382 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
|
383 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
|
384 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
|
385 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
|
386 |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule 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 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
|
388 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
|
389 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
|
390 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
|
391 |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule 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 if (url_end < len) { |
|
221
ce7f4400c2de
[hg-web] Harden forge and add changeset UI
MrJuneJune <me@mrjunejune.com>
parents:
190
diff
changeset
|
393 size_t url_len = url_end - url_start; |
|
ce7f4400c2de
[hg-web] Harden forge and add changeset UI
MrJuneJune <me@mrjunejune.com>
parents:
190
diff
changeset
|
394 if (is_safe_url(text + url_start, url_len, 1)) { |
|
ce7f4400c2de
[hg-web] Harden forge and add changeset UI
MrJuneJune <me@mrjunejune.com>
parents:
190
diff
changeset
|
395 buffer_append(buf, "<img src=\""); |
|
ce7f4400c2de
[hg-web] Harden forge and add changeset UI
MrJuneJune <me@mrjunejune.com>
parents:
190
diff
changeset
|
396 buffer_append_html_escaped_n(buf, text + url_start, url_len); |
|
ce7f4400c2de
[hg-web] Harden forge and add changeset UI
MrJuneJune <me@mrjunejune.com>
parents:
190
diff
changeset
|
397 buffer_append(buf, "\" alt=\""); |
|
ce7f4400c2de
[hg-web] Harden forge and add changeset UI
MrJuneJune <me@mrjunejune.com>
parents:
190
diff
changeset
|
398 buffer_append_html_escaped_n(buf, text + alt_start, alt_end - alt_start); |
|
ce7f4400c2de
[hg-web] Harden forge and add changeset UI
MrJuneJune <me@mrjunejune.com>
parents:
190
diff
changeset
|
399 buffer_append(buf, "\">"); |
|
ce7f4400c2de
[hg-web] Harden forge and add changeset UI
MrJuneJune <me@mrjunejune.com>
parents:
190
diff
changeset
|
400 } else { |
|
ce7f4400c2de
[hg-web] Harden forge and add changeset UI
MrJuneJune <me@mrjunejune.com>
parents:
190
diff
changeset
|
401 buffer_append_html_escaped_n(buf, text + alt_start, alt_end - alt_start); |
|
ce7f4400c2de
[hg-web] Harden forge and add changeset UI
MrJuneJune <me@mrjunejune.com>
parents:
190
diff
changeset
|
402 } |
|
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
|
403 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
|
404 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
|
405 } |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule 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 } |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule 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 } |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule 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 |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule 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 // 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
|
410 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
|
411 (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
|
412 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
|
413 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
|
414 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
|
415 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
|
416 |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule 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 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
|
418 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
|
419 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
|
420 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
|
421 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
|
422 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
|
423 } |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule 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 } |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule 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 // 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
|
427 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
|
428 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
|
429 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
|
430 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
|
431 |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule 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 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
|
433 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
|
434 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
|
435 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
|
436 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
|
437 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
|
438 } |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule 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 } |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule 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 |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule 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 // 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
|
442 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
|
443 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
|
444 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
|
445 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
|
446 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
|
447 |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule 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 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
|
449 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
|
450 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
|
451 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
|
452 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
|
453 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
|
454 } |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule 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 } |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule 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 // 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
|
458 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
|
459 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
|
460 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
|
461 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
|
462 |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
463 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
|
464 buffer_append(buf, "<code>"); |
|
221
ce7f4400c2de
[hg-web] Harden forge and add changeset UI
MrJuneJune <me@mrjunejune.com>
parents:
190
diff
changeset
|
465 buffer_append_html_escaped_n(buf, text + start, end - start); |
|
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
|
466 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
|
467 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
|
468 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
|
469 } |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
470 } |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule 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 |
|
221
ce7f4400c2de
[hg-web] Harden forge and add changeset UI
MrJuneJune <me@mrjunejune.com>
parents:
190
diff
changeset
|
472 buffer_append_html_escaped_n(buf, text + i, 1); |
|
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
|
473 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
|
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 } |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule 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 |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule 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 // 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
|
478 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
|
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 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
|
481 |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule 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 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
|
483 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
|
484 |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule 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 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
|
486 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
|
487 |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule 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 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
|
489 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
|
490 |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule 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 // 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
|
492 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
|
493 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
|
494 |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule 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 // 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
|
496 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
|
497 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
|
498 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
|
499 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
|
500 } |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule 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 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
|
502 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
|
503 |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule 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 // 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
|
505 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
|
506 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
|
507 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
|
508 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
|
509 } |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule 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 |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule 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 // 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
|
512 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
|
513 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
|
514 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
|
515 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
|
516 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
|
517 |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule 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 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
|
519 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
|
520 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
|
521 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
|
522 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
|
523 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
|
524 |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule 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 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
|
526 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
|
527 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
|
528 } |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule 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 |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule 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 // 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
|
531 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
|
532 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
|
533 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
|
534 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
|
535 |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule 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 // 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
|
537 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
|
538 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
|
539 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
|
540 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
|
541 |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule 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 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
|
543 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
|
544 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
|
545 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
|
546 |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule 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 (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
|
548 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
|
549 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
|
550 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
|
551 } |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule 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 |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule 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 // 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
|
554 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
|
555 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 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
|
557 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
|
558 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
|
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 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
|
561 |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule 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 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
|
563 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
|
564 } |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule 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 |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule 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 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
|
567 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
|
568 } |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule 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 |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule 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 // 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 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
|
572 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
|
573 |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule 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 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
|
575 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
|
576 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
|
577 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
|
578 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
|
579 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
|
580 |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule 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 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
|
582 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
|
583 |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule 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 // 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
|
585 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
|
586 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
|
587 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
|
588 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
|
589 |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule 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 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
|
591 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
|
592 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
|
593 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
|
594 |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule 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 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
|
596 // 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
|
597 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
|
598 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
|
599 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
|
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 } |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule 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 |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule 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 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
|
604 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
|
605 } |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule 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 |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule 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 // 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
|
608 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
|
609 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
|
610 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
|
611 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
|
612 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
|
613 } |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule 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 |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule 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 // 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
|
616 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
|
617 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
|
618 |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule 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 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
|
620 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
|
621 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
|
622 |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule 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 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
|
625 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
|
626 |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule 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 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
|
628 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
|
629 |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule 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 // 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
|
631 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
|
632 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
|
633 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
|
634 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
|
635 |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule 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 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
|
637 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
|
638 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
|
639 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
|
640 |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule 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 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
|
642 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
|
643 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
|
644 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
|
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 } |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule 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 |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule 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 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
|
649 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
|
650 } |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule 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 |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule 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 // 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
|
653 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
|
654 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
|
655 |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule 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 (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
|
657 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
|
658 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
|
659 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
|
660 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
|
661 |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule 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 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
|
664 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
|
665 |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule 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 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
|
667 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
|
668 |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule 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 // 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
|
670 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
|
671 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
|
672 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
|
673 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
|
674 |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule 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 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
|
676 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
|
677 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
|
678 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
|
679 |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule 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 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
|
681 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
|
682 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
|
683 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
|
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 } |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule 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 |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule 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 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
|
688 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
|
689 } |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
690 |
|
190
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
691 // 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
|
692 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
|
693 // 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
|
694 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
|
695 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
|
696 |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
697 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
|
698 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
|
699 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
|
700 |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
701 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
|
702 if (next_line) { |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
703 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
|
704 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
|
705 |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
706 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
|
707 // It's a table! |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
708 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
|
709 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
|
710 |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
711 buffer_append(buf, "<table>"); |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
712 |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
713 // Header row |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
714 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
|
715 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
|
716 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
|
717 |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
718 free(line); |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
719 if (*ptr == '\n') ptr++; |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
720 |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
721 // Parse alignments from separator |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
722 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
|
723 free(next_line); |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
724 |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
725 // Skip separator line |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
726 ptr = peek_ptr; |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
727 if (*ptr == '\n') ptr++; |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
728 |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
729 // Body rows |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
730 buffer_append(buf, "<tbody>"); |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
731 |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
732 while (*ptr) { |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
733 line_start = ptr; |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
734 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
|
735 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
|
736 |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
737 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
|
738 if (!line) break; |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
739 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
|
740 line[line_len] = '\0'; |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
741 |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
742 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
|
743 ptr = line_start; |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
744 free(line); |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
745 break; |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
746 } |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
747 |
|
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 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
|
750 buffer_append(buf, "</tr>"); |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
751 |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
752 free(line); |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
753 if (*ptr == '\n') ptr++; |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
754 } |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
755 |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
756 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
|
757 free(alignments); |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
758 continue; |
|
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 free(next_line); |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
761 } |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
762 } |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
184
diff
changeset
|
763 |
|
221
ce7f4400c2de
[hg-web] Harden forge and add changeset UI
MrJuneJune <me@mrjunejune.com>
parents:
190
diff
changeset
|
764 // Repository markdown is untrusted. Render raw HTML as text. |
|
184
8c74204fd362
[MD to HTML] Updated so it can be used through readme to html
MrJuneJune <me@mrjunejune.com>
parents:
158
diff
changeset
|
765 if (is_html_block_start(line)) { |
|
221
ce7f4400c2de
[hg-web] Harden forge and add changeset UI
MrJuneJune <me@mrjunejune.com>
parents:
190
diff
changeset
|
766 buffer_append(buf, "<p>"); |
|
ce7f4400c2de
[hg-web] Harden forge and add changeset UI
MrJuneJune <me@mrjunejune.com>
parents:
190
diff
changeset
|
767 process_inline(buf, line, line_len); |
|
ce7f4400c2de
[hg-web] Harden forge and add changeset UI
MrJuneJune <me@mrjunejune.com>
parents:
190
diff
changeset
|
768 buffer_append(buf, "</p>"); |
|
184
8c74204fd362
[MD to HTML] Updated so it can be used through readme to html
MrJuneJune <me@mrjunejune.com>
parents:
158
diff
changeset
|
769 free(line); |
|
8c74204fd362
[MD to HTML] Updated so it can be used through readme to html
MrJuneJune <me@mrjunejune.com>
parents:
158
diff
changeset
|
770 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
|
771 continue; |
|
8c74204fd362
[MD to HTML] Updated so it can be used through readme to html
MrJuneJune <me@mrjunejune.com>
parents:
158
diff
changeset
|
772 } |
|
8c74204fd362
[MD to HTML] Updated so it can be used through readme to html
MrJuneJune <me@mrjunejune.com>
parents:
158
diff
changeset
|
773 |
|
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
|
774 // 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
|
775 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
|
776 |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
777 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
|
778 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
|
779 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
|
780 |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
781 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
|
782 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
|
783 |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
784 // 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
|
785 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
|
786 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
|
787 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
|
788 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
|
789 |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
790 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
|
791 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
|
792 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
|
793 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
|
794 |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
795 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
|
796 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
|
797 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
|
798 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
|
799 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
|
800 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
|
801 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
|
802 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
|
803 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
|
804 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
|
805 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
|
806 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
|
807 } |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
808 |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule 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 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
|
810 } |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule 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 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
|
813 } |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule 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 |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule 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 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
|
816 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
|
817 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
|
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 |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule 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 // 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
|
821 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
|
822 { |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule 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 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
|
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 |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule 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 // 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
|
827 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
|
828 { |
|
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule 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 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
|
830 } |