]> www.infradead.org Git - pidgin-chime.git/commitdiff
Add markdown support
authorJohn Glotzer <glotzer@amazon.com>
Sun, 31 Dec 2017 20:54:50 +0000 (12:54 -0800)
committerPhillip Berndt <pberndt@amazon.com>
Sat, 9 Feb 2019 12:25:44 +0000 (13:25 +0100)
Makefile.am
prpl/markdown.c [new file with mode: 0644]
prpl/markdown.h [new file with mode: 0644]

index e6cd9d95a278c8e13c3c1064bf03af8571103e0e..f34be067f03e3031dfaf10dad214607aae3fc8fc 100644 (file)
@@ -23,7 +23,7 @@ PROTOBUF_SRCS = protobuf/auth_message.pb-c.c protobuf/auth_message.pb-c.h \
 
 PRPL_SRCS =    prpl/chime.h prpl/chime.c prpl/buddy.c prpl/rooms.c prpl/chat.c \
                prpl/messages.c prpl/conversations.c prpl/meeting.c prpl/attachments.c \
-               prpl/authenticate.c
+               prpl/authenticate.c prpl/markdown.c
 
 WEBSOCKET_SRCS = chime/chime-websocket-connection.c chime/chime-websocket-connection.h \
                chime/chime-websocket.c
diff --git a/prpl/markdown.c b/prpl/markdown.c
new file mode 100644 (file)
index 0000000..885ba9d
--- /dev/null
@@ -0,0 +1,47 @@
+#include "markdown.h"
+#include <debug.h>
+#include <string.h>
+#include <stdlib.h>
+#include <prpl.h>
+
+/*
+ * Uses libmarkdown to convert md to html.
+ * Caller must g_free the returned string.
+ */
+int
+do_markdown (const gchar *message, gchar **outbound) {
+       MMIOT *doc;
+       int flags = 0;
+       int nbytes, rc;
+       gchar *res;
+
+       /* make a mkd doc */
+       doc = mkd_string(message, strlen(message), flags);
+       if (!doc) {
+               purple_debug(PURPLE_DEBUG_ERROR, "chime", "mkd_string() failed.\n");
+               return -1;
+       }
+
+       /* compile the mkd doc */
+       rc = mkd_compile(doc, flags);
+       if (rc == EOF) {
+               purple_debug(PURPLE_DEBUG_ERROR, "chime", "mkd_compile failed.\n");
+               mkd_cleanup(doc);
+               return -1;
+       }
+
+       /* render the html output */
+       nbytes = mkd_document(doc, &res);
+       if (nbytes <= 0) {
+               purple_debug(PURPLE_DEBUG_ERROR, "chime", "mkd_document() failed.\n");
+               mkd_cleanup(doc);
+               return -1;
+       }
+
+       /* Since mkd_cleanup also frees res make a copy before cleaning up. */
+       *outbound = g_strdup(res);
+
+       mkd_cleanup(doc);
+
+       return 0;
+}
diff --git a/prpl/markdown.h b/prpl/markdown.h
new file mode 100644 (file)
index 0000000..1bb097f
--- /dev/null
@@ -0,0 +1,4 @@
+#include <mkdio.h>
+#include <glib.h>
+
+int do_markdown(const gchar *message, gchar **outbound);