comparison 3rdparty/maddy/italicparser.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 * ItalicParser
22 *
23 * @class
24 */
25 class ItalicParser : public LineParser
26 {
27 public:
28 /**
29 * Parse
30 *
31 * From Markdown: `text *text*`
32 *
33 * To HTML: `text <i>text</i>`
34 *
35 * @method
36 * @param {std::string&} line The line to interpret
37 * @return {void}
38 */
39 void
40 Parse(std::string& line) override
41 {
42 std::regex re("(?!.*`.*|.*<code>.*)\\*(?!.*`.*|.*<\\/code>.*)([^\\*]*)\\*(?!.*`.*|.*<\\/code>.*)");
43 static std::string replacement = "<i>$1</i>";
44 line = std::regex_replace(line, re, replacement);
45 }
46 }; // class ItalicParser
47
48 // -----------------------------------------------------------------------------
49
50 } // namespace maddy