From 91b687d5e794ef245e4aa43e1a20393b47b771cc Mon Sep 17 00:00:00 2001 From: "M. Petra Baranski" Date: Mon, 25 Dec 2017 21:21:59 +0100 Subject: [PATCH] fixed inline code for bold, em and s In inline code the markdown for bold , emphasized and strike trhough is not parsed anymore. Additionally the linker might be now faster on Linux. --- CMakeLists.txt | 17 ++++++++++++++++- include/maddy/emphasizedparser.h | 2 +- include/maddy/strikethroughparser.h | 2 +- include/maddy/strongparser.h | 2 +- tests/maddy/test_maddy_emphasizedparser.cpp | 11 +++++++++++ tests/maddy/test_maddy_strikethroughparser.cpp | 11 +++++++++++ tests/maddy/test_maddy_strongparser.cpp | 11 +++++++++++ 7 files changed, 52 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ce9e447..becb22a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -27,11 +27,26 @@ file(GLOB_RECURSE MADDY_TESTS_FILES ${CMAKE_CURRENT_SOURCE_DIR}/tests/maddy/*.cp set( CMAKE_CXX_FLAGS - "${CMAKE_CXX_FLAGS} -g -std=c++${MADDY_CPP_VERSION} -Wall -Wpedantic -Wextra -Wno-ignored-qualifiers -fno-rtti -fno-exceptions" # -O2 + "${CMAKE_CXX_FLAGS} -g -std=c++${MADDY_CPP_VERSION} -Wall -Wpedantic -Wextra -Wno-ignored-qualifiers -fno-rtti -fno-exceptions" ) # ------------------------------------------------------------------------------ +if (UNIX AND NOT APPLE) + execute_process(COMMAND ${CMAKE_CXX_COMPILER} + -fuse-ld=gold -Wl,--version + ERROR_QUIET OUTPUT_VARIABLE ld_version) + if ("${ld_version}" MATCHES "GNU gold") + message(STATUS "Found Gold linker, use faster linker") + set(CMAKE_EXE_LINKER_FLAGS + "${CMAKE_EXE_LINKER_FLAGS} -fuse-ld=gold") + set(CMAKE_SHARED_LINKER_FLAGS + "${CMAKE_SHARED_LINKER_FLAGS} -fuse-ld=gold ") + endif() +endif() + +# ------------------------------------------------------------------------------ + set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/libs/gtest/googlemock) add_subdirectory(libs) diff --git a/include/maddy/emphasizedparser.h b/include/maddy/emphasizedparser.h index 973e09d..40fdae6 100644 --- a/include/maddy/emphasizedparser.h +++ b/include/maddy/emphasizedparser.h @@ -41,7 +41,7 @@ public: void Parse(std::string& line) override { - static std::regex re("\\*([^\\*]*)\\*"); + static std::regex re("(?!`|)\\*(?!`|)([^\\*]*)\\*(?!`|)"); static std::string replacement = "$1"; line = std::regex_replace(line, re, replacement); diff --git a/include/maddy/strikethroughparser.h b/include/maddy/strikethroughparser.h index 22fb1c4..bc7002a 100644 --- a/include/maddy/strikethroughparser.h +++ b/include/maddy/strikethroughparser.h @@ -39,7 +39,7 @@ public: void Parse(std::string& line) override { - static std::regex re("\\~\\~([^\\~]*)\\~\\~"); + static std::regex re("(?!`|)\\~\\~(?!`|)([^\\~]*)\\~\\~(?!`|)"); static std::string replacement = "$1"; line = std::regex_replace(line, re, replacement); diff --git a/include/maddy/strongparser.h b/include/maddy/strongparser.h index 339af79..4ca0fa5 100644 --- a/include/maddy/strongparser.h +++ b/include/maddy/strongparser.h @@ -41,7 +41,7 @@ public: void Parse(std::string& line) override { - static std::regex re("\\*\\*([^\\*\\*]*)\\*\\*"); + static std::regex re("(?!`|)\\*\\*(?!`|)([^\\*\\*]*)\\*\\*(?!`|)"); static std::string replacement = "$1"; line = std::regex_replace(line, re, replacement); diff --git a/tests/maddy/test_maddy_emphasizedparser.cpp b/tests/maddy/test_maddy_emphasizedparser.cpp index 886a451..e908c37 100644 --- a/tests/maddy/test_maddy_emphasizedparser.cpp +++ b/tests/maddy/test_maddy_emphasizedparser.cpp @@ -20,3 +20,14 @@ TEST(MADDY_EMPHASIZEDPARSER, ItReplacesMarkdownWithEmphasizedHTML) ASSERT_EQ(expected, text); } + +TEST(MADDY_EMPHASIZEDPARSER, ItDoesNotParseInsideInlineCode) +{ + std::string text = "some text `*bla*` text testing *it* out"; + std::string expected = "some text `*bla*` text testing it out"; + auto emphasizedParser = std::make_shared(); + + emphasizedParser->Parse(text); + + ASSERT_EQ(expected, text); +} diff --git a/tests/maddy/test_maddy_strikethroughparser.cpp b/tests/maddy/test_maddy_strikethroughparser.cpp index b1ec7fb..f5dd933 100644 --- a/tests/maddy/test_maddy_strikethroughparser.cpp +++ b/tests/maddy/test_maddy_strikethroughparser.cpp @@ -20,3 +20,14 @@ TEST(MADDY_STRIKETHROUGHPARSER, ItReplacesMarkdownWithStrikeThroughHTML) ASSERT_EQ(expected, text); } + +TEST(MADDY_STRIKETHROUGHPARSER, ItDoesNotParseInsideInlineCode) +{ + std::string text = "some text `~~bla~~` text testing ~~it~~ out"; + std::string expected = "some text `~~bla~~` text testing ~~it~~ out"; + auto strikeThroughParser = std::make_shared(); + + strikeThroughParser->Parse(text); + + ASSERT_EQ(expected, text); +} diff --git a/tests/maddy/test_maddy_strongparser.cpp b/tests/maddy/test_maddy_strongparser.cpp index b222952..5086e4b 100644 --- a/tests/maddy/test_maddy_strongparser.cpp +++ b/tests/maddy/test_maddy_strongparser.cpp @@ -31,3 +31,14 @@ TEST(MADDY_STRONGPARSER, ItReplacesEmphasizedMarkdownNotWithStrongHTML) ASSERT_EQ(expected, text); } + +TEST(MADDY_STRONGPARSER, ItDoesNotParseInsideInlineCode) +{ + std::string text = "some text *bla* text testing `**it**` out"; + std::string expected = "some text *bla* text testing `**it**` out"; + auto strongParser = std::make_shared(); + + strongParser->Parse(text); + + ASSERT_EQ(expected, text); +}