|
|
@@ -0,0 +1,89 @@
|
|
|
+/* iridium-markdown.c
|
|
|
+ *
|
|
|
+ * Copyright 2018 Matthias Vogelgesang
|
|
|
+ *
|
|
|
+ * This program is free software: you can redistribute it and/or modify
|
|
|
+ * it under the terms of the GNU General Public License as published by
|
|
|
+ * the Free Software Foundation, either version 3 of the License, or
|
|
|
+ * (at your option) any later version.
|
|
|
+ *
|
|
|
+ * This program is distributed in the hope that it will be useful,
|
|
|
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
+ * GNU General Public License for more details.
|
|
|
+ *
|
|
|
+ * You should have received a copy of the GNU General Public License
|
|
|
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
+ */
|
|
|
+
|
|
|
+#include <string.h>
|
|
|
+#include <mkdio.h>
|
|
|
+#include "iridium-config.h"
|
|
|
+#include "iridium-markdown.h"
|
|
|
+
|
|
|
+struct _IridiumMarkdown
|
|
|
+{
|
|
|
+ GObject parent_instance;
|
|
|
+};
|
|
|
+
|
|
|
+G_DEFINE_TYPE (IridiumMarkdown, iridium_markdown, G_TYPE_OBJECT)
|
|
|
+
|
|
|
+IridiumMarkdown *
|
|
|
+iridium_markdown_new (void)
|
|
|
+{
|
|
|
+ return g_object_new (IRIDIUM_TYPE_MARKDOWN, NULL);
|
|
|
+}
|
|
|
+
|
|
|
+static void
|
|
|
+compile_thread (GTask *task,
|
|
|
+ gpointer source_object,
|
|
|
+ gpointer task_data,
|
|
|
+ GCancellable *cancellable)
|
|
|
+{
|
|
|
+ MMIOT *doc;
|
|
|
+ gchar *markdown;
|
|
|
+ gchar *html = NULL;
|
|
|
+
|
|
|
+ markdown = (gchar *) task_data;
|
|
|
+ doc = mkd_string (markdown, strlen (markdown), MKD_TOC);
|
|
|
+ mkd_compile (doc, MKD_TOC);
|
|
|
+ mkd_document (doc, &html);
|
|
|
+
|
|
|
+ g_task_return_pointer (task, g_strdup (html), g_free);
|
|
|
+ mkd_cleanup (doc);
|
|
|
+}
|
|
|
+
|
|
|
+void
|
|
|
+iridium_markdown_compile_async (IridiumMarkdown *self,
|
|
|
+ const gchar *markdown,
|
|
|
+ gint priority,
|
|
|
+ GCancellable *cancellable,
|
|
|
+ GAsyncReadyCallback callback,
|
|
|
+ gpointer user_data)
|
|
|
+{
|
|
|
+ GTask *task;
|
|
|
+
|
|
|
+ task = g_task_new (self, cancellable, callback, user_data);
|
|
|
+ g_task_run_in_thread (task, compile_thread);
|
|
|
+ g_task_set_task_data (task, g_strdup (markdown), g_free);
|
|
|
+ g_object_unref (task);
|
|
|
+}
|
|
|
+
|
|
|
+gpointer
|
|
|
+iridium_markdown_compile_finish (GObject *object,
|
|
|
+ GAsyncResult *result,
|
|
|
+ GError **error)
|
|
|
+{
|
|
|
+ g_return_val_if_fail (g_task_is_valid (result, object), NULL);
|
|
|
+ return g_task_propagate_pointer (G_TASK (result), error);
|
|
|
+}
|
|
|
+
|
|
|
+static void
|
|
|
+iridium_markdown_class_init (IridiumMarkdownClass *klass)
|
|
|
+{
|
|
|
+}
|
|
|
+
|
|
|
+static void
|
|
|
+iridium_markdown_init (IridiumMarkdown *self)
|
|
|
+{
|
|
|
+}
|