-
Notifications
You must be signed in to change notification settings - Fork 552
Expand file tree
/
Copy pathmarkdown_byond.cpp
More file actions
55 lines (44 loc) · 1.66 KB
/
markdown_byond.cpp
File metadata and controls
55 lines (44 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include <string>
#include <iostream>
#include <stdio.h>
#include "html.h"
#ifdef _WIN32
#define DLL_EXPORT __declspec(dllexport)
#else
#define DLL_EXPORT __attribute__ ((visibility ("default")))
#endif
extern "C" DLL_EXPORT const char * render_html(int argc, char ** argv);
extern "C" DLL_EXPORT char * free_memory(int argc, char ** argv);
extern "C" DLL_EXPORT char * init_renderer(int argc, char ** argv);
std::string result;
hoedown_html_flags flags = HOEDOWN_HTML_ESCAPE;
hoedown_extensions extensions = static_cast<hoedown_extensions>(HOEDOWN_EXT_BLOCK | HOEDOWN_EXT_SPAN | HOEDOWN_EXT_FLAGS);
hoedown_buffer *html = NULL; //= hoedown_buffer_new(16);
hoedown_document *document = NULL;
hoedown_renderer *renderer = NULL;
char * init_renderer(int argc, char ** argv) {
renderer = hoedown_html_renderer_new(flags, 0);
document = hoedown_document_new(renderer, extensions, 16);
html = hoedown_buffer_new(16);
return "Initalized";
}
const char * render_html(int argc, char ** argv) {
if (argc < 1 || argv[0] == NULL)
return "";
result.clear();
if (renderer == NULL) return "Renderer was NULL. [Notify Host/Coder]";
if (document == NULL) return "Document was NULL. [Notify Host/Coder]";
if (html == NULL) return "HTML was NULL. [Notify Host/Coder]";
char* input_text = (char*)argv[0];
int input_length = strlen(input_text);
hoedown_document_render(document, html, (uint8_t*)input_text, input_length);
result.assign((char*)html->data, html->size);
hoedown_buffer_reset(html);
return result.c_str();
}
char * free_memory(int argc, char ** argv) {
hoedown_buffer_free(html);
hoedown_document_free(document);
hoedown_html_renderer_free(renderer);
return "Freed Memory";
}