Skip to content

Commit

Permalink
Fixed issue #136
Browse files Browse the repository at this point in the history
  • Loading branch information
Mandarancio committed Jan 26, 2018
1 parent 489cec8 commit 2319c2e
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 81 deletions.
8 changes: 0 additions & 8 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,6 @@ shared_library(
install_dir: WEB_EXTENSIONS_DIRECTORY
)

# shared_library(
# 'click-extension',
# sources : [click_extension],
# dependencies : ext_deps,
# install : true,
# install_dir: WEB_EXTENSIONS_DIRECTORY
# )

executable(
EXECUTABLE_NAME,
sources : [marker_sources, hoedown_sources],
Expand Down
80 changes: 40 additions & 40 deletions src/marker-markdown.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ char* html_header(MarkerKaTeXMode katex_mode,
mermaid_script = g_strdup_printf("<script src=\"%smermaid/mermaid.min.js\"></script>", SCRIPTS_DIR);
break;
}

char * buffer = g_strdup_printf("<!doctype html>"
"<html>\n"
"<head>\n"
Expand Down Expand Up @@ -142,7 +142,7 @@ html_footer(MarkerKaTeXMode katex_mode,
highlight_render = g_strdup("<script>hljs.initHighlightingOnLoad();</script>");
break;
}

switch(mermaid_mode)
{
case MERMAID_OFF:
Expand All @@ -163,11 +163,11 @@ html_footer(MarkerKaTeXMode katex_mode,
return buffer;
}

hoedown_html_flags
hoedown_html_flags
get_html_mode(MarkerMermaidMode mermaid_mode)
{
hoedown_html_flags mode = 0;

if (mermaid_mode != MERMAID_OFF)
{
mode |= HOEDOWN_HTML_MERMAID;
Expand All @@ -187,7 +187,7 @@ get_html_mode(MarkerMermaidMode mermaid_mode)
{
mode |= HOEDOWN_HTML_EQCOUNTER;
}

if (marker_prefs_get_use_charter())
{
mode |= HOEDOWN_HTML_CHARTER;
Expand Down Expand Up @@ -221,20 +221,20 @@ marker_markdown_to_html(const char* markdown,
hoedown_html_flags html_mode = get_html_mode(mermaid_mode);

renderer = hoedown_html_renderer_new(html_mode, 0, get_local());

document = hoedown_document_new(renderer,
HOEDOWN_EXT_BLOCK |
HOEDOWN_EXT_SPAN |
HOEDOWN_EXT_MATH |
HOEDOWN_EXT_MATH_EXPLICIT |
HOEDOWN_EXT_FLAGS,
16);
buffer = hoedown_buffer_new(500);

buffer = hoedown_buffer_new(500);

char * header = html_header(katex_mode, highlight_mode, mermaid_mode);


hoedown_buffer_printf(buffer,
"%s",
header);
Expand All @@ -244,27 +244,27 @@ marker_markdown_to_html(const char* markdown,
{
hoedown_buffer_printf(buffer, "<link rel=\"stylesheet\" type=\"text/css\" href=\"%s\">\n", stylesheet_location);
}

hoedown_buffer_puts(buffer,
"</head>\n"
"<body>\n");

hoedown_document_render(document, buffer, (uint8_t*) markdown, size);

char * footer = html_footer(katex_mode, highlight_mode, mermaid_mode);
hoedown_buffer_printf(buffer,
"%s\n",
footer);
g_free(footer);

const char* buf_cstr = hoedown_buffer_cstr(buffer);

html = strdup(buf_cstr);

hoedown_html_renderer_free(renderer);
hoedown_document_free(document);
hoedown_buffer_free(buffer);

return html;
}

Expand All @@ -278,14 +278,14 @@ marker_markdown_to_html_with_css_inline(const char* markdown,
{
char* html = NULL;


FILE* fp = NULL;
fp = fopen(stylesheet_location, "r");
char* inline_css = NULL;
if (fp)
{
inline_css = NULL;

fseek(fp , 0 , SEEK_END);
long size = ftell(fp);
rewind(fp);
Expand All @@ -299,28 +299,28 @@ marker_markdown_to_html_with_css_inline(const char* markdown,
hoedown_renderer* renderer;
hoedown_document* document;
hoedown_buffer* buffer;
hoedown_html_flags html_mode = get_html_mode(mermaid_mode);
hoedown_html_flags html_mode = get_html_mode(mermaid_mode);

renderer = hoedown_html_renderer_new(html_mode, 0, get_local());

document = hoedown_document_new(renderer,
HOEDOWN_EXT_BLOCK |
HOEDOWN_EXT_SPAN |
HOEDOWN_EXT_MATH |
HOEDOWN_EXT_MATH_EXPLICIT |
HOEDOWN_EXT_FLAGS,
16);

buffer = hoedown_buffer_new(500);

char * header = html_header(katex_mode, highlight_mode, mermaid_mode);

hoedown_buffer_printf(buffer,
"%s\n",
header);

g_free(header);

if(inline_css)
{
hoedown_buffer_printf(buffer,
Expand All @@ -329,27 +329,27 @@ marker_markdown_to_html_with_css_inline(const char* markdown,
free(inline_css);
inline_css = NULL;
}

hoedown_buffer_puts(buffer,
"</head>\n"
"<body>\n");

hoedown_document_render(document, buffer, (uint8_t*) markdown, size);

char * footer = html_footer(katex_mode, highlight_mode, mermaid_mode);
hoedown_buffer_printf(buffer,
"%s\n",
footer);
g_free(footer);

const char* buf_cstr = hoedown_buffer_cstr(buffer);
html = strdup(buf_cstr);

hoedown_html_renderer_free(renderer);
hoedown_document_free(document);
hoedown_buffer_free(buffer);


return html;
}

Expand All @@ -362,11 +362,11 @@ marker_markdown_to_html_file(const char* markdown,
const char* stylesheet_location,
const char* filepath)
{
char* html = marker_markdown_to_html(markdown,
size,
katex_mode,
highlight_mode,
mermaid_mode,
char* html = marker_markdown_to_html(markdown,
size,
katex_mode,
highlight_mode,
mermaid_mode,
stylesheet_location);
FILE* fp = fopen(filepath, "w");
if (fp && html)
Expand All @@ -386,11 +386,11 @@ marker_markdown_to_html_file_with_css_inline(const char* markdown,
const char* stylesheet_location,
const char* filepath)
{
char* html = marker_markdown_to_html_with_css_inline(markdown,
size,
katex_mode,
highlight_mode,
mermaid_mode,
char* html = marker_markdown_to_html_with_css_inline(markdown,
size,
katex_mode,
highlight_mode,
mermaid_mode,
stylesheet_location);
FILE* fp = fopen(filepath, "w");
printf("fp: %p\nfilepath: %s\n", fp, filepath);
Expand Down
Loading

0 comments on commit 2319c2e

Please sign in to comment.