Added markdown support

This commit is contained in:
Markus Koch 2017-02-16 20:06:29 +01:00
parent cc6bfe82a1
commit 39fe7891de
4 changed files with 46 additions and 8 deletions

View File

@ -7,7 +7,7 @@ find_package(PkgConfig REQUIRED)
pkg_check_modules(GLIB2 REQUIRED glib-2.0)
pkg_check_modules(GOBJECT2 REQUIRED gobject-2.0)
pkg_check_modules(GTK3 REQUIRED gtk+-3.0)
pkg_check_modules(WEBKIT REQUIRED webkitgtk-3.0)
pkg_check_modules(WEBKIT REQUIRED webkit2gtk-4.0)
INCLUDE_DIRECTORIES (${GLIB2_INCLUDE_DIRS} ${GOBJECT2_INCLUDE_DIRS} ${GTK3_INCLUDE_DIRS} ${WEBKIT_INCLUDE_DIRS})
LINK_DIRECTORIES (${GLIB2_LIBRARY_DIRS} ${GOBJECT2_LIBRARY_DIRS} ${GTK3_LIBRARY_DIRS} ${WEBKIT_LIBRARY_DIRS})

View File

@ -13,7 +13,7 @@ int main(int argc, char *argv[])
gtk_init(&argc, &argv);
mainWindow = mainWindow_new();
mainWindow = mainWindow_new(TRUE);
settings_path = g_strdup_printf("%s/.mdiary.conf", g_get_home_dir());
settings = mdiary_settings_new(mainWindow);

View File

@ -429,8 +429,7 @@ static void mainWindow_webkit_init(struct mainWindow *mainWindow)
GtkWidget *scrollArea;
mainWindow->webkitView = webkit_web_view_new();
/* webkit_web_view_load_uri(WEBKIT_WEB_VIEW(mainWindow->webkitView), "https://notsyncing.net/"); */
webkit_web_view_load_html(WEBKIT_WEB_VIEW(mainWindow->webkitView), "test", "");
webkit_web_view_load_html_string(WEBKIT_WEB_VIEW(mainWindow->webkitView), "", "");
gtk_widget_show(mainWindow->webkitView);
scrollArea = gtk_scrolled_window_new(NULL, NULL);
@ -445,7 +444,7 @@ static void mainWindow_webkit_init(struct mainWindow *mainWindow)
* @brief mainWindow_new creates a new mainWindow.
* @return Returns struct mainWindow *
*/
struct mainWindow *mainWindow_new()
struct mainWindow *mainWindow_new(gboolean webkit_mode)
{
GtkBuilder *builder;
struct mainWindow *mainWindow;
@ -494,7 +493,10 @@ struct mainWindow *mainWindow_new()
g_object_unref(G_OBJECT(builder));
mainWindow_configure_treeView(mainWindow);
mainWindow_webkit_init(mainWindow);
if (webkit_mode)
mainWindow_webkit_init(mainWindow);
else
mainWindow->webkitView = NULL;
mainWindow_connect_signals(mainWindow);
mainWindow_configure_workspaceTreeView(mainWindow);
mainWindow_init_to_default(mainWindow);
@ -597,7 +599,43 @@ void mainWindow_entrySelected(GtkWidget *widget, gpointer user_data)
selection = gtk_tree_view_get_selection(mainWindow->entryListView);
if (gtk_tree_selection_get_selected(selection, &model, &iter)) {
gtk_tree_model_get(model, &iter, COL_TEXT, &text, -1);
gtk_text_buffer_set_text(mainWindow->textBuffer, text, strlen(text));
if (mainWindow->webkitView) {
gchar *tempfile_path = "/tmp/mdiary.tmp.md";
gchar *cmd = NULL;
gchar *cmd_stdout = NULL;
gchar *cmd_stderr = NULL;
gint exit_status = 0;
GFileOutputStream *stream;
GFile *file;
file = g_file_new_for_path(tempfile_path);
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);
if (g_spawn_command_line_sync(cmd, &cmd_stdout, &cmd_stderr, &exit_status, NULL) &&
exit_status == 0) {
webkit_web_view_load_html_string(WEBKIT_WEB_VIEW(mainWindow->webkitView),
cmd_stdout, "");
} else {
webkit_web_view_load_html_string(WEBKIT_WEB_VIEW(mainWindow->webkitView),
text, "");
}
g_output_stream_close(G_OUTPUT_STREAM(stream), NULL, NULL);
g_file_delete(file, NULL, NULL);
g_object_unref(stream);
g_object_unref(file);
g_free(cmd);
g_free(cmd_stdout);
g_free(cmd_stderr);
} else {
gtk_text_buffer_set_text(mainWindow->textBuffer, text, strlen(text));
}
g_free(text);
gtk_tree_model_get(model, &iter, COL_SUMMARY, &summary, -1);

View File

@ -67,7 +67,7 @@ struct mainWindow {
GtkTreeModelFilter *workspaceListFiltered;
};
struct mainWindow *mainWindow_new();
struct mainWindow *mainWindow_new(gboolean webkit_mode);
void mainWindow_set_meta_information(struct mainWindow *mainWindow,
guint time_earliest,
guint time_latest,