Mercurial
diff markdown_converter/markdown_to_html.c @ 158:1c0878eb17de
[MrJuneJune] Readme file gets compiled in server side.
| author | June Park <parkjune1995@gmail.com> |
|---|---|
| date | Wed, 14 Jan 2026 07:59:19 -0800 |
| parents | cd35e600ae34 |
| children | 8c74204fd362 |
line wrap: on
line diff
--- a/markdown_converter/markdown_to_html.c Tue Jan 13 19:18:47 2026 -0800 +++ b/markdown_converter/markdown_to_html.c Wed Jan 14 07:59:19 2026 -0800 @@ -1,74 +1,10 @@ -/** - * Markdown to HTML Converter - C Implementation - * Supports: headers, bold, italic, links, lists, code blocks, blockquotes, horizontal rules - */ - -#ifndef MARKDOWN_TO_HTML_H -#define MARKDOWN_TO_HTML_H - -#include <stddef.h> - -// Export macro for WASM/Emscripten -#ifdef __EMSCRIPTEN__ - #include <emscripten.h> - #define MDAPI EMSCRIPTEN_KEEPALIVE -#else - #ifdef _WIN32 - #ifdef MARKDOWN_EXPORTS - #define MDAPI __declspec(dllexport) - #else - #define MDAPI __declspec(dllimport) - #endif - #else - #define MDAPI extern - #endif -#endif - -/** - * Convert markdown string to HTML string. - * - * @param markdown The input markdown string (null-terminated) - * @return Newly allocated HTML string. Caller must free with markdown_free(). - * Returns NULL on allocation failure. - * - * Supported markdown features: - * - Headers: # H1, ## H2, ... ###### H6 - * - Bold: **text** or __text__ - * - Italic: *text* or _text_ - * - Strikethrough: ~~text~~ - * - Links: [text](url) - * - Images:  - * - Inline code: `code` - * - Code blocks: ```code``` - * - Unordered lists: -, *, + - * - Ordered lists: 1., 2., etc. - * - Blockquotes: > text - * - Horizontal rules: ---, ***, ___ - */ -MDAPI char *markdown_to_html(const char *markdown); - -/** - * Free HTML string returned by markdown_to_html. - * - * @param html The HTML string to free - */ -MDAPI void markdown_free(char *html); - -/** - * Get length of HTML string (useful for WASM memory operations). - * - * @param html The HTML string - * @return Length of the string, or 0 if NULL - */ -MDAPI size_t markdown_get_length(const char *html); - -#endif // MARKDOWN_TO_HTML_H #include <string.h> #include <stdlib.h> #include <stdio.h> #include <ctype.h> +#include "markdown_converter/markdown_to_html.h" -#define INITIAL_BUFFER_SIZE 4096 +#define INITIAL_BUFFER_SIZE 1024 * 1024 // 1MB // String buffer for building HTML output typedef struct { @@ -319,16 +255,18 @@ } } + // This might not be needed for now. // HTML escape special characters - if (text[i] == '<') { - buffer_append(buf, "<"); - } else if (text[i] == '>') { - buffer_append(buf, ">"); - } else if (text[i] == '&') { - buffer_append(buf, "&"); - } else { - buffer_append_char(buf, text[i]); - } + // if (text[i] == '<') { + // buffer_append(buf, "<"); + // } else if (text[i] == '>') { + // buffer_append(buf, ">"); + // } else if (text[i] == '&') { + // buffer_append(buf, "&"); + // } else { + // buffer_append_char(buf, text[i]); + // } + buffer_append_char(buf, text[i]); i++; } }