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