Compare commits

..

No commits in common. "master" and "1.0.0" have entirely different histories.

38개의 변경된 파일129개의 추가작업 그리고 1028개의 파일을 삭제

파일 보기

@ -8,5 +8,5 @@ indent_style = space
insert_final_newline = true insert_final_newline = true
trim_trailing_whitespace = true trim_trailing_whitespace = true
[*.{h,hh,hpp,c,cc,cpp,cxx,yml}] [*.{h,hh,hpp,c,cc,cpp,cxx}]
indent_size = 2 indent_size = 2

파일 보기

@ -1,32 +0,0 @@
sudo: false
language: cpp
matrix:
include:
- os: linux
dist: xenial
sudo: require
addons:
apt:
sources:
- sourceline: 'ppa:ubuntu-toolchain-r/test'
packages:
- g++-7
env:
- MATRIX_EVAL="CC=gcc-7 && CXX=g++-7"
- os: osx
osx_image: xcode10
compiler: clang
env:
- MATRIX_EVAL="CC=clang && CXX=clang++"
before_install:
# This is necessary to solve https://github.com/travis-ci/travis-ci/issues/9649
- eval "${MATRIX_EVAL}"
script:
- mkdir tmp
- cd tmp
- cmake ..
- make -j4
- ../build/MaddyTests

파일 보기

@ -5,7 +5,3 @@ licensing terms detailed in LICENSE.
a license to everyone to use it as detailed in LICENSE.) a license to everyone to use it as detailed in LICENSE.)
M. Petra Baranski (info@progsource.de) 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)

파일 보기

@ -1,67 +0,0 @@
# Changelog
This file tries to follow roughly [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
maddy uses [semver versioning](https://semver.org/).
## Badges
* ![**FIXED**](https://img.shields.io/badge/-FIXED-%23090) for any bug fixes.
* ![**SECURITY**](https://img.shields.io/badge/-SECURITY-%23c00) in case of vulnerabilities.
* ![**ADDED**](https://img.shields.io/badge/-ADDED-%23099) for new features.
* ![**CHANGED**](https://img.shields.io/badge/-CHANGED-%23e90) for changes in existing functionality.
* ![**DEPRECATED**](https://img.shields.io/badge/-DEPRECATED-%23666) for soon-to-be removed features.
* ![**REMOVED**](https://img.shields.io/badge/-REMOVED-%23900) for now removed features.
## Upcoming
* ![**ADDED**](https://img.shields.io/badge/-ADDED-%23099) Added Changelog
* ![**ADDED**](https://img.shields.io/badge/-ADDED-%23099) Added contribution guideline
* ?
## version 1.1.2 2020-10-04
* ![**ADDED**](https://img.shields.io/badge/-ADDED-%23099) `*`, `+` and `-` are equivalent for making unordered bullet list
* ![**ADDED**](https://img.shields.io/badge/-ADDED-%23099) Parsing support for fully numeric ordered lists
* ![**CHANGED**](https://img.shields.io/badge/-CHANGED-%23e90) make `Parser::Parse` accept istreams instead of stringstream
* ![**CHANGED**](https://img.shields.io/badge/-CHANGED-%23e90) CMake is creating an interface library which you can include in your own `target_link_libraries` and the global include path is untouched from maddy.
## version 1.1.1 2019-12-27
* ![**ADDED**](https://img.shields.io/badge/-ADDED-%23099) BreakLineParser
* ![**ADDED**](https://img.shields.io/badge/-ADDED-%23099) HTMLParser
* ![**ADDED**](https://img.shields.io/badge/-ADDED-%23099) Added optional config with the following options:
* en-/disable the emphasized parser
* wrap/not wrap HTML in markdown within a paragraph in output
* ![**CHANGED**](https://img.shields.io/badge/-CHANGED-%23e90) Updated gtest to release-1.10.0 to fix build issues
## version 1.1.0 2019-02-19
* ![**FIXED**](https://img.shields.io/badge/-FIXED-%23090) Added missing includes to BlockParser
* ![**FIXED**](https://img.shields.io/badge/-FIXED-%23090) Added missing dtor to BlockParser and LineParser
* ![**ADDED**](https://img.shields.io/badge/-ADDED-%23099) `__test__` can also be used to get `<strong>text</strong>`
* ![**ADDED**](https://img.shields.io/badge/-ADDED-%23099) Added AppVeyor CI
* ![**ADDED**](https://img.shields.io/badge/-ADDED-%23099) Added clang for CI
* ![**CHANGED**](https://img.shields.io/badge/-CHANGED-%23e90) Single underscore `_` results in emphasized tag `<em>`, single `*` in italic tag `<i>`
## version 1.0.3 2018-01-18
* ![**FIXED**](https://img.shields.io/badge/-FIXED-%23090) Make sure that all parsers are finished
* ![**FIXED**](https://img.shields.io/badge/-FIXED-%23090) ol documentation
* ![**ADDED**](https://img.shields.io/badge/-ADDED-%23099) Added Travic-CI with gcc
* ![**ADDED**](https://img.shields.io/badge/-ADDED-%23099) Added Howto for running the tests on the README
## version 1.0.2 2017-12-26
* ![**FIXED**](https://img.shields.io/badge/-FIXED-%23090) Fixed inline code for directly following letters (bold, emphasized and strikethrough)
## version 1.0.1 2017-12-25
* ![**FIXED**](https://img.shields.io/badge/-FIXED-%23090) Fixed inline code for bold, emphasized and strikethrough
* ![**FIXED**](https://img.shields.io/badge/-FIXED-%23090) Fixed spelling in README
* ![**ADDED**](https://img.shields.io/badge/-ADDED-%23099) Use Gold Linker on Unix if available for faster compile time
* ![**ADDED**](https://img.shields.io/badge/-ADDED-%23099) Added Github ISSUE_TEMPLATE
## version 1.0.0 2017-12-25
initial release

파일 보기

@ -1,4 +1,4 @@
# This project is licensed under the MIT license. For more information see the # This project is licensed under the MITlicense. For more information see the
# LICENSE file. # LICENSE file.
cmake_minimum_required(VERSION 2.8) cmake_minimum_required(VERSION 2.8)
@ -25,32 +25,10 @@ file(GLOB_RECURSE MADDY_TESTS_FILES ${CMAKE_CURRENT_SOURCE_DIR}/tests/maddy/*.cp
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
if (UNIX) set(
set( CMAKE_CXX_FLAGS
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 -fsanitize=address -fno-omit-frame-pointer" )
)
else()
set(
CMAKE_CXX_FLAGS
"${CMAKE_CXX_FLAGS} -std=c++${MADDY_CPP_VERSION}"
)
endif()
# ------------------------------------------------------------------------------
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()
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
@ -60,9 +38,10 @@ add_subdirectory(libs)
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
add_library(maddy INTERFACE) include_directories(
target_include_directories(maddy INTERFACE ${LIBS_INCLUDE_DIRS}
${MADDY_INCLUDE_DIR} ${MADDY_INCLUDE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/tests
) )
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
@ -72,9 +51,5 @@ add_executable(
${MADDY_TESTS_FILES} ${MADDY_TESTS_FILES}
${CMAKE_CURRENT_SOURCE_DIR}/tests/main.cpp ${CMAKE_CURRENT_SOURCE_DIR}/tests/main.cpp
) )
target_include_directories(MaddyTests PUBLIC target_link_libraries(MaddyTests gmock_main)
${LIBS_INCLUDE_DIRS}
${CMAKE_CURRENT_SOURCE_DIR}/tests
)
target_link_libraries(MaddyTests maddy gmock_main)
add_test(MaddyTests ${CMAKE_CURRENT_SOURCE_DIR}/build/MaddyTests) add_test(MaddyTests ${CMAKE_CURRENT_SOURCE_DIR}/build/MaddyTests)

파일 보기

@ -1,26 +0,0 @@
# Contribution Guideline
First of all: I am thankful for any contribution this project gets.
## Creating Issues
You found a bug, you miss some feature in the project or have an idea how to
improve the code? Then [create a GitHub issue](https://github.com/progsource/maddy/issues/new).
## Creating Pull-Requests
* Use a branch other than master.
* Add yourself to the `AUTHORS` file.
* Try to stick with the code style the files are having right now.
* Write in your commit messages what/why you did something. Often times a one-liner might be enough, but if you want to write more, make an empty line in between like:
```
Short description
More and longer text for the commit message with some more information.
That can go over multiple lines.
```
Do not include Github issue ticket numbers inside commit messages.
* Explain for what your PR is for - like providing a use-case or something similar.
* Update documentation of the Markdown syntax if anything changed there. (`docs/definitions.md`)
* Add a changelog entry at "Upcoming" inside of `CHANGELOG.md`
* Make sure, that the tests are successful.

파일 보기

@ -1,17 +0,0 @@
## Minimal Code Example
```
```
## Conditions
. | .
--------------------- | ------------------
**Operating System:** | ?
**Compiler:** | ?
**Compiler flags:** | ?
**maddy version:** | ?
## Description
What did you try? What is not working?

파일 보기

@ -1,4 +1,4 @@
Copyright 2017, 2018, 2019, 2020 M. Petra Baranski Copyright 2017 M. Petra Baranski
Permission is hereby granted, free of charge, to any person obtaining a copy of Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in this software and associated documentation files (the "Software"), to deal in

파일 보기

@ -1,3 +1,51 @@
# qsmaddy # maddy
Fork of [maddy](https://github.com/progsource/maddy) with some quick hacks to make it fit better for [qswiki](https://gitea.quitesimple.org/crtxcr/qswiki) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![Version: 1.0.0](https://img.shields.io/badge/Version-1.0.0-brightgreen.svg)](https://semver.org/)
maddy is a C++ Markdown to HTML **header-only** parser library.
## Supportes OS
It actually should work on any OS, that supports the C++14 standard library.
It is tested to work on:
* Linux (without exceptions and without RTTI)
## Dependencies
* C++14
## Why maddy?
When I was needing a Markdown parser in C++ I couldn't find any, that was
fitting my needs. So I simply wrote my own one.
## Markdown syntax
The supported syntax can be found in the [definitions docs](docs/definitions.md).
## HowTo use
To use maddy in your project, simply add the include path of maddy to yours
and in the code, you can then do the following:
```c++
#include <memory>
#include <string>
#include "maddy/parser.h"
std::stringstream markdownInput("");
std::shared_ptr<maddy::Parser> parser = std::make_shared<maddy::Parser>();
std::string htmlOutput = parser->Parse(markdownInput);
```
## How to contribute
There are different possibilities:
* Create a GitHub issue
* Create a pull request with an own branch (don't forget to put yourself in the
AUTHORS file)

파일 보기

@ -1,15 +0,0 @@
image: Visual Studio 2017
install:
- cmd: git submodule update --init --recursive
before_build:
- cmd: mkdir tmp
- cmd: cd tmp
- cmd: cmake -G "Visual Studio 15 Win64" ..
build:
project: $(APPVEYOR_BUILD_FOLDER)\tmp\$(APPVEYOR_PROJECT_NAME).sln
test_script:
- cmd: ctest -VV -C "Debug"

파일 보기

@ -7,10 +7,6 @@ destroy the output, if there was HTML in your markdown.
The Parser expects you to use spaces and not tabs for indentation in the The Parser expects you to use spaces and not tabs for indentation in the
markdown. markdown.
If a line starts with `<` and `config->isHTMLWrappedInParagraph` is false, it
expects that the upcoming line is HTML and therefor will not be surrounded by a
paragraph.
## Headlines ## Headlines
``` ```
@ -44,13 +40,11 @@ results in
## Lists ## Lists
### unordered ### unordered
Characters "*", "+" or "-" to make an unordered "bullet" list are equivalent.
``` ```
- unordered * unordered
* list * list
+ items * items
``` ```
results in results in
@ -64,29 +58,25 @@ results in
``` ```
* unordered * unorederd
* list * list
* items * items
* in * in
+ an * an
- hierarchy * hierarchy
``` ```
results in results in
```html ```html
<ul> <ul>
<li>unordered <li>list</li>
<li>items
<ul> <ul>
<li>list</li> <li>in</li>
<li>items <li>an</li>
<ul>
<li>in</li>
<li>an</li>
</ul>
</li>
<li>hierarchy</li>
</ul> </ul>
</li> </li>
<li>hierarchy</li>
</ul> </ul>
``` ```
@ -94,42 +84,18 @@ results in
``` ```
1. ordered
2. list
3. items
```
results in
```html
<ol>
<li>ordered</li>
<li>list</li>
<li>items</li>
</ol>
```
```
1. ordered 1. ordered
* list * list
* items * items
``` ```
results in results in
```html ```html
<ol> <ol>
<li>ordered</li> <li>ordered</li>
<li>list</li> <li>list</li>
<li>items</li> <li>items</li>
</ol> </ol>
``` ```
``` ```
@ -142,9 +108,7 @@ results in
* hierarchy * hierarchy
``` ```
results in results in
```html ```html
<ol> <ol>
<li>ordered</li> <li>ordered</li>
@ -152,9 +116,7 @@ results in
<ol> <ol>
<li>items</li> <li>items</li>
<li>in <li>in
<ol> <ol>an</ol>
<li>an</li>
</ol>
</li> </li>
<li>hierarchy</li> <li>hierarchy</li>
</ol> </ol>
@ -247,30 +209,16 @@ results in
``` ```
**bold text** **bold text**
__bold text__
``` ```
results in results in
```html ```html
<strong>bold text</strong> <strong>bold text</strong>
<strong>bold text</strong>
```
## italic
```
*italic text*
```
results in
```html
<i>italic text</i>
``` ```
## emphasized ## emphasized
This can be disabled by setting `config->isEmphasizedParserEnabled = false`.
``` ```
_emphasized text_ *emphasized text*
``` ```
results in results in
```html ```html
@ -297,17 +245,6 @@ results in
<hr/> <hr/>
``` ```
## break line
```
New\r\nLine
```
results in
```html
New<br>
Line
```
## Images ## Images
``` ```

파일 보기

@ -7,11 +7,7 @@
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
#include <functional> #include <functional>
#include <sstream>
#include <string> #include <string>
// windows compatibility includes
#include <cctype>
#include <algorithm>
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
@ -48,13 +44,6 @@ public:
, getBlockParserForLineCallback(getBlockParserForLineCallback) , getBlockParserForLineCallback(getBlockParserForLineCallback)
{} {}
/**
* dtor
*
* @method
*/
virtual ~BlockParser() {}
/** /**
* AddLine * AddLine
* *
@ -157,26 +146,24 @@ protected:
{ {
bool hasMetNonSpace = false; bool hasMetNonSpace = false;
uint32_t indentation = static_cast<uint32_t>( uint32_t indentation = std::count_if(
std::count_if( line.begin(),
line.begin(), line.end(),
line.end(), [&hasMetNonSpace](unsigned char c)
[&hasMetNonSpace](unsigned char c) {
if (hasMetNonSpace)
{ {
if (hasMetNonSpace)
{
return false;
}
if (std::isspace(c))
{
return true;
}
hasMetNonSpace = true;
return false; return false;
} }
)
if (std::isspace(c))
{
return true;
}
hasMetNonSpace = true;
return false;
}
); );
return indentation; return indentation;

파일 보기

@ -1,51 +0,0 @@
/*
* This project is licensed under the MIT license. For more information see the
* LICENSE file.
*/
#pragma once
// -----------------------------------------------------------------------------
#include <string>
#include <regex>
#include "maddy/lineparser.h"
// -----------------------------------------------------------------------------
namespace maddy {
// -----------------------------------------------------------------------------
/**
* BreakLineParser
*
* @class
*/
class BreakLineParser : public LineParser
{
public:
/**
* Parse
*
* From Markdown: `text\r\n text`
*
* To HTML: `text<br> text`
*
* @method
* @param {std::string&} line The line to interpret
* @return {void}
*/
void
Parse(std::string& line) override
{
static std::regex re(R"((\r\n|\r))");
static std::string replacement = "<br>";
line = std::regex_replace(line, re, replacement);
}
}; // class BreakLineParser
// -----------------------------------------------------------------------------
} // namespace maddy

파일 보기

@ -1,36 +0,0 @@
/*
* This project is licensed under the MIT license. For more information see the
* LICENSE file.
*/
#pragma once
#include <string>
#include <regex>
#include <functional>
namespace maddy {
inline std::string regex_callback_replacer(std::regex &regex, const std::string &input,
std::function<std::string(std::smatch &)> &callback)
{
std::string result;
auto tagsbegin = std::sregex_iterator(input.begin(), input.end(), regex);
auto tagsend = std::sregex_iterator();
auto matchbegin = 0;
for(std::sregex_iterator i = tagsbegin; i != tagsend; ++i)
{
std::smatch match = *i;
auto matchlength = match.length(0);
auto matchpos = match.position();
result += input.substr(matchbegin, matchpos - matchbegin);
result += callback(match);
matchbegin = matchpos + matchlength;
}
result += input.substr(matchbegin);
return result;
}
}

파일 보기

@ -30,7 +30,7 @@ public:
/** /**
* Parse * Parse
* *
* From Markdown: `text _text_` * From Markdown: `text *text*`
* *
* To HTML: `text <em>text</em>` * To HTML: `text <em>text</em>`
* *
@ -41,7 +41,7 @@ public:
void void
Parse(std::string& line) override Parse(std::string& line) override
{ {
static std::regex re("(?!.*`.*|.*<code>.*)_(?!.*`.*|.*<\\/code>.*)([^_]*)_(?!.*`.*|.*<\\/code>.*)"); static std::regex re("\\*([^\\*]*)\\*");
static std::string replacement = "<em>$1</em>"; static std::string replacement = "<em>$1</em>";
line = std::regex_replace(line, re, replacement); line = std::regex_replace(line, re, replacement);

파일 보기

@ -1,127 +0,0 @@
/*
* This project is licensed under the MIT license. For more information see the
* LICENSE file.
*/
#pragma once
// -----------------------------------------------------------------------------
#include <functional>
#include <string>
#include "maddy/blockparser.h"
// -----------------------------------------------------------------------------
namespace maddy {
// -----------------------------------------------------------------------------
/**
* HtmlParser
*
* @class
*/
class HtmlParser : public BlockParser
{
public:
/**
* ctor
*
* @method
* @param {std::function<void(std::string&)>} parseLineCallback
* @param {std::function<std::shared_ptr<BlockParser>(const std::string& line)>} getBlockParserForLineCallback
*/
HtmlParser(
std::function<void(std::string&)> parseLineCallback,
std::function<std::shared_ptr<BlockParser>(const std::string& line)> getBlockParserForLineCallback
)
: BlockParser(parseLineCallback, getBlockParserForLineCallback)
, isStarted(false)
, isFinished(false)
, isGreaterThanFound(false)
{}
/**
* IsStartingLine
*
* If the line is starting with `<`, HTML is expected to follow.
* Nothing after that will be parsed, it only is copied.
*
* @method
* @param {const std::string&} line
* @return {bool}
*/
static bool
IsStartingLine(const std::string& line)
{
return line[0] == '<';
}
/**
* IsFinished
*
* `>` followed by an empty line will end the HTML block.
*
* @method
* @return {bool}
*/
bool
IsFinished() const override
{
return this->isFinished;
}
protected:
bool
isInlineBlockAllowed() const override
{
return false;
}
bool
isLineParserAllowed() const override
{
return false;
}
void
parseBlock(std::string& line) override
{
if (!this->isStarted)
{
this->isStarted = true;
}
if (!line.empty() && line[line.size() - 1] == '>')
{
this->isGreaterThanFound = true;
return;
}
if (line.empty() && this->isGreaterThanFound)
{
this->isFinished = true;
return;
}
if (!line.empty() && this->isGreaterThanFound)
{
this->isGreaterThanFound = false;
}
if (!line.empty())
{
line += " ";
}
}
private:
bool isStarted;
bool isFinished;
bool isGreaterThanFound;
}; // class HtmlParser
// -----------------------------------------------------------------------------
} // namespace maddy

파일 보기

@ -1,50 +0,0 @@
/*
* This project is licensed under the MIT license. For more information see the
* LICENSE file.
*/
#pragma once
// -----------------------------------------------------------------------------
#include <string>
#include <regex>
#include "maddy/lineparser.h"
// -----------------------------------------------------------------------------
namespace maddy {
// -----------------------------------------------------------------------------
/**
* ItalicParser
*
* @class
*/
class ItalicParser : public LineParser
{
public:
/**
* Parse
*
* From Markdown: `text *text*`
*
* To HTML: `text <i>text</i>`
*
* @method
* @param {std::string&} line The line to interpret
* @return {void}
*/
void
Parse(std::string& line) override
{
static std::regex re("(?!.*`.*|.*<code>.*)\\*(?!.*`.*|.*<\\/code>.*)([^\\*]*)\\*(?!.*`.*|.*<\\/code>.*)");
static std::string replacement = "<i>$1</i>";
line = std::regex_replace(line, re, replacement);
}
}; // class ItalicParser
// -----------------------------------------------------------------------------
} // namespace maddy

파일 보기

@ -22,13 +22,6 @@ namespace maddy {
class LineParser class LineParser
{ {
public: public:
/**
* dtor
*
* @method
*/
virtual ~LineParser() {}
/** /**
* Parse * Parse
* *

파일 보기

@ -10,7 +10,6 @@
#include <regex> #include <regex>
#include "maddy/lineparser.h" #include "maddy/lineparser.h"
#include "maddy/callbackreplacer.h"
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
@ -27,16 +26,6 @@ namespace maddy {
*/ */
class LinkParser : public LineParser class LinkParser : public LineParser
{ {
private:
std::function<std::string(std::smatch &)> callback = [](std::smatch & match){
std::string inner = match.str(1);
std::string link = match.str(2);
return "<a href=\"" + link + "\">" + inner + "</a>";
};
std::regex re = std::regex("\\[([^\\]]*)\\]\\(([^\\]]*)\\)");
public: public:
/** /**
* Parse * Parse
@ -52,12 +41,10 @@ public:
void void
Parse(std::string& line) override Parse(std::string& line) override
{ {
line = regex_callback_replacer(re,line,callback); static std::regex re("\\[([^\\]]*)\\]\\(([^\\]]*)\\)");
} static std::string replacement = "<a href=\"$2\">$1</a>";
void setCallback(std::function<std::string(std::smatch &)> callback) line = std::regex_replace(line, re, replacement);
{
this->callback = callback;
} }
}; // class LinkParser }; // class LinkParser

파일 보기

@ -89,9 +89,9 @@ protected:
bool isStartOfNewListItem = this->isStartOfNewListItem(line); bool isStartOfNewListItem = this->isStartOfNewListItem(line);
uint32_t indentation = getIndentationWidth(line); uint32_t indentation = getIndentationWidth(line);
static std::regex orderedlineRegex("^[1-9]+[0-9]*\\. "); static std::regex orderedlineRegex("^1\\. ");
line = std::regex_replace(line, orderedlineRegex, ""); line = std::regex_replace(line, orderedlineRegex, "");
static std::regex unorderedlineRegex("^\\* "); static std::regex unorderedlineRegex("^(\\* )");
line = std::regex_replace(line, unorderedlineRegex, ""); line = std::regex_replace(line, unorderedlineRegex, "");
if (!this->isStarted) if (!this->isStarted)
@ -132,7 +132,7 @@ private:
bool bool
isStartOfNewListItem(const std::string& line) const isStartOfNewListItem(const std::string& line) const
{ {
static std::regex re("^(?:[1-9]+[0-9]*\\. |\\* ).*"); static std::regex re("^(?:1\\. |\\* ).*");
return std::regex_match(line, re); return std::regex_match(line, re);
} }
}; // class OrderedListParser }; // class OrderedListParser

파일 보기

@ -44,9 +44,8 @@ public:
/** /**
* IsStartingLine * IsStartingLine
* *
* If the line is not empty, it will be a paragraph. * If the line is not empty, it will be a paragraph. So this block parser has
* * to always run as the last one!
* This block parser has to always run as the last one!
* *
* @method * @method
* @param {const std::string&} line * @param {const std::string&} line

파일 보기

@ -10,14 +10,11 @@
#include <functional> #include <functional>
#include <string> #include <string>
#include "maddy/parserconfig.h"
// BlockParser // BlockParser
#include "maddy/checklistparser.h" #include "maddy/checklistparser.h"
#include "maddy/codeblockparser.h" #include "maddy/codeblockparser.h"
#include "maddy/headlineparser.h" #include "maddy/headlineparser.h"
#include "maddy/horizontallineparser.h" #include "maddy/horizontallineparser.h"
#include "maddy/htmlparser.h"
#include "maddy/orderedlistparser.h" #include "maddy/orderedlistparser.h"
#include "maddy/paragraphparser.h" #include "maddy/paragraphparser.h"
#include "maddy/quoteparser.h" #include "maddy/quoteparser.h"
@ -25,11 +22,9 @@
#include "maddy/unorderedlistparser.h" #include "maddy/unorderedlistparser.h"
// LineParser // LineParser
#include "maddy/breaklineparser.h"
#include "maddy/emphasizedparser.h" #include "maddy/emphasizedparser.h"
#include "maddy/imageparser.h" #include "maddy/imageparser.h"
#include "maddy/inlinecodeparser.h" #include "maddy/inlinecodeparser.h"
#include "maddy/italicparser.h"
#include "maddy/linkparser.h" #include "maddy/linkparser.h"
#include "maddy/strikethroughparser.h" #include "maddy/strikethroughparser.h"
#include "maddy/strongparser.h" #include "maddy/strongparser.h"
@ -57,13 +52,10 @@ public:
* *
* @method * @method
*/ */
Parser(std::shared_ptr<ParserConfig> config = nullptr) Parser()
: config(config) : emphasizedParser(std::make_shared<EmphasizedParser>())
, breakLineParser(std::make_shared<BreakLineParser>())
, emphasizedParser(std::make_shared<EmphasizedParser>())
, imageParser(std::make_shared<ImageParser>()) , imageParser(std::make_shared<ImageParser>())
, inlineCodeParser(std::make_shared<InlineCodeParser>()) , inlineCodeParser(std::make_shared<InlineCodeParser>())
, italicParser(std::make_shared<ItalicParser>())
, linkParser(std::make_shared<LinkParser>()) , linkParser(std::make_shared<LinkParser>())
, strikeThroughParser(std::make_shared<StrikeThroughParser>()) , strikeThroughParser(std::make_shared<StrikeThroughParser>())
, strongParser(std::make_shared<StrongParser>()) , strongParser(std::make_shared<StrongParser>())
@ -73,11 +65,11 @@ public:
* Parse * Parse
* *
* @method * @method
* @param {const std::istream&} markdown * @param {const std::stringstream&} markdown
* @return {std::string} HTML * @return {std::string} HTML
*/ */
std::string std::string
Parse(std::istream& markdown) const Parse(std::stringstream& markdown) const
{ {
std::string result = ""; std::string result = "";
std::shared_ptr<BlockParser> currentBlockParser = nullptr; std::shared_ptr<BlockParser> currentBlockParser = nullptr;
@ -101,76 +93,13 @@ public:
} }
} }
// make sure, that all parsers are finished
if (currentBlockParser)
{
std::string emptyLine = "";
currentBlockParser->AddLine(emptyLine);
if (currentBlockParser->IsFinished())
{
result += currentBlockParser->GetResult().str();
currentBlockParser = nullptr;
}
}
return result; return result;
} }
void
setBreakLineParser(std::shared_ptr<BreakLineParser> breakLineParser)
{
this->breakLineParser = breakLineParser;
}
void
setEmphasizedParser(std::shared_ptr<EmphasizedParser> emphasizedParser)
{
this->emphasizedParser = emphasizedParser;
}
void
setImageParser(std::shared_ptr<ImageParser> imageParser)
{
this->imageParser = imageParser;
}
void
setInlineCodeParser(std::shared_ptr<InlineCodeParser> inlineCodeParser)
{
this->inlineCodeParser = inlineCodeParser;
}
void
setItalicParser(std::shared_ptr<ItalicParser> italicParser)
{
this->italicParser = italicParser;
}
void
setLinkParser(std::shared_ptr<LinkParser> linkParser)
{
this->linkParser = linkParser;
}
void
setStrikeThroughParser(std::shared_ptr<StrikeThroughParser> strikeThroughParser)
{
this->strikeThroughParser = strikeThroughParser;
}
void
setStrongParser(std::shared_ptr<StrongParser> strongParser)
{
this->strongParser = strongParser;
}
private: private:
std::shared_ptr<ParserConfig> config;
std::shared_ptr<BreakLineParser> breakLineParser;
std::shared_ptr<EmphasizedParser> emphasizedParser; std::shared_ptr<EmphasizedParser> emphasizedParser;
std::shared_ptr<ImageParser> imageParser; std::shared_ptr<ImageParser> imageParser;
std::shared_ptr<InlineCodeParser> inlineCodeParser; std::shared_ptr<InlineCodeParser> inlineCodeParser;
std::shared_ptr<ItalicParser> italicParser;
std::shared_ptr<LinkParser> linkParser; std::shared_ptr<LinkParser> linkParser;
std::shared_ptr<StrikeThroughParser> strikeThroughParser; std::shared_ptr<StrikeThroughParser> strikeThroughParser;
std::shared_ptr<StrongParser> strongParser; std::shared_ptr<StrongParser> strongParser;
@ -185,19 +114,11 @@ private:
// Attention! StrongParser has to be before EmphasizedParser // Attention! StrongParser has to be before EmphasizedParser
this->strongParser->Parse(line); this->strongParser->Parse(line);
this->emphasizedParser->Parse(line);
if (!this->config || this->config->isEmphasizedParserEnabled)
{
this->emphasizedParser->Parse(line);
}
this->strikeThroughParser->Parse(line); this->strikeThroughParser->Parse(line);
this->inlineCodeParser->Parse(line); this->inlineCodeParser->Parse(line);
this->italicParser->Parse(line);
this->breakLineParser->Parse(line);
} }
std::shared_ptr<BlockParser> std::shared_ptr<BlockParser>
@ -252,14 +173,6 @@ private:
{ {
parser = this->createUnorderedListParser(); parser = this->createUnorderedListParser();
} }
else if (
this->config &&
!this->config->isHTMLWrappedInParagraph &&
maddy::HtmlParser::IsStartingLine(line)
)
{
parser = std::make_shared<maddy::HtmlParser>(nullptr, nullptr);
}
else if (maddy::ParagraphParser::IsStartingLine(line)) else if (maddy::ParagraphParser::IsStartingLine(line))
{ {
parser = std::make_shared<maddy::ParagraphParser>( parser = std::make_shared<maddy::ParagraphParser>(

파일 보기

@ -1,31 +0,0 @@
/*
* This project is licensed under the MIT license. For more information see the
* LICENSE file.
*/
#pragma once
// -----------------------------------------------------------------------------
namespace maddy {
// -----------------------------------------------------------------------------
/**
* ParserConfig
*
* @class
*/
struct ParserConfig
{
bool isEmphasizedParserEnabled;
bool isHTMLWrappedInParagraph;
ParserConfig()
: isEmphasizedParserEnabled(true)
, isHTMLWrappedInParagraph(true)
{}
}; // class ParserConfig
// -----------------------------------------------------------------------------
} // namespace maddy

파일 보기

@ -39,7 +39,7 @@ public:
void void
Parse(std::string& line) override Parse(std::string& line) override
{ {
static std::regex re("(?!.*`.*|.*<code>.*)\\~\\~(?!.*`.*|.*<\\/code>.*)([^\\~]*)\\~\\~(?!.*`.*|.*<\\/code>.*)"); static std::regex re("\\~\\~([^\\~]*)\\~\\~");
static std::string replacement = "<s>$1</s>"; static std::string replacement = "<s>$1</s>";
line = std::regex_replace(line, re, replacement); line = std::regex_replace(line, re, replacement);

파일 보기

@ -30,9 +30,9 @@ public:
/** /**
* Parse * Parse
* *
* From Markdown: `text **text** __text__` * From Markdown: `text **text**`
* *
* To HTML: `text <strong>text</strong> <strong>text</strong>` * To HTML: `text <strong>text</strong>`
* *
* @method * @method
* @param {std::string&} line The line to interpret * @param {std::string&} line The line to interpret
@ -41,16 +41,10 @@ public:
void void
Parse(std::string& line) override Parse(std::string& line) override
{ {
static std::vector<std::regex> res static std::regex re("\\*\\*([^\\*\\*]*)\\*\\*");
{
std::regex{"(?!.*`.*|.*<code>.*)\\*\\*(?!.*`.*|.*<\\/code>.*)([^\\*\\*]*)\\*\\*(?!.*`.*|.*<\\/code>.*)"},
std::regex{"(?!.*`.*|.*<code>.*)__(?!.*`.*|.*<\\/code>.*)([^__]*)__(?!.*`.*|.*<\\/code>.*)"}
};
static std::string replacement = "<strong>$1</strong>"; static std::string replacement = "<strong>$1</strong>";
for (const auto& re : res)
{ line = std::regex_replace(line, re, replacement);
line = std::regex_replace(line, re, replacement);
}
} }
}; // class StrongParser }; // class StrongParser

파일 보기

@ -54,7 +54,7 @@ public:
static bool static bool
IsStartingLine(const std::string& line) IsStartingLine(const std::string& line)
{ {
static std::regex re("^[+*-] .*"); static std::regex re("^\\* .*");
return std::regex_match(line, re); return std::regex_match(line, re);
} }
@ -89,7 +89,7 @@ protected:
bool isStartOfNewListItem = IsStartingLine(line); bool isStartOfNewListItem = IsStartingLine(line);
uint32_t indentation = getIndentationWidth(line); uint32_t indentation = getIndentationWidth(line);
static std::regex lineRegex("^([+*-] )"); static std::regex lineRegex("^(\\* )");
line = std::regex_replace(line, lineRegex, ""); line = std::regex_replace(line, lineRegex, "");
if (!this->isStarted) if (!this->isStarted)

@ -1 +1 @@
Subproject commit 703bd9caab50b139428cea1aaff9974ebee5742e Subproject commit 5490beb0602eab560fa3969a4410e11d94bf12af

파일 보기

@ -1,35 +0,0 @@
/*
* This project is licensed under the MIT license. For more information see the
* LICENSE file.
*/
#include <memory>
#include "gmock/gmock.h"
#include "maddy/breaklineparser.h"
// -----------------------------------------------------------------------------
TEST(MADDY_BREAKLINEPARSER, ItReplacesMarkdownWithBreakLineHTML)
{
std::string text =
"Test the text\r\n"
"test text to check\r\n"
"check testing to text.\r"
"Check test to test text\r"
"This is a test\r\n"
"No more test to check";
std::string expected =
"Test the text<br>"
"test text to check<br>"
"check testing to text.<br>"
"Check test to test text<br>"
"This is a test<br>"
"No more test to check";
auto breakLineParser = std::make_shared<maddy::BreakLineParser>();
breakLineParser->Parse(text);
ASSERT_EQ(text, expected);
}

파일 보기

@ -12,7 +12,7 @@
TEST(MADDY_EMPHASIZEDPARSER, ItReplacesMarkdownWithEmphasizedHTML) TEST(MADDY_EMPHASIZEDPARSER, ItReplacesMarkdownWithEmphasizedHTML)
{ {
std::string text = "some text _bla_ text testing _it_ out"; std::string text = "some text *bla* text testing *it* out";
std::string expected = "some text <em>bla</em> text testing <em>it</em> out"; std::string expected = "some text <em>bla</em> text testing <em>it</em> out";
auto emphasizedParser = std::make_shared<maddy::EmphasizedParser>(); auto emphasizedParser = std::make_shared<maddy::EmphasizedParser>();
@ -20,14 +20,3 @@ TEST(MADDY_EMPHASIZEDPARSER, ItReplacesMarkdownWithEmphasizedHTML)
ASSERT_EQ(expected, text); 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 <em>it</em> out";
auto emphasizedParser = std::make_shared<maddy::EmphasizedParser>();
emphasizedParser->Parse(text);
ASSERT_EQ(expected, text);
}

파일 보기

@ -1,82 +0,0 @@
/*
* This project is licensed under the MIT license. For more information see the
* LICENSE file.
*/
#include <memory>
#include "gmock/gmock.h"
#include "maddy/htmlparser.h"
// -----------------------------------------------------------------------------
class MADDY_HTMLPARSER : public ::testing::Test
{
protected:
std::shared_ptr<maddy::HtmlParser> pParser;
void
SetUp() override
{
this->pParser = std::make_shared<maddy::HtmlParser>(
nullptr,
nullptr
);
}
};
// -----------------------------------------------------------------------------
TEST_F(MADDY_HTMLPARSER, IsFinishedReturnsFalseInTheBeginning)
{
ASSERT_FALSE(pParser->IsFinished());
}
TEST_F(MADDY_HTMLPARSER, IsStartingLineReturnsFalseWhenFacedWithNoSmallerThan)
{
const std::vector<std::string> markdown = {
"> quote"
, "some text"
, "* list"
, "1. numbered list"
, "|table>"
};
for (size_t i = 0; i < markdown.size(); ++i)
{
ASSERT_FALSE(maddy::HtmlParser::IsStartingLine(markdown[i]));
}
}
TEST_F(MADDY_HTMLPARSER, IsStartingLineReturnsTrueWhenFacedWithSmallerThan)
{
const std::string markdown = "<div id=\"test\">test element</div>";
ASSERT_TRUE(maddy::HtmlParser::IsStartingLine(markdown));
}
TEST_F(MADDY_HTMLPARSER, ItReplacesNoHtml)
{
const std::vector<std::string> markdown {
"some text in a paragraph"
, ""
, "<div> some HTML</div>"
, ""
, "<div>more"
, "HTML"
, "</div>"
, ""
};
const std::string expected = "some text in a paragraph <div> some HTML</div><div>more HTML </div>";
for (std::string md : markdown)
{
pParser->AddLine(md);
}
ASSERT_TRUE(pParser->IsFinished());
std::stringstream& output(pParser->GetResult());
const std::string& outputString = output.str();
ASSERT_EQ(expected, outputString);
}

파일 보기

@ -1,23 +0,0 @@
/*
* This project is licensed under the MIT license. For more information see the
* LICENSE file.
*/
#include <memory>
#include "gmock/gmock.h"
#include "maddy/italicparser.h"
// -----------------------------------------------------------------------------
TEST(MADDY_ITALICPARSER, ItReplacesMarkdownWithItalicHTML)
{
std::string text = "some text *bla* text testing *it* out";
std::string expected = "some text <i>bla</i> text testing <i>it</i> out";
auto italicParser = std::make_shared<maddy::ItalicParser>();
italicParser->Parse(text);
ASSERT_EQ(text, expected);
}

파일 보기

@ -96,26 +96,3 @@ TEST_F(MADDY_ORDEREDLISTPARSER, ItReplacesMarkdownWithAnHierachicalHtmlList)
ASSERT_EQ(expected, outputString); 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);
}

파일 보기

@ -19,18 +19,3 @@ TEST(MADDY_PARSER, ItShouldParse)
ASSERT_EQ(testHtml, output); ASSERT_EQ(testHtml, output);
} }
TEST(MADDY_PARSER, ItShouldParseWithConfig)
{
auto config = std::make_shared<maddy::ParserConfig>();
config->isEmphasizedParserEnabled = false;
config->isHTMLWrappedInParagraph = false;
auto parser = std::make_shared<maddy::Parser>(config);
std::stringstream markdown(testMarkdown);
const std::string output = parser->Parse(markdown);
ASSERT_EQ(testHtml2, output);
}

파일 보기

@ -11,9 +11,9 @@ const std::string testMarkdown = "# This is a test\n\
This should result in a praragraph\n\ This should result in a praragraph\n\
it's that simple.\n\ it's that simple.\n\
\n\ \n\
* an *unordered* list\n\ * an unordered list\n\
* with some **hierarchy**\n\ * with some **hierarchy**\n\
1. and an _ordered_\n\ 1. and an *ordered*\n\
* list\n\ * list\n\
* directly\n\ * directly\n\
* inside\n\ * inside\n\
@ -42,8 +42,6 @@ And well - let's see how an image would be shown:\n\
\n\ \n\
---\n\ ---\n\
\n\ \n\
<a name=\"to top\"></a>\n\
\n\
### and more headlines\n\ ### and more headlines\n\
\n\ \n\
- [ ] how\n\ - [ ] how\n\
@ -69,5 +67,4 @@ foot a|foot b|foot c\n\
\n\ \n\
"; ";
const std::string testHtml = "<h1>This is a test</h1><p>This should result in a praragraph it's that simple. </p><ul><li>an <i>unordered</i> list<ul><li>with some <strong>hierarchy</strong><ol><li>and an <em>ordered</em></li><li>list</li><li>directly</li></ol></li><li>inside</li></ul></li></ul><pre><code>\nvar c = 'blub';\n</code></pre><blockquote><p>A Quote </p><p>With some <s>text</s> blocks inside </p><ul><li>even a list </li><li>should be </li><li>possible </li></ul></blockquote><p>And well <code>inline code</code> should also work. </p><h2>Another Headline</h2><p>And not to forget <a href=\"http://progsource.de\">link to progsource</a> should work. And well - let's see how an image would be shown: </p><p><img src=\"http://progsource.de/img/progsource.png\" alt=\"an image\"/> </p><hr/><p><a name=\"to top\"></a> </p><h3>and more headlines</h3><ul class=\"checklist\"><li><label><input type=\"checkbox\"/> how</label></li><li><label><input type=\"checkbox\"/> about<ul class=\"checklist\"><li><label><input type=\"checkbox\"/> a</label></li><li><label><input type=\"checkbox\" checked=\"checked\"/> nice</label></li></ul></label></li><li><label><input type=\"checkbox\" checked=\"checked\"/> check</label></li><li><label><input type=\"checkbox\"/> list</label></li></ul><h4>even a table</h4><table><thead><tr><th>Left header</th><th>middle header</th><th>last header</th></tr></thead><tbody><tr><td>cell 1</td><td>cell <strong>2</strong></td><td>cell 3</td></tr><tr><td>cell 4</td><td>cell 5</td><td>cell 6</td></tr></tbody><tfoot><tr><td>foot a</td><td>foot b</td><td>foot c</td></tr></tfoot></table><h5>h5</h5><h6>h6</h6>"; const std::string testHtml = "<h1>This is a test</h1><p>This should result in a praragraph it's that simple. </p><ul><li>an unordered list<ul><li>with some <strong>hierarchy</strong><ol><li>and an <em>ordered</em></li><li>list</li><li>directly</li></ol></li><li>inside</li></ul></li></ul><pre><code>\nvar c = 'blub';\n</code></pre><blockquote><p>A Quote </p><p>With some <s>text</s> blocks inside </p><ul><li>even a list </li><li>should be </li><li>possible </li></ul></blockquote><p>And well <code>inline code</code> should also work. </p><h2>Another Headline</h2><p>And not to forget <a href=\"http://progsource.de\">link to progsource</a> should work. And well - let's see how an image would be shown: </p><p><img src=\"http://progsource.de/img/progsource.png\" alt=\"an image\"/> </p><hr/><h3>and more headlines</h3><ul class=\"checklist\"><li><label><input type=\"checkbox\"/> how</label></li><li><label><input type=\"checkbox\"/> about<ul class=\"checklist\"><li><label><input type=\"checkbox\"/> a</label></li><li><label><input type=\"checkbox\" checked=\"checked\"/> nice</label></li></ul></label></li><li><label><input type=\"checkbox\" checked=\"checked\"/> check</label></li><li><label><input type=\"checkbox\"/> list</label></li></ul><h4>even a table</h4><table><thead><tr><th>Left header</th><th>middle header</th><th>last header</th></tr></thead><tbody><tr><td>cell 1</td><td>cell <strong>2</strong></td><td>cell 3</td></tr><tr><td>cell 4</td><td>cell 5</td><td>cell 6</td></tr></tbody><tfoot><tr><td>foot a</td><td>foot b</td><td>foot c</td></tr></tfoot></table><h5>h5</h5><h6>h6</h6>";
const std::string testHtml2 = "<h1>This is a test</h1><p>This should result in a praragraph it's that simple. </p><ul><li>an <i>unordered</i> list<ul><li>with some <strong>hierarchy</strong><ol><li>and an _ordered_</li><li>list</li><li>directly</li></ol></li><li>inside</li></ul></li></ul><pre><code>\nvar c = 'blub';\n</code></pre><blockquote><p>A Quote </p><p>With some <s>text</s> blocks inside </p><ul><li>even a list </li><li>should be </li><li>possible </li></ul></blockquote><p>And well <code>inline code</code> should also work. </p><h2>Another Headline</h2><p>And not to forget <a href=\"http://progsource.de\">link to progsource</a> should work. And well - let's see how an image would be shown: </p><p><img src=\"http://progsource.de/img/progsource.png\" alt=\"an image\"/> </p><hr/><a name=\"to top\"></a><h3>and more headlines</h3><ul class=\"checklist\"><li><label><input type=\"checkbox\"/> how</label></li><li><label><input type=\"checkbox\"/> about<ul class=\"checklist\"><li><label><input type=\"checkbox\"/> a</label></li><li><label><input type=\"checkbox\" checked=\"checked\"/> nice</label></li></ul></label></li><li><label><input type=\"checkbox\" checked=\"checked\"/> check</label></li><li><label><input type=\"checkbox\"/> list</label></li></ul><h4>even a table</h4><table><thead><tr><th>Left header</th><th>middle header</th><th>last header</th></tr></thead><tbody><tr><td>cell 1</td><td>cell <strong>2</strong></td><td>cell 3</td></tr><tr><td>cell 4</td><td>cell 5</td><td>cell 6</td></tr></tbody><tfoot><tr><td>foot a</td><td>foot b</td><td>foot c</td></tr></tfoot></table><h5>h5</h5><h6>h6</h6>";

파일 보기

@ -20,14 +20,3 @@ TEST(MADDY_STRIKETHROUGHPARSER, ItReplacesMarkdownWithStrikeThroughHTML)
ASSERT_EQ(expected, text); ASSERT_EQ(expected, text);
} }
TEST(MADDY_STRIKETHROUGHPARSER, ItDoesNotParseInsideInlineCode)
{
std::string text = "some text `~~bla~~` ` ~~text~~ ` testing <code>~~it~~</code> out";
std::string expected = "some text `~~bla~~` ` ~~text~~ ` testing <code>~~it~~</code> out";
auto strikeThroughParser = std::make_shared<maddy::StrikeThroughParser>();
strikeThroughParser->Parse(text);
ASSERT_EQ(expected, text);
}

파일 보기

@ -12,87 +12,22 @@
TEST(MADDY_STRONGPARSER, ItReplacesMarkdownWithStrongHTML) TEST(MADDY_STRONGPARSER, ItReplacesMarkdownWithStrongHTML)
{ {
struct testIt std::string text = "some text **bla** text testing **it** out";
{ std::string expected = "some text <strong>bla</strong> text testing <strong>it</strong> out";
std::string text;
std::string expected;
};
std::vector<testIt> tests
{
{
"some text **bla** text testing **it** out",
"some text <strong>bla</strong> text testing <strong>it</strong> out"
},
{
"some text __bla__ text testing __it__ out",
"some text <strong>bla</strong> text testing <strong>it</strong> out"
},
};
auto strongParser = std::make_shared<maddy::StrongParser>(); auto strongParser = std::make_shared<maddy::StrongParser>();
for (auto& test : tests) strongParser->Parse(text);
{
strongParser->Parse(test.text); ASSERT_EQ(expected, text);
ASSERT_EQ(test.expected, test.text);
}
} }
TEST(MADDY_STRONGPARSER, ItReplacesEmphasizedMarkdownNotWithStrongHTML) TEST(MADDY_STRONGPARSER, ItReplacesEmphasizedMarkdownNotWithStrongHTML)
{ {
struct testIt std::string text = "some text *bla* text testing **it** out";
{ std::string expected = "some text *bla* text testing <strong>it</strong> out";
std::string text;
std::string expected;
};
std::vector<testIt> tests
{
{
"some text *bla* text testing **it** out",
"some text *bla* text testing <strong>it</strong> out"
},
{
"some text _bla_ text testing __it__ out",
"some text _bla_ text testing <strong>it</strong> out"
},
};
auto strongParser = std::make_shared<maddy::StrongParser>(); auto strongParser = std::make_shared<maddy::StrongParser>();
for (auto& test : tests) strongParser->Parse(text);
{
strongParser->Parse(test.text); ASSERT_EQ(expected, text);
ASSERT_EQ(test.expected, test.text);
}
}
TEST(MADDY_STRONGPARSER, ItDoesNotParseInsideInlineCode)
{
struct testIt
{
std::string text;
std::string expected;
};
std::vector<testIt> tests
{
{
"some text **bla** `/**text**/` testing `**it**` out",
"some text **bla** `/**text**/` testing `**it**` out",
},
{
"some text _bla_ text testing __it__ out",
"some text _bla_ text testing <strong>it</strong> out"
},
};
auto strongParser = std::make_shared<maddy::StrongParser>();
for (auto& test : tests)
{
strongParser->Parse(test.text);
ASSERT_EQ(test.expected, test.text);
}
} }

파일 보기

@ -55,14 +55,9 @@ TEST_F(MADDY_UNORDEREDLISTPARSER, ItReplacesMarkdownWithAnHtmlUnorderedList)
std::vector<std::string> markdown = { std::vector<std::string> markdown = {
"* a" "* a"
, "* b" , "* b"
, "- c"
, "- d"
, "+ e"
, "+ f"
, "* g"
, "" , ""
}; };
std::string expected = "<ul><li>a</li><li>b</li><li>c</li><li>d</li><li>e</li><li>f</li><li>g</li></ul>"; std::string expected = "<ul><li>a</li><li>b</li></ul>";
for (std::string md : markdown) for (std::string md : markdown)
{ {
@ -85,12 +80,9 @@ TEST_F(MADDY_UNORDEREDLISTPARSER, ItReplacesMarkdownWithAnHierachicalHtmlList)
, " * e" , " * e"
, "* b" , "* b"
, " * c" , " * c"
, " + x"
, " + y"
, " - z"
, "" , ""
}; };
std::string expected = "<ul><li>a<ul><li>d</li><li>e</li></ul></li><li>b<ul><li>c</li><li>x</li><li>y</li><li>z</li></ul></li></ul>"; std::string expected = "<ul><li>a<ul><li>d</li><li>e</li></ul></li><li>b<ul><li>c</li></ul></li></ul>";
for (std::string md : markdown) for (std::string md : markdown)
{ {

파일 보기

@ -8,7 +8,7 @@
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
int main (int argc, char** argv) { int main (int argc, char** argv) {
::testing::GTEST_FLAG(throw_on_failure) = true; ::testing::GTEST_FLAG(throw_on_failure) = false;
::testing::InitGoogleMock(&argc, argv); ::testing::InitGoogleMock(&argc, argv);
return RUN_ALL_TESTS(); return RUN_ALL_TESTS();
} }