From b0fa335b66cc74982d229c3adc6fb5845c230cb7 Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Mon, 1 Jan 2018 14:31:51 +0100 Subject: [PATCH] common: add Markdown-to-HTML conversion wrapper around cmark --- src/common/markdown.cpp | 37 +++++++++++++++++++++++++++++++++++++ src/common/markdown.h | 24 ++++++++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 src/common/markdown.cpp create mode 100644 src/common/markdown.h diff --git a/src/common/markdown.cpp b/src/common/markdown.cpp new file mode 100644 index 000000000..7ef7d3034 --- /dev/null +++ b/src/common/markdown.cpp @@ -0,0 +1,37 @@ +/* + mkvmerge -- utility for splicing together matroska files + from component media subtypes + + Distributed under the GPL v2 + see the file COPYING for details + or visit http://www.gnu.org/copyleft/gpl.html + + Written by Moritz Bunkus . +*/ + +#include "common/common_pch.h" + +#if defined(HAVE_CMARK) + +# include + +# include "common/markdown.h" + +namespace mtx { namespace markdown { + +std::string +to_html(std::string const &markdown_text, + int options) { + auto html = cmark_markdown_to_html(markdown_text.c_str(), markdown_text.length(), options); + if (!html) + return {}; + + auto html_str = std::string{html}; + free(html); + + return html_str; +} + +}} + +#endif // defined(HAVE_CMARK) diff --git a/src/common/markdown.h b/src/common/markdown.h new file mode 100644 index 000000000..c757a23e7 --- /dev/null +++ b/src/common/markdown.h @@ -0,0 +1,24 @@ +/* + mkvmerge -- utility for splicing together matroska files + from component media subtypes + + Distributed under the GPL v2 + see the file COPYING for details + or visit http://www.gnu.org/copyleft/gpl.html + + Written by Moritz Bunkus . +*/ + +#pragma once + +#include "common/common_pch.h" + +#if defined(HAVE_CMARK) + +namespace mtx { namespace markdown { + +std::string to_html(std::string const &markdown_text, int options = 0); + +}} + +#endif // defined(HAVE_CMARK)