Switch to libcmark

pull/1/head
Konstantinos Sideris 6 years ago
parent c347c0d5f5
commit 074608dec1
  1. 3
      CMakeLists.txt
  2. 39
      cmake/Findcmark.cmake
  3. 11
      deps/CMakeLists.txt
  4. 20
      deps/cmake/Maddy.cmake
  5. 15
      src/Utils.cpp

@ -250,7 +250,7 @@ find_package(OpenSSL REQUIRED)
find_package(MatrixClient 0.1.0 REQUIRED)
find_package(Olm 2 REQUIRED)
find_package(spdlog 1.0.0 CONFIG REQUIRED)
find_package(maddy 1.0.0 CONFIG REQUIRED)
find_package(cmark REQUIRED)
if(NOT LMDBXX_INCLUDE_DIR)
find_path(LMDBXX_INCLUDE_DIR
@ -362,6 +362,7 @@ set(TRANSLATION_DEPS ${LANG_QRC} ${QRC} ${QM_SRC})
set(COMMON_LIBS
MatrixClient::MatrixClient
${Boost_LIBRARIES}
cmark::cmark
Qt5::Widgets
Qt5::Svg
Qt5::Concurrent

@ -0,0 +1,39 @@
#
# CMake module to search for the cmark library
#
find_path(CMARK_INCLUDE_DIR
NAMES cmark.h
PATHS /usr/include
/usr/local/include
$ENV{LIB_DIR}/include
$ENV{LIB_DIR}/include/cmark)
find_library(CMARK_LIBRARY
NAMES cmark
PATHS /usr/lib /usr/local/lib $ENV{LIB_DIR}/lib)
if(OLM_FOUND)
set(OLM_INCLUDE_DIRS ${CMARK_INCLUDE_DIR})
if(NOT OLM_LIBRARIES)
set(OLM_LIBRARIES ${CMARK_LIBRARY})
endif()
endif()
if(NOT TARGET cmark::cmark)
add_library(cmark::cmark UNKNOWN IMPORTED)
set_target_properties(cmark::cmark
PROPERTIES INTERFACE_INCLUDE_DIRECTORIES
${CMARK_INCLUDE_DIR})
set_property(TARGET cmark::cmark APPEND
PROPERTY IMPORTED_LOCATION ${CMARK_LIBRARY})
endif()
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(cmark
DEFAULT_MSG
CMARK_INCLUDE_DIR
CMARK_LIBRARY)
mark_as_advanced(CMARK_LIBRARY CMARK_INCLUDE_DIR)

@ -26,7 +26,6 @@ option(USE_BUNDLED_SPDLOG "Use the bundled version of spdlog." ${USE_BUNDLED})
option(USE_BUNDLED_OLM "Use the bundled version of libolm." ${USE_BUNDLED})
option(USE_BUNDLED_TWEENY "Use the bundled version of Tweeny." ${USE_BUNDLED})
option(USE_BUNDLED_LMDBXX "Use the bundled version of lmdbxx." ${USE_BUNDLED})
option(USE_BUNDLED_MADDY "Use the bundled version of maddy." ${USE_BUNDLED})
option(USE_BUNDLED_MATRIX_CLIENT "Use the bundled version of mtxclient."
${USE_BUNDLED})
@ -65,12 +64,6 @@ set(SPDLOG_URL https://github.com/gabime/spdlog/archive/v1.1.0.tar.gz)
set(SPDLOG_HASH
3dbcbfd8c07e25f5e0d662b194d3a7772ef214358c49ada23c044c4747ce8b19)
set(
MADDY_URL
https://github.com/mujx/maddy/archive/d6b32013a580d40de57ac8b6650846abecbb071f.tar.gz
)
set(MADDY_HASH c40df975420aa9f1549d9e528af84243f701b5264ed9c32d86b1cfc9306c15b8)
set(JSON_HEADER_URL
https://github.com/nlohmann/json/releases/download/v3.2.0/json.hpp)
set(JSON_HEADER_HASH
@ -87,10 +80,6 @@ if(USE_BUNDLED_SPDLOG)
include(SpdLog)
endif()
if(USE_BUNDLED_MADDY)
include(Maddy)
endif()
if(USE_BUNDLED_OLM)
include(Olm)
endif()

@ -1,20 +0,0 @@
set(WINDOWS_FLAGS "")
if(MSVC)
set(WINDOWS_FLAGS "-DCMAKE_GENERATOR_PLATFORM=x64")
endif()
ExternalProject_Add(
Maddy
URL ${MADDY_URL}
URL_HASH SHA256=${MADDY_HASH}
BUILD_IN_SOURCE 1
SOURCE_DIR ${DEPS_BUILD_DIR}/maddy
CONFIGURE_COMMAND ${CMAKE_COMMAND}
-DCMAKE_INSTALL_PREFIX=${DEPS_INSTALL_DIR}
${DEPS_BUILD_DIR}/maddy
${WINDOWS_FLAGS})
list(APPEND THIRD_PARTY_DEPS Maddy)

@ -8,7 +8,7 @@
#include <cmath>
#include <boost/variant.hpp>
#include <maddy/parser.h>
#include <cmark.h>
#include "Config.h"
@ -333,16 +333,21 @@ utils::linkifyMessage(const QString &body)
std::string
utils::markdownToHtml(const std::string &text)
{
std::stringstream markdownInput(text);
auto parser = std::make_shared<maddy::Parser>();
const char *tmp_buf = cmark_markdown_to_html(text.c_str(), text.size(), CMARK_OPT_DEFAULT);
return parser->Parse(markdownInput);
// Copy the null terminated output buffer.
std::string html(tmp_buf);
// The buffer is no longer needed.
free((char *)tmp_buf);
return html;
}
std::string
utils::markdownToHtml(const QString &text)
{
return markdownToHtml(text.toStdString());
return utils::markdownToHtml(text.toStdString());
}
std::string

Loading…
Cancel
Save