Mercurial
comparison markdown_converter/markdown_to_html.c @ 156:cd35e600ae34
[MarkDown Converter] Fixed few things and made a test
| author | June Park <parkjune1995@gmail.com> |
|---|---|
| date | Mon, 12 Jan 2026 15:20:39 -0800 |
| parents | bdcc610eeed8 |
| children | 1c0878eb17de |
comparison
equal
deleted
inserted
replaced
| 155:3bb45eb67906 | 156:cd35e600ae34 |
|---|---|
| 1 /** | 1 /** |
| 2 * Markdown to HTML Converter - C Implementation | 2 * Markdown to HTML Converter - C Implementation |
| 3 * Supports: headers, bold, italic, links, lists, code blocks, blockquotes, horizontal rules | 3 * Supports: headers, bold, italic, links, lists, code blocks, blockquotes, horizontal rules |
| 4 */ | 4 */ |
| 5 | 5 |
| 6 #include "markdown_to_html.h" | 6 #ifndef MARKDOWN_TO_HTML_H |
| 7 #define MARKDOWN_TO_HTML_H | |
| 8 | |
| 9 #include <stddef.h> | |
| 10 | |
| 11 // Export macro for WASM/Emscripten | |
| 12 #ifdef __EMSCRIPTEN__ | |
| 13 #include <emscripten.h> | |
| 14 #define MDAPI EMSCRIPTEN_KEEPALIVE | |
| 15 #else | |
| 16 #ifdef _WIN32 | |
| 17 #ifdef MARKDOWN_EXPORTS | |
| 18 #define MDAPI __declspec(dllexport) | |
| 19 #else | |
| 20 #define MDAPI __declspec(dllimport) | |
| 21 #endif | |
| 22 #else | |
| 23 #define MDAPI extern | |
| 24 #endif | |
| 25 #endif | |
| 26 | |
| 27 /** | |
| 28 * Convert markdown string to HTML string. | |
| 29 * | |
| 30 * @param markdown The input markdown string (null-terminated) | |
| 31 * @return Newly allocated HTML string. Caller must free with markdown_free(). | |
| 32 * Returns NULL on allocation failure. | |
| 33 * | |
| 34 * Supported markdown features: | |
| 35 * - Headers: # H1, ## H2, ... ###### H6 | |
| 36 * - Bold: **text** or __text__ | |
| 37 * - Italic: *text* or _text_ | |
| 38 * - Strikethrough: ~~text~~ | |
| 39 * - Links: [text](url) | |
| 40 * - Images:  | |
| 41 * - Inline code: `code` | |
| 42 * - Code blocks: ```code``` | |
| 43 * - Unordered lists: -, *, + | |
| 44 * - Ordered lists: 1., 2., etc. | |
| 45 * - Blockquotes: > text | |
| 46 * - Horizontal rules: ---, ***, ___ | |
| 47 */ | |
| 48 MDAPI char *markdown_to_html(const char *markdown); | |
| 49 | |
| 50 /** | |
| 51 * Free HTML string returned by markdown_to_html. | |
| 52 * | |
| 53 * @param html The HTML string to free | |
| 54 */ | |
| 55 MDAPI void markdown_free(char *html); | |
| 56 | |
| 57 /** | |
| 58 * Get length of HTML string (useful for WASM memory operations). | |
| 59 * | |
| 60 * @param html The HTML string | |
| 61 * @return Length of the string, or 0 if NULL | |
| 62 */ | |
| 63 MDAPI size_t markdown_get_length(const char *html); | |
| 64 | |
| 65 #endif // MARKDOWN_TO_HTML_H | |
| 7 #include <string.h> | 66 #include <string.h> |
| 8 #include <stdlib.h> | 67 #include <stdlib.h> |
| 9 #include <stdio.h> | 68 #include <stdio.h> |
| 10 #include <ctype.h> | 69 #include <ctype.h> |
| 11 | 70 |