comparison 3rdparty/maddy/linkparser.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 * LinkParser
22 *
23 * Has to be used after the `ImageParser`.
24 *
25 * @class
26 */
27 class LinkParser : public LineParser
28 {
29 public:
30 /**
31 * Parse
32 *
33 * From Markdown: `[text](http://example.com)`
34 *
35 * To HTML: `<a href="http://example.com">text</a>`
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::regex re("\\[([^\\]]*)\\]\\(([^\\]]*)\\)");
45 static std::string replacement = "<a href=\"$2\">$1</a>";
46
47 line = std::regex_replace(line, re, replacement);
48 }
49 }; // class LinkParser
50
51 // -----------------------------------------------------------------------------
52
53 } // namespace maddy