common: add Markdown-to-HTML conversion wrapper around cmark

This commit is contained in:
Moritz Bunkus 2018-01-01 14:31:51 +01:00
parent f700dfbd1e
commit b0fa335b66
2 changed files with 61 additions and 0 deletions

37
src/common/markdown.cpp Normal file
View File

@ -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 <moritz@bunkus.org>.
*/
#include "common/common_pch.h"
#if defined(HAVE_CMARK)
# include <cmark.h>
# 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)

24
src/common/markdown.h Normal file
View File

@ -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 <moritz@bunkus.org>.
*/
#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)