From: John Glotzer Date: Sun, 31 Dec 2017 20:54:50 +0000 (-0800) Subject: Add markdown support X-Git-Tag: v1.4~13^2~2 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=c2ea151b2414067ec42d8f82105ce0e6820dfbbf;p=pidgin-chime.git Add markdown support --- diff --git a/Makefile.am b/Makefile.am index e6cd9d9..f34be06 100644 --- a/Makefile.am +++ b/Makefile.am @@ -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 index 0000000..885ba9d --- /dev/null +++ b/prpl/markdown.c @@ -0,0 +1,47 @@ +#include "markdown.h" +#include +#include +#include +#include + +/* + * 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 index 0000000..1bb097f --- /dev/null +++ b/prpl/markdown.h @@ -0,0 +1,4 @@ +#include +#include + +int do_markdown(const gchar *message, gchar **outbound);