Change Markdown renderer to statically link hoedown
This commit is contained in:
parent
1287949669
commit
16c3dcac15
3
.gitmodules
vendored
Normal file
3
.gitmodules
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
[submodule "src/hoedown"]
|
||||||
|
path = src/hoedown
|
||||||
|
url = git@github.com:hoedown/hoedown.git
|
@ -21,9 +21,21 @@ add_custom_command(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/resources.c"
|
|||||||
COMMENT "Generating resources"
|
COMMENT "Generating resources"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
add_custom_command(OUTPUT "${CMAKE_CURRENT_SOURCE_DIR}/src/hoedown/libhoedown.a"
|
||||||
|
COMMAND make libhoedown.a
|
||||||
|
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/src/hoedown"
|
||||||
|
COMMENT "Compiling libhoedown"
|
||||||
|
)
|
||||||
|
|
||||||
|
ADD_LIBRARY(HOEDOWN STATIC IMPORTED)
|
||||||
|
SET_TARGET_PROPERTIES(HOEDOWN PROPERTIES
|
||||||
|
IMPORTED_LOCATION "${CMAKE_CURRENT_SOURCE_DIR}/src/hoedown/libhoedown.a"
|
||||||
|
)
|
||||||
|
|
||||||
aux_source_directory(./src SRC_LIST)
|
aux_source_directory(./src SRC_LIST)
|
||||||
add_executable(${PROJECT_NAME} ${SRC_LIST})
|
add_executable(${PROJECT_NAME} ${SRC_LIST})
|
||||||
target_sources(${PROJECT_NAME} PUBLIC "${CMAKE_CURRENT_BINARY_DIR}/resources.c")
|
target_sources(${PROJECT_NAME} PUBLIC "${CMAKE_CURRENT_BINARY_DIR}/resources.c")
|
||||||
target_link_libraries(${PROJECT_NAME} ${GTK3_LIBRARIES} ${WEBKIT_LIBRARIES})
|
target_sources(${PROJECT_NAME} PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/src/hoedown/libhoedown.a")
|
||||||
|
target_link_libraries(${PROJECT_NAME} ${GTK3_LIBRARIES} ${WEBKIT_LIBRARIES} HOEDOWN)
|
||||||
|
|
||||||
install (TARGETS ${PROJECT_NAME} DESTINATION bin)
|
install (TARGETS ${PROJECT_NAME} DESTINATION bin)
|
||||||
|
@ -13,7 +13,7 @@ Renders everything as is. You will see the source code except for the header abo
|
|||||||
The following constructs are supported: *italics*, **bold**, Headings 1 to 4.
|
The following constructs are supported: *italics*, **bold**, Headings 1 to 4.
|
||||||
|
|
||||||
## Full HTML with Images
|
## Full HTML with Images
|
||||||
As the external md command is invoked and a web browser used to render the content, all markdown syntax supported by the md command is supported.
|
Markdown is rendered using [Hoedown](https://github.com/hoedown/hoedown/) and displayed using an integrated web browser. This all Markdown syntax (including images) are supported.
|
||||||
|
|
||||||
# Encrypted Entries Using GPG
|
# Encrypted Entries Using GPG
|
||||||
MDiary supports gpg encrypted entries. To use this feature, place a gpg encrypted entry as *<name>.md.gpg* in the workspace. MDiary will automatically show a decrypt button in the header bar which will invoke gpg to decrypt all encrypted entries in the workspace for this session.
|
MDiary supports gpg encrypted entries. To use this feature, place a gpg encrypted entry as *<name>.md.gpg* in the workspace. MDiary will automatically show a decrypt button in the header bar which will invoke gpg to decrypt all encrypted entries in the workspace for this session.
|
||||||
|
1
src/hoedown
Submodule
1
src/hoedown
Submodule
@ -0,0 +1 @@
|
|||||||
|
Subproject commit 980b9c549b4348d50b683ecee6abee470b98acda
|
@ -771,16 +771,18 @@ void mainWindow_calendarSelected(GtkWidget *widget, gpointer user_data)
|
|||||||
|
|
||||||
static void mainWindow_set_text(struct mainWindow *mainWindow, gchar *text, gchar *file_url)
|
static void mainWindow_set_text(struct mainWindow *mainWindow, gchar *text, gchar *file_url)
|
||||||
{
|
{
|
||||||
gchar *tempfile_path = "/tmp/mdiary.tmp.md";
|
|
||||||
gchar *cmd = NULL;
|
gchar *cmd = NULL;
|
||||||
gchar *cmd_stdout = NULL;
|
gchar *cmd_stdout = NULL;
|
||||||
gchar *cmd_stderr = NULL;
|
gchar *cmd_stderr = NULL;
|
||||||
gint exit_status = 0;
|
|
||||||
gchar *base_url = NULL;
|
|
||||||
GFileOutputStream *stream = NULL;
|
GFileOutputStream *stream = NULL;
|
||||||
GFile *file = NULL;
|
GFile *file = NULL;
|
||||||
GtkTextIter iter;
|
GtkTextIter iter;
|
||||||
GtkTextIter iter_end;
|
GtkTextIter iter_end;
|
||||||
|
hoedown_buffer *ob;
|
||||||
|
hoedown_renderer *renderer = NULL;
|
||||||
|
void (*renderer_free)(hoedown_renderer *) = NULL;
|
||||||
|
hoedown_document *document;
|
||||||
|
gchar *base_url = NULL;
|
||||||
|
|
||||||
if (mainWindow->renderer == RENDERER_TEXT) {
|
if (mainWindow->renderer == RENDERER_TEXT) {
|
||||||
gtk_text_buffer_set_text(mainWindow->textBuffer, text, strlen(text));
|
gtk_text_buffer_set_text(mainWindow->textBuffer, text, strlen(text));
|
||||||
@ -802,24 +804,21 @@ static void mainWindow_set_text(struct mainWindow *mainWindow, gchar *text, gcha
|
|||||||
} else {
|
} else {
|
||||||
if (text[0] != '\0') {
|
if (text[0] != '\0') {
|
||||||
base_url = g_strdup_printf("file://%s", file_url);
|
base_url = g_strdup_printf("file://%s", file_url);
|
||||||
file = g_file_new_for_path(tempfile_path);
|
g_info("Rendering markdown as full HTML...");
|
||||||
stream = g_file_replace(
|
|
||||||
file, NULL, FALSE,
|
|
||||||
G_FILE_CREATE_NONE,
|
|
||||||
NULL, NULL);
|
|
||||||
g_output_stream_write(G_OUTPUT_STREAM(stream), text, strlen(text), NULL, NULL);
|
|
||||||
g_output_stream_flush(G_OUTPUT_STREAM(stream), NULL, NULL);
|
|
||||||
|
|
||||||
cmd = g_strdup_printf("markdown %s", tempfile_path);
|
renderer = hoedown_html_renderer_new(0, 0);
|
||||||
if (g_spawn_command_line_sync(cmd, &cmd_stdout, &cmd_stderr, &exit_status, NULL) &&
|
renderer_free = hoedown_html_renderer_free;
|
||||||
exit_status == 0) {
|
|
||||||
webkit_web_view_load_html(WEBKIT_WEB_VIEW(mainWindow->webkitView),
|
ob = hoedown_buffer_new(64);
|
||||||
cmd_stdout, base_url);
|
document = hoedown_document_new(renderer, 0, 16);
|
||||||
} else {
|
hoedown_document_render(document, ob, (const uint8_t *) text, strlen(text));
|
||||||
g_warning("Could not render markdown for file. Showing plain text instead.\n");
|
|
||||||
webkit_web_view_load_html(WEBKIT_WEB_VIEW(mainWindow->webkitView),
|
webkit_web_view_load_html(WEBKIT_WEB_VIEW(mainWindow->webkitView),
|
||||||
text, base_url);
|
hoedown_buffer_cstr(ob), base_url);
|
||||||
}
|
|
||||||
|
hoedown_buffer_free(ob);
|
||||||
|
hoedown_document_free(document);
|
||||||
|
renderer_free(renderer);
|
||||||
g_free(base_url);
|
g_free(base_url);
|
||||||
} else {
|
} else {
|
||||||
webkit_web_view_load_html(WEBKIT_WEB_VIEW(mainWindow->webkitView),
|
webkit_web_view_load_html(WEBKIT_WEB_VIEW(mainWindow->webkitView),
|
||||||
|
@ -8,6 +8,9 @@
|
|||||||
#include "mdiary.h"
|
#include "mdiary.h"
|
||||||
#include "md_pango.h"
|
#include "md_pango.h"
|
||||||
|
|
||||||
|
#include "hoedown/src/document.h"
|
||||||
|
#include "hoedown/src/html.h"
|
||||||
|
|
||||||
#define FILE_LIST_MAX_LEN 5
|
#define FILE_LIST_MAX_LEN 5
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
|
Loading…
Reference in New Issue
Block a user