add gui.escape_markup

This commit is contained in:
MihailRis
2024-12-06 20:25:21 +03:00
parent 16698cc68b
commit 467b4ad043
5 changed files with 56 additions and 3 deletions
+1 -2
View File
@@ -1,7 +1,5 @@
#include "markdown.hpp"
#include <sstream>
#include "graphics/core/Font.hpp"
using namespace markdown;
@@ -66,6 +64,7 @@ Result<CharT> process_markdown(
pos++;
continue;
}
pos--;
}
} else if (first == '*') {
if (pos + 1 < source.size() && source[pos+1] == '*') {
+21
View File
@@ -2,6 +2,7 @@
#include <string>
#include <memory>
#include <sstream>
struct FontStylesScheme;
@@ -19,4 +20,24 @@ namespace markdown {
Result<char> process(std::string_view source, bool eraseMarkdown);
Result<wchar_t> process(std::wstring_view source, bool eraseMarkdown);
template <typename CharT>
inline std::basic_string<CharT> escape(std::string_view source) {
std::basic_stringstream<CharT> ss;
int pos = 0;
while (pos < source.size()) {
CharT first = source[pos];
if (first == '\\' && pos + 1 < source.size()) {
CharT second = source[++pos];
ss << first << second;
pos++;
continue;
} else if (first == '*' || first == '~' || first == '_') {
ss << '\\';
}
ss << first;
pos++;
}
return ss.str();
}
}