comparison 3rdparty/maddy/strongparser.h @ 0:a4671277546c tip

created the repository for the thymian project
author ferencd
date Tue, 17 Aug 2021 11:19:54 +0200
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:a4671277546c
1 /*
2 * This project is licensed under the MIT license. For more information see the
3 * LICENSE file.
4 */
5 #pragma once
6
7 // -----------------------------------------------------------------------------
8
9 #include <string>
10 #include <regex>
11
12 #include "maddy/lineparser.h"
13
14 // -----------------------------------------------------------------------------
15
16 namespace maddy {
17
18 // -----------------------------------------------------------------------------
19
20 /**
21 * StrongParser
22 *
23 * Has to be used before the `EmphasizedParser`.
24 *
25 * @class
26 */
27 class StrongParser : public LineParser
28 {
29 public:
30 /**
31 * Parse
32 *
33 * From Markdown: `text **text** __text__`
34 *
35 * To HTML: `text <strong>text</strong> <strong>text</strong>`
36 *
37 * @method
38 * @param {std::string&} line The line to interpret
39 * @return {void}
40 */
41 void
42 Parse(std::string& line) override
43 {
44 static std::vector<std::regex> res
45 {
46 std::regex{"(?!.*`.*|.*<code>.*)\\*\\*(?!.*`.*|.*<\\/code>.*)([^\\*\\*]*)\\*\\*(?!.*`.*|.*<\\/code>.*)"},
47 std::regex{"(?!.*`.*|.*<code>.*)__(?!.*`.*|.*<\\/code>.*)([^__]*)__(?!.*`.*|.*<\\/code>.*)"}
48 };
49 static std::string replacement = "<strong>$1</strong>";
50 for (const auto& re : res)
51 {
52 line = std::regex_replace(line, re, replacement);
53 }
54 }
55 }; // class StrongParser
56
57 // -----------------------------------------------------------------------------
58
59 } // namespace maddy