1
0
duplikat dari https://github.com/quitesimpleorg/qsmaddy.git synced 2025-04-17 01:49:02 +02:00

Compare commits

...

7 Melakukan

Penulis SHA1 Pesan Tanggal
167ce3943d Update README 2021-04-18 13:10:50 +02:00
e0e0db80d5 Linkparser: Use callbacks, so app can influence how the HTML gets rendered exactly
In particular, this allows making dynamic decisions: Some links may
for example require a different CSS class or so, therefore a static
hardcoded template is not enough for those cases.
2021-04-18 13:10:50 +02:00
8ac353a9d7 Parser: Add setters to allow influencing the parsing with custom implementations 2021-04-18 12:55:30 +02:00
2f14336692 italicparser: Parse(): Add static keyword to regex
In line with the other parsers, add the static keyword to the
regex.
2021-04-18 11:40:15 +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
7 mengubah file dengan 196 tambahan dan 83 penghapusan

67
CHANGELOG.md Normal file
Melihat File

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

26
CONTRIBUTING.md Normal file
Melihat 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.

Melihat File

@ -1,80 +1,3 @@
# maddy
# qsmaddy
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![Version: 1.1.2](https://img.shields.io/badge/Version-1.1.2-brightgreen.svg)](https://semver.org/)
[![Travis Build Status](https://travis-ci.org/progsource/maddy.svg?branch=master)](https://travis-ci.org/progsource/maddy)
[![Appveyor Build Status](https://ci.appveyor.com/api/projects/status/04m0lg27kigv1pg8/branch/master?svg=true)](https://ci.appveyor.com/project/progsource/maddy/branch/master)
maddy is a C++ Markdown to HTML **header-only** parser library.
## Supported OS
It actually should work on any OS, that supports the C++14 standard library.
It is tested to work on:
* Linux (gcc)
* OSX (clang)
* Windows (Visual Studio 2017)
## 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).
## How to 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("");
// config is optional
std::shared_ptr<maddy::ParserConfig> config = std::make_shared<maddy::ParserConfig>();
config->isEmphasizedParserEnabled = true; // default
config->isHTMLWrappedInParagraph = true; // default
std::shared_ptr<maddy::Parser> parser = std::make_shared<maddy::Parser>(config);
std::string htmlOutput = parser->Parse(markdownInput);
```
## How to run the tests
*(tested on Linux with
[git](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git) and
[cmake](https://cmake.org/install/) installed)*
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 ..
make
make test # or run the executable in ../build/MaddyTests
```
## How to contribute
There are different possibilities:
* [Create a GitHub issue](https://github.com/progsource/maddy/issues/new)
* Create a pull request with an own branch (don't forget to put yourself in the
AUTHORS file)
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)

Melihat File

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

Melihat File

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

Melihat File

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

Melihat File

@ -116,6 +116,54 @@ public:
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:
std::shared_ptr<ParserConfig> config;
std::shared_ptr<BreakLineParser> breakLineParser;