From cde0137e90121bfa9626c0e2cd7ebbce93b40279 Mon Sep 17 00:00:00 2001 From: Drew Mettlach Date: Sat, 3 Oct 2020 17:22:21 -0500 Subject: [PATCH] orderedlistparser: Add parsing support for fully numeric markdown lists --- AUTHORS | 2 +- docs/definitions.md | 20 +++++++++++++++++ include/maddy/orderedlistparser.h | 6 ++--- tests/maddy/test_maddy_orderedlistparser.cpp | 23 ++++++++++++++++++++ 4 files changed, 47 insertions(+), 4 deletions(-) diff --git a/AUTHORS b/AUTHORS index f64561c..5156a30 100644 --- a/AUTHORS +++ b/AUTHORS @@ -7,4 +7,4 @@ a license to everyone to use it as detailed in LICENSE.) M. Petra Baranski (info@progsource.de) Patrick José Pereira (patrickelectric@gmail.com) Martin Kopecky (martin.kopecky357@gmail.com) - +Andrew Mettlach (dmmettlach@gmail.com) diff --git a/docs/definitions.md b/docs/definitions.md index fd6f286..862b956 100644 --- a/docs/definitions.md +++ b/docs/definitions.md @@ -94,6 +94,26 @@ results in ``` +1. ordered +2. list +3. items + +``` + +results in + +```html + +
    +
  1. ordered
  2. +
  3. list
  4. +
  5. items
  6. +
+ +``` + +``` + 1. ordered * list * items diff --git a/include/maddy/orderedlistparser.h b/include/maddy/orderedlistparser.h index b14babb..e41d3b1 100644 --- a/include/maddy/orderedlistparser.h +++ b/include/maddy/orderedlistparser.h @@ -89,9 +89,9 @@ protected: bool isStartOfNewListItem = this->isStartOfNewListItem(line); uint32_t indentation = getIndentationWidth(line); - static std::regex orderedlineRegex("^1\\. "); + static std::regex orderedlineRegex("^[1-9]+[0-9]*\\. "); line = std::regex_replace(line, orderedlineRegex, ""); - static std::regex unorderedlineRegex("^(\\* )"); + static std::regex unorderedlineRegex("^\\* "); line = std::regex_replace(line, unorderedlineRegex, ""); if (!this->isStarted) @@ -132,7 +132,7 @@ private: bool isStartOfNewListItem(const std::string& line) const { - static std::regex re("^(?:1\\. |\\* ).*"); + static std::regex re("^(?:[1-9]+[0-9]*\\. |\\* ).*"); return std::regex_match(line, re); } }; // class OrderedListParser diff --git a/tests/maddy/test_maddy_orderedlistparser.cpp b/tests/maddy/test_maddy_orderedlistparser.cpp index 326fe96..ecb73c5 100644 --- a/tests/maddy/test_maddy_orderedlistparser.cpp +++ b/tests/maddy/test_maddy_orderedlistparser.cpp @@ -96,3 +96,26 @@ TEST_F(MADDY_ORDEREDLISTPARSER, ItReplacesMarkdownWithAnHierachicalHtmlList) ASSERT_EQ(expected, outputString); } + +TEST_F(MADDY_ORDEREDLISTPARSER, ItReplacesNumberedMarkdownListWithAnHtmlOrderedList) +{ + std::vector markdown = { + "1. a" + , "94. b" + , "103. c" + , "" + }; + std::string expected = "
  1. a
  2. b
  3. c
"; + + for (std::string md : markdown) + { + olParser->AddLine(md); + } + + ASSERT_TRUE(olParser->IsFinished()); + + std::stringstream& output(olParser->GetResult()); + const std::string& outputString = output.str(); + + ASSERT_EQ(expected, outputString); +}