mirror of
https://github.com/quitesimpleorg/qsmaddy.git
synced 2024-12-22 19:29:49 +01:00
Merge pull request #34 from solodolo/numeric-list
orderedlistparser: Add parsing support for fully numeric markdown lists
This commit is contained in:
commit
ba5cb5d6c5
1
AUTHORS
1
AUTHORS
@ -7,4 +7,5 @@ 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)
|
||||
Evan Klitzke (evan@eklitzke.org)
|
||||
|
@ -94,6 +94,26 @@ results in
|
||||
|
||||
```
|
||||
|
||||
1. ordered
|
||||
2. list
|
||||
3. items
|
||||
|
||||
```
|
||||
|
||||
results in
|
||||
|
||||
```html
|
||||
|
||||
<ol>
|
||||
<li>ordered</li>
|
||||
<li>list</li>
|
||||
<li>items</li>
|
||||
</ol>
|
||||
|
||||
```
|
||||
|
||||
```
|
||||
|
||||
1. ordered
|
||||
* list
|
||||
* items
|
||||
|
@ -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
|
||||
|
@ -96,3 +96,26 @@ TEST_F(MADDY_ORDEREDLISTPARSER, ItReplacesMarkdownWithAnHierachicalHtmlList)
|
||||
|
||||
ASSERT_EQ(expected, outputString);
|
||||
}
|
||||
|
||||
TEST_F(MADDY_ORDEREDLISTPARSER, ItReplacesNumberedMarkdownListWithAnHtmlOrderedList)
|
||||
{
|
||||
std::vector<std::string> markdown = {
|
||||
"1. a"
|
||||
, "94. b"
|
||||
, "103. c"
|
||||
, ""
|
||||
};
|
||||
std::string expected = "<ol><li>a</li><li>b</li><li>c</li></ol>";
|
||||
|
||||
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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user