From 074608dec15e10a61decdcc017cc1927b99b8dc3 Mon Sep 17 00:00:00 2001 From: Konstantinos Sideris Date: Tue, 11 Sep 2018 14:56:09 +0300 Subject: [PATCH] Switch to libcmark --- CMakeLists.txt | 3 ++- cmake/Findcmark.cmake | 39 +++++++++++++++++++++++++++++++++++++++ deps/CMakeLists.txt | 11 ----------- deps/cmake/Maddy.cmake | 20 -------------------- src/Utils.cpp | 15 ++++++++++----- 5 files changed, 51 insertions(+), 37 deletions(-) create mode 100644 cmake/Findcmark.cmake delete mode 100644 deps/cmake/Maddy.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 741f4ae..05436a3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 diff --git a/cmake/Findcmark.cmake b/cmake/Findcmark.cmake new file mode 100644 index 0000000..fd7d062 --- /dev/null +++ b/cmake/Findcmark.cmake @@ -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) diff --git a/deps/CMakeLists.txt b/deps/CMakeLists.txt index 3160375..5df60d2 100644 --- a/deps/CMakeLists.txt +++ b/deps/CMakeLists.txt @@ -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() diff --git a/deps/cmake/Maddy.cmake b/deps/cmake/Maddy.cmake deleted file mode 100644 index 699d214..0000000 --- a/deps/cmake/Maddy.cmake +++ /dev/null @@ -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) diff --git a/src/Utils.cpp b/src/Utils.cpp index 5d5508b..6ac675d 100644 --- a/src/Utils.cpp +++ b/src/Utils.cpp @@ -8,7 +8,7 @@ #include #include -#include +#include #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(); + 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