88 Commits
1.0.3 ... 1.2.0

Author SHA1 Message Date
Petra Baranski
cc7f95f4c1 fix: cmake fails to create zip file 2023-07-27 19:22:23 +02:00
Petra Baranski
d203e8502c docs: fix version in README.md 2023-07-27 19:11:29 +02:00
Petra Baranski
7624810374 fix: markdown-bug-report template 2023-07-27 19:09:50 +02:00
Petra Baranski
5dd974cca1 chore: fix cpp-bug-report template 2023-07-27 19:08:21 +02:00
Petra Baranski
6015b0c9e9 Merge pull request #43 from progsource/version-1.2.0
Version 1.2.0
2023-07-27 19:05:08 +02:00
Petra Baranski
155fb2c7e6 docs: update changelog for 1.2.0 2023-07-27 18:55:20 +02:00
Petra Baranski
123b921f2a style: make regex strings more readable 2023-07-27 18:48:03 +02:00
Petra Baranski
aecb1b30e6 chore: have prettier issue templates 2023-07-27 18:48:03 +02:00
Petra Baranski
baa5c9ccd0 ci: create release workflow 2023-07-27 18:48:03 +02:00
Petra Baranski
02d3ccaf22 docs: update version number 2023-07-27 18:47:50 +02:00
Petra Baranski
bf64f3e3dc Merge pull request #42 from progsource/latex-support
Latex support
2023-07-27 15:34:47 +02:00
Petra Baranski
9090c41709 chore: remove possible vscode files via gitignore 2023-07-27 14:52:08 +02:00
Petra Baranski
01d1e48d11 feat: add optional latex block support 2023-07-27 14:51:56 +02:00
Petra Baranski
f0c282e0c0 docs: update info about code block with class 2023-07-25 22:23:02 +02:00
Petra Baranski
cbcef933e1 Merge pull request #41 from progsource/codeblock-parser-language-class
Codeblock parser language class
2023-07-24 20:40:57 +02:00
Petra Baranski
a1001cb991 feat: add class to block code 2023-07-24 20:35:05 +02:00
Petra Baranski
d23ba23a4c docs: update changelog with last merged PR changes 2023-07-24 20:19:18 +02:00
Petra Baranski
d12186af8a Merge pull request #40 from progsource/advanced_config
feat: add config options to en-/disable each parser
2023-07-23 17:56:27 +02:00
Petra Baranski
41396ab246 feat: add config options to en-/disable each parser
Also fix cmake line, so that ctest can find the test executable;
update readme.
2023-07-23 17:51:03 +02:00
Petra Baranski
51e1813373 Merge pull request #39 from progsource/build_update
Use GitHub workflow instead of external tools.

Update cmake and gtest and add gtest via cmake instead
of github submodule.
2023-07-23 09:02:39 +02:00
Petra Baranski
823645995e ci: use github workflow instead of travis and appveyor 2023-07-23 08:51:10 +02:00
Petra Baranski
87ec259c28 build: add option for running tests
cmake configuration for running tests is now in the
tests folder.

Add option in main cmake file that has to be set to
ON and only build the tests in that case.

Update appveyor and travis ci configurations accordingly.
2023-07-23 06:04:34 +02:00
Petra Baranski
6dd47f5de5 build: move gtest into cmake and up cmake min version
cmake minimum required version is now 3.25.

Instead of loading gtest via git submodule, it is now loaded
in the cmake files.

gtest version upped to v1.13.0.
2023-07-23 05:37:11 +02:00
Petra Baranski
f3d934d6ec Merge pull request #35 from quitesimpleorg/fix/add_static_italic
italicparser: Parse(): Add static keyword to regex
2021-04-18 20:40:11 +02:00
Albert S
a28769be2b italicparser: Parse(): Add static keyword to regex
In line with the other parsers, add the static keyword to the
regex.
2021-04-18 20:24:26 +02:00
Petra Baranski
adb1a910d4 fixed spelling in README 2020-10-10 08:11:48 +02:00
Petra Baranski
f38b3cf4fa cleaned up Changelog colors 2020-10-10 08:08:35 +02:00
Petra Baranski
6b632abd44 Added CHANGELOG and CONTRIBUTING 2020-10-10 08:03:21 +02:00
Petra Baranski
38f802de09 updated version 2020-10-04 19:03:44 +02:00
Petra Baranski
348aa81607 Improved cmake setup 2020-10-04 19:02:39 +02:00
Petra Baranski
ba5cb5d6c5 Merge pull request #34 from solodolo/numeric-list
orderedlistparser: Add parsing support for fully numeric markdown lists
2020-10-04 18:40:57 +02:00
Petra Baranski
fd698d1f5f Merge branch 'master' into numeric-list 2020-10-04 18:31:29 +02:00
Petra Baranski
5b2f20041c Merge pull request #30 from eklitzke/istream
make Parser::Parse accept istreams instead of stringstream
2020-10-04 18:21:25 +02:00
Drew Mettlach
cde0137e90 orderedlistparser: Add parsing support for fully numeric markdown lists 2020-10-03 17:22:21 -05:00
Evan Klitzke
71ee49d1ea make Parser::Parse accept istreams instead of stringstream 2020-07-12 11:30:41 -07:00
Petra Baranski
19338d2b56 Merge pull request #28 from martin357/master
Added another character for bullet point("-", "+")
2020-02-08 07:54:56 +01:00
Martin Kopecky
cb75226b4a *, + and - are equivalent for making unordered bullet lists as per https://spec-md.com/#sec-Lists
Modified tests and documentation to reflect that.
2020-02-03 22:52:57 +01:00
Martin Kopecký
51d61b68fe Added another character for bullet point("-") 2020-01-30 17:38:55 +01:00
Petra Baranski
2fe7a71bf3 No paragraphs for html (#27)
* htmlparser added
* Added ParserConfig
    * added option to disable the emphasized parser
    * added option to not wrap HTML in markdown within a paragraph in output
* Updated docs
* Version update 1.1.1
2019-12-27 19:48:29 +01:00
Petra Baranski
3b3e16a6bc Merge pull request #25 from patrickelectric/breakline
breaklineparser
2019-12-19 13:29:15 +01:00
Patrick José Pereira
a03ff9c33d definitions: Add break line
Signed-off-by: Patrick José Pereira <patrickelectric@gmail.com>
2019-12-18 21:07:47 -03:00
Patrick José Pereira
77782635d4 breaklineparser: First version
Some markdown provides such as GitHub, uses \r\n to create <br>

Signed-off-by: Patrick José Pereira <patrickelectric@gmail.com>
2019-12-16 11:10:25 -03:00
Petra Baranski
0fb6de703d Merge pull request #24 from patrickelectric/update_gtest
gtest: Use the last release version release-1.10.0
2019-12-14 13:35:04 +01:00
Patrick José Pereira
4e4e17d2c0 gtest: Use the last release version release-1.10.0
Signed-off-by: Patrick José Pereira <patrickelectric@gmail.com>
2019-12-04 09:15:56 -03:00
M. Petra Baranski
59b808bf50 update readme one more time 2019-02-19 03:50:46 +01:00
M. Petra Baranski
ab0872a6cb updated readme 2019-02-19 03:20:04 +01:00
Petra Baranski
7d5d311ecb Merge pull request #19 from progsource/release_1.1.0
updated version info for 1.1.0
2019-02-19 03:12:53 +01:00
M. Petra Baranski
1f00ae90b2 updated version info for 1.1.0 2019-02-19 03:06:12 +01:00
Petra Baranski
b167316d52 Merge pull request #18 from progsource/appveyor
try out appveyor
2019-02-19 02:51:43 +01:00
M. Petra Baranski
3484198ade appveyor - use debug 2019-02-19 02:43:15 +01:00
M. Petra Baranski
c5c37a7627 appveyor - now? 2019-02-19 02:34:39 +01:00
M. Petra Baranski
0762f6cc5d appveyor - build this now.... 2019-02-19 02:31:16 +01:00
M. Petra Baranski
92db217966 appveyor - guess where the sln might be 2019-02-19 02:25:57 +01:00
M. Petra Baranski
b5a6628f44 appveyor - try to specify sln 2019-02-19 02:23:21 +01:00
M. Petra Baranski
371dc41aff appveyor do cmake before build 2019-02-19 02:21:00 +01:00
M. Petra Baranski
519c81eaab appveyor in test_script it is already in tmp 2019-02-19 02:12:54 +01:00
M. Petra Baranski
77a74fef56 appveyor on init the repo isn't cloned yet 2019-02-19 02:10:38 +01:00
M. Petra Baranski
81090b8ca7 init submodules for appveyor 2019-02-19 02:09:23 +01:00
M. Petra Baranski
0b00ee7137 VS 15 is 2017 version... 2019-02-19 02:06:19 +01:00
M. Petra Baranski
af6dd8f65a try out appveyor 2019-02-19 02:02:58 +01:00
Petra Baranski
ab567fc2f1 Merge pull request #17 from patrickelectric/windows
blockparser: Add missing includes to fix msvc builds
2019-02-19 01:27:59 +01:00
Patrick José Pereira
62c840bb77 blockparser: Add missing includes to fix msvc builds
Signed-off-by: Patrick José Pereira <patrickelectric@gmail.com>
2019-02-13 15:47:16 -02:00
Petra Baranski
8f0ec363fd Merge pull request #12 from patrickelectric/travis
Update travis gcc version and add macox/clang test
2018-10-25 20:11:16 +02:00
Patrick José Pereira
a84da9de61 emphasizedparser: Underscore does not need backslash
Signed-off-by: Patrick José Pereira <patrickelectric@gmail.com>
2018-10-25 14:51:50 -03:00
Patrick José Pereira
7c26aa0431 strongparser: Underscore does not need backslash
Signed-off-by: Patrick José Pereira <patrickelectric@gmail.com>
2018-10-25 14:51:49 -03:00
Patrick José Pereira
3c54e901c3 travis: Add macox/clang test
Signed-off-by: Patrick José Pereira <patrickelectric@gmail.com>
2018-10-25 14:51:49 -03:00
Patrick José Pereira
dae4b5bb35 travis: Move to gcc-7
Signed-off-by: Patrick José Pereira <patrickelectric@gmail.com>
2018-10-25 14:51:49 -03:00
Petra Baranski
0af145ab8f Merge pull request #15 from progsource/add-lineparser-dtro
added dtor to lineparser
2018-10-25 17:51:41 +02:00
M. Petra Baranski
8294841cf5 added dtor to lineparser 2018-10-25 17:45:52 +02:00
Petra Baranski
e6bd0bdb4f Merge pull request #14 from progsource/add-dtor
added BlockParser dtor
2018-10-25 17:35:40 +02:00
M. Petra Baranski
348532acb8 added BlockParser dtor 2018-10-25 17:26:25 +02:00
Petra Baranski
6af5374138 Merge pull request #13 from patrickelectric/test_italic
test_maddy_parser: Add italic test
2018-10-25 17:15:48 +02:00
Patrick José Pereira
c7eef2b34a test_maddy_parser: Add italic test
Signed-off-by: Patrick José Pereira <patrickelectric@gmail.com>
2018-10-25 12:01:25 -03:00
Petra Baranski
be681034e0 Merge pull request #10 from patrickelectric/add_italic
Add italic parser
2018-10-25 16:48:59 +02:00
Petra Baranski
78652f64d5 Merge branch 'master' into add_italic 2018-10-25 16:42:33 +02:00
Petra Baranski
b5f24f01a3 Merge pull request #9 from patrickelectric/more_bold
Add __ tag in bold parser and test
2018-10-25 16:41:54 +02:00
Patrick José Pereira
eae3b270c0 docs: Update italic and emphasized documentation
Signed-off-by: Patrick José Pereira <patrickelectric@gmail.com>
2018-10-25 11:36:22 -03:00
Patrick José Pereira
2562d780b8 test_maddy_parser: Update main test with emphasized tag
Signed-off-by: Patrick José Pereira <patrickelectric@gmail.com>
2018-10-25 11:36:22 -03:00
Patrick José Pereira
6e7aec7947 test_maddy_emphasizedparser: Update tests
Signed-off-by: Patrick José Pereira <patrickelectric@gmail.com>
2018-10-25 11:36:22 -03:00
Patrick José Pereira
ee42f7eae9 emphasizedparser: Move from *this* to _this_
Signed-off-by: Patrick José Pereira <patrickelectric@gmail.com>
2018-10-25 11:36:22 -03:00
Patrick José Pereira
e8ba8f661a test_maddy_italicparser: Add tests for the italic parser
Signed-off-by: Patrick José Pereira <patrickelectric@gmail.com>
2018-10-25 11:36:22 -03:00
Patrick José Pereira
9b37255346 italicparser: Add first version
Signed-off-by: Patrick José Pereira <patrickelectric@gmail.com>
2018-10-25 11:36:22 -03:00
Patrick José Pereira
a85ba0eec7 docs: Update strong documentation
Signed-off-by: Patrick José Pereira <patrickelectric@gmail.com>
2018-10-25 11:34:12 -03:00
Patrick José Pereira
7e56e82b6a AUTHORS: Add my name
Signed-off-by: Patrick José Pereira <patrickelectric@gmail.com>
2018-10-25 11:34:12 -03:00
Patrick José Pereira
62365f1c7c test_maddy_strongparser: Add tests to __ tag
Signed-off-by: Patrick José Pereira <patrickelectric@gmail.com>
2018-10-25 11:34:12 -03:00
Patrick José Pereira
eb2b4fa929 strongparser: Add __ tag
Signed-off-by: Patrick José Pereira <patrickelectric@gmail.com>
2018-10-25 11:34:08 -03:00
Petra Baranski
a19845cdb5 Merge pull request #11 from patrickelectric/fix_clang
blackparser: Add missing include
2018-10-25 08:48:53 +02:00
Patrick José Pereira
22c656f855 blackparser: Add missing include
Fix clang build

Signed-off-by: Patrick José Pereira <patrickelectric@gmail.com>
2018-10-22 20:16:13 -03:00
51 changed files with 1780 additions and 212 deletions

View File

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

View File

@@ -0,0 +1,63 @@
name: C++ Bug Report
description: File a bug report regarding C++ problems
title: "[Bug][C++]: "
labels: ["bug", "triage"]
body:
- type: markdown
attributes:
value: |
Thanks for taking the time to fill out this bug report!
- type: input
id: os
attributes:
label: Operating System
description: On which OS are you running maddy?
placeholder: ex. Windows/Linux/OSX
validations:
required: true
- type: input
id: compiler
attributes:
label: Compiler
description: Which compiler do you use?
placeholder: ex. mingw/Visual Studio/clang
validations:
required: true
- type: input
id: compiler_flags
attributes:
label: Compiler flags
description: Which compiler flags do you use?
placeholder: ex. -fno-rtti
validations:
required: true
- type: dropdown
id: maddy_version
attributes:
label: maddy version
description: What version of maddy are you using?
options:
- 1.2.0 (latest)
- 1.1.2
- 1.1.1
- 1.1.0
- 1.0.3
- 1.0.2
- 1.0.1
- 1.0.0
validations:
required: true
- type: textarea
id: example
attributes:
label: Minimal C++ example
description: To be able to reproduce your issue, please give some example C++ code which creates problems.
validations:
required: true
- type: textarea
id: whats-wrong
attributes:
label: What is not working? What did you try?
description: Also, what did you expect to happen?
validations:
required: true

View File

@@ -0,0 +1,15 @@
name: Feature Request
description: Missing some feature?
labels: ["feature"]
body:
- type: markdown
attributes:
value: |
Thanks for taking the time to create a feature request!
- type: textarea
id: feature-description
attributes:
label: What are you missing in maddy?
description: If you want some extra Markdown supported, please also write a Markdown example and an expected HTML output.
validations:
required: true

View File

@@ -0,0 +1,63 @@
name: Markdown Bug Report
description: File a bug report regarding Markdown problems
title: "[Bug][Markdown]: "
labels: ["bug", "triage"]
body:
- type: markdown
attributes:
value: |
Thanks for taking the time to fill out this bug report!
- type: input
id: os
attributes:
label: Operating System
description: On which OS are you running maddy?
placeholder: ex. Windows/Linux/OSX
validations:
required: true
- type: input
id: compiler
attributes:
label: Compiler
description: Which compiler do you use?
placeholder: ex. mingw/Visual Studio/clang
validations:
required: true
- type: input
id: compiler_flags
attributes:
label: Compiler flags
description: Which compiler flags do you use?
placeholder: ex. -fno-rtti
validations:
required: true
- type: dropdown
id: maddy_version
attributes:
label: maddy version
description: What version of maddy are you using?
options:
- 1.2.0 (latest)
- 1.1.2
- 1.1.1
- 1.1.0
- 1.0.3
- 1.0.2
- 1.0.1
- 1.0.0
validations:
required: true
- type: textarea
id: example
attributes:
label: Minimal Mardown example
description: To be able to reproduce your issue, please give some example Markdown which creates problems.
validations:
required: true
- type: textarea
id: whats-wrong
attributes:
label: What is not working? What did you try?
description: Also, what did you expect to happen?
validations:
required: true

View File

@@ -0,0 +1,34 @@
name: release
permissions:
contents: write
on:
push:
tags:
- '*'
jobs:
release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: lukka/get-cmake@latest
with:
cmakeVersion: "~3.25.0" # <--= optional, use most recent 3.25.x version
ninjaVersion: "^1.11.1" # <--= optional, use most recent 1.x version
- name: create zip
run: |
mkdir build
mkdir tmp
cd tmp
cmake -DMADDY_CREATE_PACKAGE=ON ..
make maddy_package
- name: create release
uses: svenstaro/upload-release-action@v2
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: build/maddy-src.zip
tag: ${{ github.ref }}
body: "You can find all changes of this release in the [changelog](https://github.com/progsource/maddy/blob/master/CHANGELOG.md)"

63
.github/workflows/run-tests.yml vendored Normal file
View File

@@ -0,0 +1,63 @@
name: run-tests
run-name: test ${{ github.ref }}
on:
push:
branches:
- master
pull_request:
branches:
- master
jobs:
test-on-ubuntu:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: lukka/get-cmake@latest
with:
cmakeVersion: "~3.25.0" # <--= optional, use most recent 3.25.x version
ninjaVersion: "^1.11.1" # <--= optional, use most recent 1.x version
- name: build
run: |
mkdir tmp
cd tmp
cmake -DMADDY_BUILD_WITH_TESTS=ON ..
make -j4
- name: run tests
run: |
./build/MaddyTests
test-on-windows:
runs-on: windows-latest
steps:
- uses: actions/checkout@v3
- uses: lukka/get-cmake@latest
with:
cmakeVersion: "~3.25.0" # <--= optional, use most recent 3.25.x version
ninjaVersion: "^1.11.1" # <--= optional, use most recent 1.x version
- name: build
run: |
mkdir tmp
cd tmp
cmake -G "Visual Studio 17 2022" -A x64 -DMADDY_BUILD_WITH_TESTS=ON ..
cmake --build . --config Debug
- name: run tests
run: |
./build/Debug/MaddyTests.exe
test-on-osx:
runs-on: macos-latest
steps:
- uses: actions/checkout@v3
- uses: lukka/get-cmake@latest
with:
cmakeVersion: "~3.25.0" # <--= optional, use most recent 3.25.x version
ninjaVersion: "^1.11.1" # <--= optional, use most recent 1.x version
- name: build
run: |
mkdir tmp
cd tmp
cmake -DMADDY_BUILD_WITH_TESTS=ON ..
make -j4
- name: run tests
run: |
./build/MaddyTests

4
.gitignore vendored
View File

@@ -161,10 +161,6 @@ tags
### VisualStudioCode ###
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
.history
### Xcode ###

3
.gitmodules vendored
View File

@@ -1,3 +0,0 @@
[submodule "libs/gtest"]
path = libs/gtest
url = https://github.com/google/googletest.git

View File

@@ -1,18 +0,0 @@
dist: trusty
sudo: false
language: cpp
compiler: g++
install: export CXX="g++-6"
addons:
apt:
sources:
- ubuntu-toolchain-r-test
packages:
- g++-6
script:
- mkdir tmp
- cd tmp
- cmake ..
- make
- ../build/MaddyTests

View File

@@ -5,3 +5,8 @@ licensing terms detailed in LICENSE.
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)
Albert Schwarzkopf (dev-maddy@quitesimple.org)

81
CHANGELOG.md Normal file
View File

@@ -0,0 +1,81 @@
# 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
* ?
## version 1.2.0 2023-07-27
* ![**ADDED**](https://img.shields.io/badge/-ADDED-%23099) Added Changelog
* ![**ADDED**](https://img.shields.io/badge/-ADDED-%23099) Added contribution guideline
* ![**CHANGED**](https://img.shields.io/badge/-CHANGED-%23e90) updated cmake minimum required version to 3.25
* ![**CHANGED**](https://img.shields.io/badge/-CHANGED-%23e90) gtest is now loaded via cmake and not a git submodule any longer - updated gtest version to 1.13.0
* ![**CHANGED**](https://img.shields.io/badge/-CHANGED-%23e90) tests are only run if the cmake option `MADDY_BUILD_WITH_TESTS` is on, moved test cmake code to the `tests` subfolder
* ![**REMOVED**](https://img.shields.io/badge/-REMOVED-%23900) travis CI and appveyor
* ![**ADDED**](https://img.shields.io/badge/-ADDED-%23099) GitHub workflow for tests
* ![**DEPRECATED**](https://img.shields.io/badge/-DEPRECATED-%23666) config flags `isEmphasizedParserEnabled` and `isHTMLWrappedInParagraph`
* ![**ADDED**](https://img.shields.io/badge/-ADDED-%23099) config flag `enabledParsers` to en-/disable each parser separately
* ![**ADDED**](https://img.shields.io/badge/-ADDED-%23099) class attribute to code blocks if there is text after the three backticks like ` ```cpp`
* ![**ADDED**](https://img.shields.io/badge/-ADDED-%23099) optional support for latex blocks - it's off by default
* ![**ADDED**](https://img.shields.io/badge/-ADDED-%23099) version info to the parser class
* ![**ADDED**](https://img.shields.io/badge/-ADDED-%23099) GitHub workflow for release, so that one can include maddy easier via cmake's `FetchContent`
## 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

View File

@@ -1,17 +1,10 @@
# This project is licensed under the MIT license. For more information see the
# LICENSE file.
cmake_minimum_required(VERSION 2.8)
cmake_minimum_required(VERSION 3.25)
project(maddy)
enable_testing()
# ------------------------------------------------------------------------------
set(MADDY_CPP_VERSION 14)
add_definitions(-DCPP_VERSION=${MADDY_CPP_VERSION})
# ------------------------------------------------------------------------------
set(CMAKE_BINARY_DIR ${CMAKE_CURRENT_SOURCE_DIR}/build)
@@ -20,51 +13,49 @@ set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR})
# ------------------------------------------------------------------------------
option(MADDY_BUILD_WITH_TESTS "enable building tests - does not work with zip download" OFF)
if(${MADDY_BUILD_WITH_TESTS})
enable_testing()
endif()
option(MADDY_CREATE_PACKAGE "create a package for a version release" OFF)
# ------------------------------------------------------------------------------
set(MADDY_INCLUDE_DIR ${PROJECT_SOURCE_DIR}/include)
file(GLOB_RECURSE MADDY_TESTS_FILES ${CMAKE_CURRENT_SOURCE_DIR}/tests/maddy/*.cpp)
# ------------------------------------------------------------------------------
set(
CMAKE_CXX_FLAGS
"${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"
)
if(NOT DEFINED CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 14)
endif()
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# ------------------------------------------------------------------------------
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()
if(${CMAKE_CXX_STANDARD} LESS 14)
message(FATAL_ERROR "maddy requires >=C++14")
endif()
# ------------------------------------------------------------------------------
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/libs/gtest/googlemock)
add_subdirectory(libs)
# ------------------------------------------------------------------------------
include_directories(
${LIBS_INCLUDE_DIRS}
add_library(maddy INTERFACE)
target_include_directories(maddy INTERFACE
${MADDY_INCLUDE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/tests
)
# ------------------------------------------------------------------------------
add_executable(
MaddyTests
${MADDY_TESTS_FILES}
${CMAKE_CURRENT_SOURCE_DIR}/tests/main.cpp
)
target_link_libraries(MaddyTests gmock_main)
add_test(MaddyTests ${CMAKE_CURRENT_SOURCE_DIR}/build/MaddyTests)
if(${MADDY_BUILD_WITH_TESTS})
add_subdirectory(tests)
endif()
# ------------------------------------------------------------------------------
if(${MADDY_CREATE_PACKAGE})
set(MADDY_PACKAGE_FILES include/ CMakeLists.txt LICENSE)
add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/${PROJECT_NAME}-src.zip
COMMAND ${CMAKE_COMMAND} -E tar c ${CMAKE_BINARY_DIR}/${PROJECT_NAME}-src.zip --format=zip -- ${MADDY_PACKAGE_FILES}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
DEPENDS ${MADDY_PACKAGE_FILES})
add_custom_target(${PROJECT_NAME}_package DEPENDS ${CMAKE_BINARY_DIR}/${PROJECT_NAME}-src.zip)
endif()

26
CONTRIBUTING.md Normal file
View File

@@ -0,0 +1,26 @@
# 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.

View File

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

View File

@@ -1,4 +1,4 @@
Copyright 2017 M. Petra Baranski
Copyright 2017, 2018, 2019, 2020, 2023 M. Petra Baranski
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

View File

@@ -1,8 +1,7 @@
# maddy
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![Version: 1.0.3](https://img.shields.io/badge/Version-1.0.3-brightgreen.svg)](https://semver.org/)
[![Build Status](https://travis-ci.org/progsource/maddy.svg?branch=master)](https://travis-ci.org/progsource/maddy)
[![Version: 1.2.0](https://img.shields.io/badge/Version-1.2.0-brightgreen.svg)](https://semver.org/)
maddy is a C++ Markdown to HTML **header-only** parser library.
@@ -12,7 +11,9 @@ 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)
* Linux (gcc)
* OSX (clang)
* Windows (Visual Studio 17 2022, mingw)
## Dependencies
@@ -20,13 +21,40 @@ It is tested to work on:
## Why maddy?
When I was needing a Markdown parser in C++ I couldn't find any, that was
When I was looking for 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).
## How to add maddy to your cmake project
You can use [FetchContent](https://cmake.org/cmake/help/latest/module/FetchContent.html)
which was introduced in CMake 3.11.
This way you can add
```cmake
include(FetchContent)
FetchContent_Declare(
maddy
URL https://github.com/progsource/maddy/.../maddy-src.zip
)
FetchContent_MakeAvailable(maddy)
add_executable(my_exe)
target_link_libraries(my_exe PUBLIC maddy)
```
to your CMake file to make it work. Check the
[release](https://github.com/progsource/maddy/releases) for the full
zip-file-url.
The zip only contains a `CMakeLists.txt`, the `include` folder and the `LICENSE`
file.
## How to use
To use maddy in your project, simply add the include path of maddy to yours
@@ -39,10 +67,21 @@ and in the code, you can then do the following:
#include "maddy/parser.h"
std::stringstream markdownInput("");
std::shared_ptr<maddy::Parser> parser = std::make_shared<maddy::Parser>();
// config is optional
std::shared_ptr<maddy::ParserConfig> config = std::make_shared<maddy::ParserConfig>();
// config->isEmphasizedParserEnabled = false; // default true - this flag is deprecated
// config->isHTMLWrappedInParagraph = false; // default true - this flag is deprecated
config->enabledParsers &= ~maddy::types::EMPHASIZED_PARSER; // equivalent to !isEmphasizedParserEnabled
config->enabledParsers |= maddy::types::HTML_PARSER; // equivalent to !isHTMLWrappedInParagraph
std::shared_ptr<maddy::Parser> parser = std::make_shared<maddy::Parser>(config);
std::string htmlOutput = parser->Parse(markdownInput);
```
You can find all parser flags in
[`include/maddy/parserconfig.h`](include/maddy/parserconfig.h).
## How to run the tests
*(tested on Linux with
@@ -54,10 +93,9 @@ Open your preferred terminal and type:
```shell
git clone https://github.com/progsource/maddy.git
cd maddy
git submodule update --init --recursive
mkdir tmp
cd tmp
cmake ..
cmake -DMADDY_BUILD_WITH_TESTS=ON ..
make
make test # or run the executable in ../build/MaddyTests
```
@@ -66,6 +104,7 @@ make test # or run the executable in ../build/MaddyTests
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)
* [Create a GitHub issue](https://github.com/progsource/maddy/issues/new)
* Create a pull request with an own branch
Please also read [CONTRIBUTING.md](CONTRIBUTING.md).

View File

@@ -7,6 +7,10 @@ destroy the output, if there was HTML in your markdown.
The Parser expects you to use spaces and not tabs for indentation in the
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
```
@@ -40,11 +44,13 @@ results in
## Lists
### unordered
Characters "*", "+" or "-" to make an unordered "bullet" list are equivalent.
```
* unordered
- unordered
* list
* items
+ items
```
results in
@@ -62,8 +68,8 @@ results in
* list
* items
* in
* an
* hierarchy
+ an
- hierarchy
```
results in
@@ -88,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
@@ -194,6 +220,18 @@ results in
<pre><code>
some code
</code></pre>
```
```cpp
int a = 42;
```
results in
```html
<pre class="cpp"><code>
int a = 42;
</code></pre>
```
## Inline code
@@ -221,16 +259,30 @@ results in
```
**bold text**
__bold text__
```
results in
```html
<strong>bold text</strong>
<strong>bold text</strong>
```
## italic
```
*italic text*
```
results in
```html
<i>italic text</i>
```
## emphasized
This can be disabled by setting `config->isEmphasizedParserEnabled = false`.
```
*emphasized text*
_emphasized text_
```
results in
```html
@@ -257,6 +309,17 @@ results in
<hr/>
```
## break line
```
New\r\nLine
```
results in
```html
New<br>
Line
```
## Images
```
@@ -313,3 +376,29 @@ becomes
</table>
```
table header and footer are optional
## LaTeX(MathJax) block support
To turn on the LaTeX support - which basically is only a
[MathJax](https://www.mathjax.org/) support and makes sure, that formulas aren't
internally checked for other parsers - it has to be enabled in config:
```cpp
std::shared_ptr<maddy::ParserConfig> config = std::make_shared<maddy::ParserConfig>();
config->enabledParsers |= maddy::types::LATEX_BLOCK_PARSER;
std::shared_ptr<maddy::Parser> parser = std::make_shared<maddy::Parser>(config);
std::string htmlOutput = parser->Parse(markdownInput);
```
After this you can do the following in Markdown:
```
$$x = {-b \\pm \\sqrt{b^2-4ac} \\over 2a}.$$
```
Which results in
```html
$$x = {-b \\pm \\sqrt{b^2-4ac} \\over 2a}.$$\n
```

View File

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

View File

@@ -0,0 +1,51 @@
/*
* 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

View File

@@ -54,7 +54,7 @@ public:
static bool
IsStartingLine(const std::string& line)
{
static std::regex re("^- \\[[x| ]\\] .*");
static std::regex re(R"(^- \[[x| ]\] .*)");
return std::regex_match(line, re);
}
@@ -92,11 +92,11 @@ protected:
static std::regex lineRegex("^(- )");
line = std::regex_replace(line, lineRegex, "");
static std::regex emptyBoxRegex("^\\[ \\]");
static std::regex emptyBoxRegex(R"(^\[ \])");
static std::string emptyBoxReplacement = "<input type=\"checkbox\"/>";
line = std::regex_replace(line, emptyBoxRegex, emptyBoxReplacement);
static std::regex boxRegex("^\\[x\\]");
static std::regex boxRegex(R"(^\[x\])");
static std::string boxReplacement = "<input type=\"checkbox\" checked=\"checked\"/>";
line = std::regex_replace(line, boxRegex, boxReplacement);

View File

@@ -74,7 +74,7 @@ public:
static bool
IsStartingLine(const std::string& line)
{
static std::regex re("^(?:`){3}$");
static std::regex re("^(?:`){3}(.*)$");
return std::regex_match(line, re);
}
@@ -123,6 +123,13 @@ protected:
return;
}
}
else if (!this->isStarted && line.substr(0, 3) == "```")
{
line = "<pre class=\"" + line.substr(3) + "\"><code>\n";
this->isStarted = true;
this->isFinished = false;
return;
}
line += "\n";
}

View File

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

127
include/maddy/htmlparser.h Normal file
View File

@@ -0,0 +1,127 @@
/*
* 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

View File

@@ -41,7 +41,7 @@ public:
void
Parse(std::string& line) override
{
static std::regex re("\\!\\[([^\\]]*)\\]\\(([^\\]]*)\\)");
static std::regex re(R"(\!\[([^\]]*)\]\(([^\]]*)\))");
static std::string replacement = "<img src=\"$2\" alt=\"$1\"/>";
line = std::regex_replace(line, re, replacement);

View File

@@ -0,0 +1,50 @@
/*
* 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(R"((?!.*`.*|.*<code>.*)\*(?!.*`.*|.*<\/code>.*)([^\*]*)\*(?!.*`.*|.*<\/code>.*))");
static std::string replacement = "<i>$1</i>";
line = std::regex_replace(line, re, replacement);
}
}; // class ItalicParser
// -----------------------------------------------------------------------------
} // namespace maddy

View File

@@ -0,0 +1,135 @@
/*
* This project is licensed under the MIT license. For more information see the
* LICENSE file.
*/
#pragma once
// -----------------------------------------------------------------------------
#include <functional>
#include <string>
#include <regex>
#include "maddy/blockparser.h"
// -----------------------------------------------------------------------------
namespace maddy {
// -----------------------------------------------------------------------------
/**
* LatexBlockParser
*
* Support for https://www.mathjax.org/
* Be aware, that if you want to make MathJax work, you need also their
* JavaScript library added to your HTML code.
* maddy does not itself add that code to be more flexible in how you write your
* head and full body.
*
* From Markdown: `$$` surrounded text
*
* ```
* $$some formula
* $$
* ```
*
* To HTML:
*
* ```
* $$some formula
* $$
* ```
*
* @class
*/
class LatexBlockParser : public BlockParser
{
public:
/**
* ctor
*
* @method
* @param {std::function<void(std::string&)>} parseLineCallback
* @param {std::function<std::shared_ptr<BlockParser>(const std::string& line)>} getBlockParserForLineCallback
*/
LatexBlockParser(
std::function<void(std::string&)> parseLineCallback,
std::function<std::shared_ptr<BlockParser>(const std::string& line)> getBlockParserForLineCallback
)
: BlockParser(parseLineCallback, getBlockParserForLineCallback)
, isStarted(false)
, isFinished(false)
{}
/**
* IsStartingLine
*
* If the line starts with two dollars, then it is a latex block.
*
* ```
* $$
* ```
*
* @method
* @param {const std::string&} line
* @return {bool}
*/
static bool
IsStartingLine(const std::string& line)
{
static std::regex re(R"(^(?:\$){2}(.*)$)");
return std::regex_match(line, re);
}
/**
* IsFinished
*
* @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 && line.substr(0, 2) == "$$")
{
this->isStarted = true;
this->isFinished = false;
}
if (this->isStarted && !this->isFinished && line.size() > 1 && line.substr(line.size() - 2, 2) == "$$")
{
this->isFinished = true;
this->isStarted = false;
}
line += "\n";
}
private:
bool isStarted;
bool isFinished;
}; // class LatexBlockParser
// -----------------------------------------------------------------------------
} // namespace maddy

View File

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

View File

@@ -41,7 +41,7 @@ public:
void
Parse(std::string& line) override
{
static std::regex re("\\[([^\\]]*)\\]\\(([^\\]]*)\\)");
static std::regex re(R"(\[([^\]]*)\]\(([^\]]*)\))");
static std::string replacement = "<a href=\"$2\">$1</a>";
line = std::regex_replace(line, re, replacement);

View File

@@ -89,9 +89,9 @@ protected:
bool isStartOfNewListItem = this->isStartOfNewListItem(line);
uint32_t indentation = getIndentationWidth(line);
static std::regex orderedlineRegex("^1\\. ");
static std::regex orderedlineRegex(R"(^[1-9]+[0-9]*\. )");
line = std::regex_replace(line, orderedlineRegex, "");
static std::regex unorderedlineRegex("^(\\* )");
static std::regex unorderedlineRegex(R"(^\* )");
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(R"(^(?:[1-9]+[0-9]*\. |\* ).*)");
return std::regex_match(line, re);
}
}; // class OrderedListParser

View File

@@ -34,18 +34,21 @@ public:
*/
ParagraphParser(
std::function<void(std::string&)> parseLineCallback,
std::function<std::shared_ptr<BlockParser>(const std::string& line)> getBlockParserForLineCallback
std::function<std::shared_ptr<BlockParser>(const std::string& line)> getBlockParserForLineCallback,
bool isEnabled
)
: BlockParser(parseLineCallback, getBlockParserForLineCallback)
, isStarted(false)
, isFinished(false)
, isEnabled(isEnabled)
{}
/**
* IsStartingLine
*
* If the line is not empty, it will be a paragraph. So this block parser has
* to always run as the last one!
* If the line is not empty, it will be a paragraph.
*
* This block parser has to always run as the last one!
*
* @method
* @param {const std::string&} line
@@ -87,19 +90,31 @@ protected:
void
parseBlock(std::string& line) override
{
if (!this->isStarted)
if (this->isEnabled && !this->isStarted)
{
line = "<p>" + line + " ";
this->isStarted = true;
return;
}
else if (!this->isEnabled && !this->isStarted)
{
line += " ";
this->isStarted = true;
return;
}
if (line.empty())
if (this->isEnabled && line.empty())
{
line += "</p>";
this->isFinished = true;
return;
}
else if (!this->isEnabled && line.empty())
{
line += "<br/>";
this->isFinished = true;
return;
}
line += " ";
}
@@ -107,6 +122,7 @@ protected:
private:
bool isStarted;
bool isFinished;
bool isEnabled;
}; // class ParagraphParser
// -----------------------------------------------------------------------------

View File

@@ -10,11 +10,15 @@
#include <functional>
#include <string>
#include "maddy/parserconfig.h"
// BlockParser
#include "maddy/checklistparser.h"
#include "maddy/codeblockparser.h"
#include "maddy/headlineparser.h"
#include "maddy/horizontallineparser.h"
#include "maddy/htmlparser.h"
#include "maddy/latexblockparser.h"
#include "maddy/orderedlistparser.h"
#include "maddy/paragraphparser.h"
#include "maddy/quoteparser.h"
@@ -22,9 +26,11 @@
#include "maddy/unorderedlistparser.h"
// LineParser
#include "maddy/breaklineparser.h"
#include "maddy/emphasizedparser.h"
#include "maddy/imageparser.h"
#include "maddy/inlinecodeparser.h"
#include "maddy/italicparser.h"
#include "maddy/linkparser.h"
#include "maddy/strikethroughparser.h"
#include "maddy/strongparser.h"
@@ -45,6 +51,14 @@ namespace maddy {
class Parser
{
public:
/**
* Version info
*
* Check https://github.com/progsource/maddy/blob/master/CHANGELOG.md
* for the changelog.
*/
static const std::string VERSION() { static const std::string v = "1.2.0"; return v; }
/**
* ctor
*
@@ -52,24 +66,94 @@ public:
*
* @method
*/
Parser()
: emphasizedParser(std::make_shared<EmphasizedParser>())
, imageParser(std::make_shared<ImageParser>())
, inlineCodeParser(std::make_shared<InlineCodeParser>())
, linkParser(std::make_shared<LinkParser>())
, strikeThroughParser(std::make_shared<StrikeThroughParser>())
, strongParser(std::make_shared<StrongParser>())
{}
Parser(std::shared_ptr<ParserConfig> config = nullptr)
: config(config)
{
// deprecated backward compatibility
// will be removed in 1.4.0 latest including the booleans
if (this->config && !this->config->isEmphasizedParserEnabled)
{
this->config->enabledParsers &= ~maddy::types::EMPHASIZED_PARSER;
}
if (this->config && !this->config->isHTMLWrappedInParagraph)
{
this->config->enabledParsers |= maddy::types::HTML_PARSER;
}
if (
!this->config ||
(this->config->enabledParsers & maddy::types::BREAKLINE_PARSER) != 0
)
{
this->breakLineParser = std::make_shared<BreakLineParser>();
}
if (
!this->config ||
(this->config->enabledParsers & maddy::types::EMPHASIZED_PARSER) != 0
)
{
this->emphasizedParser = std::make_shared<EmphasizedParser>();
}
if (
!this->config ||
(this->config->enabledParsers & maddy::types::IMAGE_PARSER) != 0
)
{
this->imageParser = std::make_shared<ImageParser>();
}
if (
!this->config ||
(this->config->enabledParsers & maddy::types::INLINE_CODE_PARSER) != 0
)
{
this->inlineCodeParser = std::make_shared<InlineCodeParser>();
}
if (
!this->config ||
(this->config->enabledParsers & maddy::types::ITALIC_PARSER) != 0
)
{
this->italicParser = std::make_shared<ItalicParser>();
}
if (
!this->config ||
(this->config->enabledParsers & maddy::types::LINK_PARSER) != 0
)
{
this->linkParser = std::make_shared<LinkParser>();
}
if (
!this->config ||
(this->config->enabledParsers & maddy::types::STRIKETHROUGH_PARSER) != 0
)
{
this->strikeThroughParser = std::make_shared<StrikeThroughParser>();
}
if (
!this->config ||
(this->config->enabledParsers & maddy::types::STRONG_PARSER) != 0
)
{
this->strongParser = std::make_shared<StrongParser>();
}
}
/**
* Parse
*
* @method
* @param {const std::stringstream&} markdown
* @param {const std::istream&} markdown
* @return {std::string} HTML
*/
std::string
Parse(std::stringstream& markdown) const
Parse(std::istream& markdown) const
{
std::string result = "";
std::shared_ptr<BlockParser> currentBlockParser = nullptr;
@@ -109,9 +193,12 @@ public:
}
private:
std::shared_ptr<ParserConfig> config;
std::shared_ptr<BreakLineParser> breakLineParser;
std::shared_ptr<EmphasizedParser> emphasizedParser;
std::shared_ptr<ImageParser> imageParser;
std::shared_ptr<InlineCodeParser> inlineCodeParser;
std::shared_ptr<ItalicParser> italicParser;
std::shared_ptr<LinkParser> linkParser;
std::shared_ptr<StrikeThroughParser> strikeThroughParser;
std::shared_ptr<StrongParser> strongParser;
@@ -121,16 +208,46 @@ private:
runLineParser(std::string& line) const
{
// Attention! ImageParser has to be before LinkParser
this->imageParser->Parse(line);
this->linkParser->Parse(line);
if (this->imageParser)
{
this->imageParser->Parse(line);
}
if (this->linkParser)
{
this->linkParser->Parse(line);
}
// Attention! StrongParser has to be before EmphasizedParser
this->strongParser->Parse(line);
this->emphasizedParser->Parse(line);
if (this->strongParser)
{
this->strongParser->Parse(line);
}
this->strikeThroughParser->Parse(line);
if (this->emphasizedParser)
{
this->emphasizedParser->Parse(line);
}
this->inlineCodeParser->Parse(line);
if (this->strikeThroughParser)
{
this->strikeThroughParser->Parse(line);
}
if (this->inlineCodeParser)
{
this->inlineCodeParser->Parse(line);
}
if (this->italicParser)
{
this->italicParser->Parse(line);
}
if (this->breakLineParser)
{
this->breakLineParser->Parse(line);
}
}
std::shared_ptr<BlockParser>
@@ -138,58 +255,128 @@ private:
{
std::shared_ptr<BlockParser> parser;
if (maddy::CodeBlockParser::IsStartingLine(line))
if (
(
!this->config ||
(this->config->enabledParsers & maddy::types::CODE_BLOCK_PARSER) != 0
) &&
maddy::CodeBlockParser::IsStartingLine(line)
)
{
parser = std::make_shared<maddy::CodeBlockParser>(
nullptr,
nullptr
);
}
else if (maddy::HeadlineParser::IsStartingLine(line))
else if (
this->config &&
(this->config->enabledParsers & maddy::types::LATEX_BLOCK_PARSER) != 0 &&
maddy::LatexBlockParser::IsStartingLine(line)
)
{
parser = std::make_shared<LatexBlockParser>(
nullptr,
nullptr
);
}
else if (
(
!this->config ||
(this->config->enabledParsers & maddy::types::HEADLINE_PARSER) != 0
) &&
maddy::HeadlineParser::IsStartingLine(line)
)
{
parser = std::make_shared<maddy::HeadlineParser>(
nullptr,
nullptr
);
}
else if (maddy::HorizontalLineParser::IsStartingLine(line))
else if (
(
!this->config ||
(this->config->enabledParsers & maddy::types::HORIZONTAL_LINE_PARSER) != 0
) &&
maddy::HorizontalLineParser::IsStartingLine(line)
)
{
parser = std::make_shared<maddy::HorizontalLineParser>(
nullptr,
nullptr
);
}
else if (maddy::QuoteParser::IsStartingLine(line))
else if (
(
!this->config ||
(this->config->enabledParsers & maddy::types::QUOTE_PARSER) != 0
) &&
maddy::QuoteParser::IsStartingLine(line)
)
{
parser = std::make_shared<maddy::QuoteParser>(
[this](std::string& line){ this->runLineParser(line); },
[this](const std::string& line){ return this->getBlockParserForLine(line); }
);
}
else if (maddy::TableParser::IsStartingLine(line))
else if (
(
!this->config ||
(this->config->enabledParsers & maddy::types::TABLE_PARSER) != 0
) &&
maddy::TableParser::IsStartingLine(line)
)
{
parser = std::make_shared<maddy::TableParser>(
[this](std::string& line){ this->runLineParser(line); },
nullptr
);
}
else if (maddy::ChecklistParser::IsStartingLine(line))
else if (
(
!this->config ||
(this->config->enabledParsers & maddy::types::CHECKLIST_PARSER) != 0
) &&
maddy::ChecklistParser::IsStartingLine(line)
)
{
parser = this->createChecklistParser();
}
else if (maddy::OrderedListParser::IsStartingLine(line))
else if (
(
!this->config ||
(this->config->enabledParsers & maddy::types::ORDERED_LIST_PARSER) != 0
) &&
maddy::OrderedListParser::IsStartingLine(line)
)
{
parser = this->createOrderedListParser();
}
else if (maddy::UnorderedListParser::IsStartingLine(line))
else if (
(
!this->config ||
(this->config->enabledParsers & maddy::types::UNORDERED_LIST_PARSER) != 0
) &&
maddy::UnorderedListParser::IsStartingLine(line)
)
{
parser = this->createUnorderedListParser();
}
else if (maddy::ParagraphParser::IsStartingLine(line))
else if (
this->config &&
(this->config->enabledParsers & maddy::types::HTML_PARSER) != 0 &&
maddy::HtmlParser::IsStartingLine(line)
)
{
parser = std::make_shared<maddy::HtmlParser>(nullptr, nullptr);
}
else if (
maddy::ParagraphParser::IsStartingLine(line)
)
{
parser = std::make_shared<maddy::ParagraphParser>(
[this](std::string& line){ this->runLineParser(line); },
nullptr
nullptr,
(!this->config || (this->config->enabledParsers & maddy::types::PARAGRAPH_PARSER) != 0)
);
}
@@ -205,7 +392,13 @@ private:
{
std::shared_ptr<BlockParser> parser;
if (maddy::ChecklistParser::IsStartingLine(line))
if (
(
!this->config ||
(this->config->enabledParsers & maddy::types::CHECKLIST_PARSER) != 0
) &&
maddy::ChecklistParser::IsStartingLine(line)
)
{
parser = this->createChecklistParser();
}
@@ -224,11 +417,23 @@ private:
{
std::shared_ptr<BlockParser> parser;
if (maddy::OrderedListParser::IsStartingLine(line))
if (
(
!this->config ||
(this->config->enabledParsers & maddy::types::ORDERED_LIST_PARSER) != 0
) &&
maddy::OrderedListParser::IsStartingLine(line)
)
{
parser = this->createOrderedListParser();
}
else if (maddy::UnorderedListParser::IsStartingLine(line))
else if (
(
!this->config ||
(this->config->enabledParsers & maddy::types::UNORDERED_LIST_PARSER) != 0
) &&
maddy::UnorderedListParser::IsStartingLine(line)
)
{
parser = this->createUnorderedListParser();
}
@@ -247,11 +452,23 @@ private:
{
std::shared_ptr<BlockParser> parser;
if (maddy::OrderedListParser::IsStartingLine(line))
if (
(
!this->config ||
(this->config->enabledParsers & maddy::types::ORDERED_LIST_PARSER) != 0
) &&
maddy::OrderedListParser::IsStartingLine(line)
)
{
parser = this->createOrderedListParser();
}
else if (maddy::UnorderedListParser::IsStartingLine(line))
else if (
(
!this->config ||
(this->config->enabledParsers & maddy::types::UNORDERED_LIST_PARSER) != 0
) &&
maddy::UnorderedListParser::IsStartingLine(line)
)
{
parser = this->createUnorderedListParser();
}

View File

@@ -0,0 +1,80 @@
/*
* This project is licensed under the MIT license. For more information see the
* LICENSE file.
*/
#pragma once
#include <stdint.h>
// -----------------------------------------------------------------------------
namespace maddy {
// -----------------------------------------------------------------------------
namespace types {
/**
* PARSER_TYPE
*
* Bitwise flags to turn on/off each parser
*/
enum PARSER_TYPE : uint32_t
{
NONE = 0,
BREAKLINE_PARSER = 0b1,
CHECKLIST_PARSER = 0b10,
CODE_BLOCK_PARSER = 0b100,
EMPHASIZED_PARSER = 0b1000,
HEADLINE_PARSER = 0b10000,
HORIZONTAL_LINE_PARSER = 0b100000,
HTML_PARSER = 0b1000000,
IMAGE_PARSER = 0b10000000,
INLINE_CODE_PARSER = 0b100000000,
ITALIC_PARSER = 0b1000000000,
LINK_PARSER = 0b10000000000,
ORDERED_LIST_PARSER = 0b100000000000,
PARAGRAPH_PARSER = 0b1000000000000,
QUOTE_PARSER = 0b10000000000000,
STRIKETHROUGH_PARSER = 0b100000000000000,
STRONG_PARSER = 0b1000000000000000,
TABLE_PARSER = 0b10000000000000000,
UNORDERED_LIST_PARSER = 0b100000000000000000,
LATEX_BLOCK_PARSER = 0b1000000000000000000,
DEFAULT = 0b0111111111110111111,
ALL = 0b1111111111111111111,
};
} // namespace types
/**
* ParserConfig
*
* @class
*/
struct ParserConfig
{
/**
* @deprecated will be removed in 1.4.0 latest
*/
bool isEmphasizedParserEnabled;
/**
* @deprecated will be removed in 1.4.0 latest
*/
bool isHTMLWrappedInParagraph;
uint32_t enabledParsers;
ParserConfig()
: isEmphasizedParserEnabled(true)
, isHTMLWrappedInParagraph(true)
, enabledParsers(maddy::types::DEFAULT)
{}
}; // class ParserConfig
// -----------------------------------------------------------------------------
} // namespace maddy

View File

@@ -54,7 +54,7 @@ public:
static bool
IsStartingLine(const std::string& line)
{
static std::regex re("^\\>.*");
static std::regex re(R"(^\>.*)");
return std::regex_match(line, re);
}
@@ -144,9 +144,9 @@ protected:
void
parseBlock(std::string& line) override
{
static std::regex lineRegexWithSpace("^\\> ");
static std::regex lineRegexWithSpace(R"(^\> )");
line = std::regex_replace(line, lineRegexWithSpace, "");
static std::regex lineRegexWithoutSpace("^\\>");
static std::regex lineRegexWithoutSpace(R"(^\>)");
line = std::regex_replace(line, lineRegexWithoutSpace, "");
if (!line.empty())

View File

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

View File

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

View File

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

View File

@@ -1,14 +0,0 @@
# This project is licensed under the MIT license. For more information see the
# LICENSE file.
cmake_minimum_required(VERSION 2.8)
set(LIBS_INCLUDE_DIRS
# -- googletest / -mock --------------------------------------------------------
${CMAKE_CURRENT_SOURCE_DIR}/gtest/googletest/include
${CMAKE_CURRENT_SOURCE_DIR}/gtest/googlemock/include
# ------------------------------------------------------------------------------
PARENT_SCOPE)
set(LIBS_SRC_FILES
PARENT_SCOPE)

Submodule libs/gtest deleted from 5490beb060

47
tests/CMakeLists.txt Normal file
View File

@@ -0,0 +1,47 @@
# This project is licensed under the MIT license. For more information see the
# LICENSE file.
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()
# ------------------------------------------------------------------------------
include(FetchContent)
FetchContent_Declare(
googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG b796f7d44681514f58a683a3a71ff17c94edb0c1 # v1.13.0
)
FetchContent_MakeAvailable(googletest)
# ------------------------------------------------------------------------------
file(GLOB_RECURSE MADDY_TESTS_FILES ${CMAKE_CURRENT_SOURCE_DIR}/maddy/*.cpp)
# ------------------------------------------------------------------------------
add_executable(
MaddyTests
${MADDY_TESTS_FILES}
${CMAKE_CURRENT_SOURCE_DIR}/main.cpp
)
target_include_directories(MaddyTests PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}
)
target_link_libraries(MaddyTests maddy gmock_main)
set_target_properties(MaddyTests PROPERTIES
CMAKE_CXX_FLAGS
"${CMAKE_CXX_FLAGS} -g -Wall -Wpedantic -Wextra -Wno-ignored-qualifiers -fno-rtti -fno-exceptions -fsanitize=address -fno-omit-frame-pointer"
)
add_test(NAME MaddyTests COMMAND MaddyTests)

View File

@@ -0,0 +1,35 @@
/*
* 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);
}

View File

@@ -59,3 +59,26 @@ TEST_F(MADDY_CODEBLOCKPARSER, ItReplacesMarkdownWithAnHtmlCodeBlock)
ASSERT_EQ(expected, outputString);
}
TEST_F(MADDY_CODEBLOCKPARSER, ItShouldUseAnythingBehindFirstBackticksAsClass)
{
std::vector<std::string> markdown = {
"```cpp"
, "some code"
, "some other code"
, "```"
};
std::string expected = "<pre class=\"cpp\"><code>\nsome code\nsome other code\n</code></pre>";
for (std::string md : markdown)
{
cbParser->AddLine(md);
}
ASSERT_TRUE(cbParser->IsFinished());
std::stringstream& output(cbParser->GetResult());
const std::string& outputString = output.str();
ASSERT_EQ(expected, outputString);
}

View File

@@ -12,7 +12,7 @@
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";
auto emphasizedParser = std::make_shared<maddy::EmphasizedParser>();
@@ -23,7 +23,7 @@ TEST(MADDY_EMPHASIZEDPARSER, ItReplacesMarkdownWithEmphasizedHTML)
TEST(MADDY_EMPHASIZEDPARSER, ItDoesNotParseInsideInlineCode)
{
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 `*bla*` `/**text*/` testing <em>it</em> out";
auto emphasizedParser = std::make_shared<maddy::EmphasizedParser>();

View File

@@ -0,0 +1,82 @@
/*
* 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);
}

View File

@@ -0,0 +1,23 @@
/*
* 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);
}

View File

@@ -0,0 +1,102 @@
/*
* This project is licensed under the MIT license. For more information see the
* LICENSE file.
*/
#include <memory>
#include "gmock/gmock.h"
#include "maddy/latexblockparser.h"
// -----------------------------------------------------------------------------
class MADDY_LATEXBLOCKPARSER : public ::testing::Test
{
protected:
std::shared_ptr<maddy::LatexBlockParser> lbParser;
void
SetUp() override
{
this->lbParser = std::make_shared<maddy::LatexBlockParser>(
nullptr,
nullptr
);
}
};
// -----------------------------------------------------------------------------
TEST_F(MADDY_LATEXBLOCKPARSER, IsStartingLineReturnsTrueWhenFacedWithTwoDollars)
{
ASSERT_TRUE(maddy::LatexBlockParser::IsStartingLine("$$"));
}
TEST_F(MADDY_LATEXBLOCKPARSER, IsFinishedReturnsFalseInTheBeginning)
{
ASSERT_FALSE(lbParser->IsFinished());
}
TEST_F(MADDY_LATEXBLOCKPARSER, ItReplacesOneLineMarkdownWithALatexBlock)
{
std::vector<std::string> markdown = {
"$$x = {-b \\pm \\sqrt{b^2-4ac} \\over 2a}.$$"
};
std::string expected = "$$x = {-b \\pm \\sqrt{b^2-4ac} \\over 2a}.$$\n";
for (std::string md : markdown)
{
lbParser->AddLine(md);
}
ASSERT_TRUE(lbParser->IsFinished());
std::stringstream& output(lbParser->GetResult());
const std::string& outputString = output.str();
ASSERT_EQ(expected, outputString);
}
TEST_F(MADDY_LATEXBLOCKPARSER, ItReplacesABlockMarkdownWithALatexBlock)
{
std::vector<std::string> markdown = {
"$$",
"x = {-b \\pm \\sqrt{b^2-4ac} \\over 2a}.",
"$$"
};
std::string expected = "$$\nx = {-b \\pm \\sqrt{b^2-4ac} \\over 2a}.\n$$\n";
for (std::string md : markdown)
{
lbParser->AddLine(md);
}
ASSERT_TRUE(lbParser->IsFinished());
std::stringstream& output(lbParser->GetResult());
const std::string& outputString = output.str();
ASSERT_EQ(expected, outputString);
}
TEST_F(MADDY_LATEXBLOCKPARSER, ItReplacesAMultilineBlockMarkdownWithALatexBlock)
{
std::vector<std::string> markdown = {
"$$",
"x = {-b \\pm \\sqrt{b^2-4ac}",
"\\over 2a}.$$"
};
std::string expected = "$$\nx = {-b \\pm \\sqrt{b^2-4ac}\n\\over 2a}.$$\n";
for (std::string md : markdown)
{
lbParser->AddLine(md);
}
ASSERT_TRUE(lbParser->IsFinished());
std::stringstream& output(lbParser->GetResult());
const std::string& outputString = output.str();
ASSERT_EQ(expected, outputString);
}

View File

@@ -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);
}

View File

@@ -20,7 +20,8 @@ protected:
{
this->pParser = std::make_shared<maddy::ParagraphParser>(
nullptr,
nullptr
nullptr,
true
);
}
};

View File

@@ -19,3 +19,48 @@ TEST(MADDY_PARSER, ItShouldParse)
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);
}
TEST(MADDY_PARSER, ItShouldParseWithBitwiseConfig)
{
auto config = std::make_shared<maddy::ParserConfig>();
config->enabledParsers &= ~maddy::types::EMPHASIZED_PARSER;
config->enabledParsers |= maddy::types::HTML_PARSER;
auto parser = std::make_shared<maddy::Parser>(config);
std::stringstream markdown(testMarkdown);
const std::string output = parser->Parse(markdown);
ASSERT_EQ(testHtml2, output);
}
TEST(MADDY_PARSER, ItShouldParseWithSmallConfig)
{
auto config = std::make_shared<maddy::ParserConfig>();
config->enabledParsers = maddy::types::EMPHASIZED_PARSER |
maddy::types::STRONG_PARSER;
auto parser = std::make_shared<maddy::Parser>(config);
std::stringstream markdown(testMarkdown);
const std::string output = parser->Parse(markdown);
ASSERT_EQ(testHtml3, output);
}

View File

@@ -11,9 +11,9 @@ const std::string testMarkdown = "# This is a test\n\
This should result in a praragraph\n\
it's that simple.\n\
\n\
* an unordered list\n\
* an *unordered* list\n\
* with some **hierarchy**\n\
1. and an *ordered*\n\
1. and an _ordered_\n\
* list\n\
* directly\n\
* inside\n\
@@ -42,6 +42,8 @@ And well - let's see how an image would be shown:\n\
\n\
---\n\
\n\
<a name=\"to top\"></a>\n\
\n\
### and more headlines\n\
\n\
- [ ] how\n\
@@ -67,4 +69,6 @@ foot a|foot b|foot c\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 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 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 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>";
const std::string testHtml3 = "# This is a test <br/>This should result in a praragraph it's that simple. <br/>* an *unordered* list * with some <strong>hierarchy</strong> 1. and an <em>ordered</em> * list * directly * inside <br/>``` var c = 'blub'; ``` <br/>> A Quote > > With some ~~text~~ blocks inside > > * even a list > * should be > * possible > <br/>And well `inline code` should also work. <br/>## Another Headline <br/>And not to forget [link to progsource](http://progsource.de) should work. And well - let's see how an image would be shown: <br/>![an image](http://progsource.de/img/progsource.png) <br/>--- <br/><a name=\"to top\"></a> <br/>### and more headlines <br/>- [ ] how - [ ] about - [ ] a - [x] nice - [x] check - [ ] list <br/>#### even a table <br/>|table> Left header|middle header|last header - | - | - cell 1|cell <strong>2</strong>|cell 3 cell 4|cell 5|cell 6 - | - | - foot a|foot b|foot c |<table <br/>##### h5 ###### h6 <br/>";

View File

@@ -12,33 +12,87 @@
TEST(MADDY_STRONGPARSER, ItReplacesMarkdownWithStrongHTML)
{
std::string text = "some text **bla** text testing **it** out";
std::string expected = "some text <strong>bla</strong> text testing <strong>it</strong> out";
struct testIt
{
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>();
strongParser->Parse(text);
ASSERT_EQ(expected, text);
for (auto& test : tests)
{
strongParser->Parse(test.text);
ASSERT_EQ(test.expected, test.text);
}
}
TEST(MADDY_STRONGPARSER, ItReplacesEmphasizedMarkdownNotWithStrongHTML)
{
std::string text = "some text *bla* text testing **it** out";
std::string expected = "some text *bla* text testing <strong>it</strong> out";
struct testIt
{
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>();
strongParser->Parse(text);
ASSERT_EQ(expected, text);
for (auto& test : tests)
{
strongParser->Parse(test.text);
ASSERT_EQ(test.expected, test.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";
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>();
strongParser->Parse(text);
ASSERT_EQ(expected, text);
for (auto& test : tests)
{
strongParser->Parse(test.text);
ASSERT_EQ(test.expected, test.text);
}
}

View File

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