diff --git a/src/render/text/element.cpp b/src/render/text/element.cpp
index 3a90313e..8cde8d88 100644
--- a/src/render/text/element.cpp
+++ b/src/render/text/element.cpp
@@ -37,7 +37,7 @@ struct TextElementsFromString {
int bold = 0, italic = 0, symbol = 0;
int soft = 0, kwpph = 0, param = 0, line = 0, soft_line = 0;
int code = 0, code_kw = 0, code_string = 0, param_ref = 0;
- int param_id = 0;
+ int param_id = 0, li = 0;
vector colors;
vector sizes;
vector fonts;
@@ -75,29 +75,31 @@ private:
// a (formatting) tag
size_t tag_start = pos;
pos = skip_tag(text, tag_start);
- if (is_substr(text, tag_start, _( ":"), tag_start);
if (colon < pos - 1 && text.GetChar(colon) == _(':')) {
auto c = parse_color(text.substr(colon+1, pos-colon-2));
@@ -108,18 +110,18 @@ private:
colors.push_back(style.font.color);
}
}
- } else if (is_substr(text, tag_start, _(":"), tag_start);
if (colon < pos - 1 && text.GetChar(colon) == _(':')) {
fonts.push_back(text.substr(colon+1, pos-colon-2));
}
- } else if (is_substr(text, tag_start, _(":"), tag_start);
if (colon < pos - 1 && text.GetChar(colon) == _(':')) {
double size = style.font.size;
@@ -127,10 +129,10 @@ private:
v.ToDouble(&size);
sizes.push_back(size);
}
- } else if (is_substr(text, tag_start, _("
if (pos != String::npos) {
@@ -142,10 +144,10 @@ private:
}
param_ref += 1;
}
- else if (is_substr(text, tag_start, _("children, text, pos, end_tag);
elements.push_back(e);
pos = skip_tag(text, end_tag);
- } else if (is_substr(text, tag_start, _( " e = make_intrusive(pos, end_tag);
fromString(e->children, text, pos, end_tag);
elements.push_back(e);
pos = skip_tag(text, end_tag);
- } else if (is_substr(text, tag_start, _(" outside tag"));
+ }
paragraphs.back().margin_end_char = pos;
- } else if (is_substr(text, tag_start, _(":"), tag_start);
if (colon < pos - 1 && text.GetChar(colon) == _(':')) {
size_t colon2 = text.find_first_of(_(">:"), colon + 1);
@@ -188,16 +193,16 @@ private:
paragraphs.back().margin_right = m.right;
paragraphs.back().margin_top = m.top;
}
- } else if (is_substr(text, tag_start, _(":"), tag_start);
if (colon < pos - 1 && text.GetChar(colon) == _(':')) {
Alignment align = alignment_from_string(text.substr(colon+1, pos-colon-2));
aligns.push_back(align);
paragraphs.back().alignment = align;
}
- } else if (is_substr(text, tag_start, _(" as , only , and are considered
+bool is_tag_end_char(Char c) {
+ return c == '>' || c == '-' || c == ':' || c == ' ';
+}
+
+bool is_tag(const String& str, size_t pos, const String& tag) {
+ return is_substr(str, pos, tag) && pos+tag.size() < str.size() && is_tag_end_char(str[pos+tag.size()]);
+}
+
[[nodiscard]] size_t in_tag(const String& str, const String& tag, size_t start, size_t end) {
size_t last_start = String::npos;
size_t size = str.size();
@@ -261,10 +270,10 @@ String::const_iterator find_close_tag(String::const_iterator tag, String::const_
for (size_t pos = 0 ; pos < end ; ) {
Char c = str.GetChar(pos);
if (c == _('<')) {
- if (is_substr(str, pos + 1, static_cast(tag.c_str())+1)) {
+ if (is_substr(str, pos + 1, static_cast(tag.c_str())+1) && pos+tag.size() < str.size() && is_tag_end_char(str[pos+tag.size()])) {
if (pos < start) last_start = pos;
++taglevel;
- } else if (pos + 2 < size && str.GetChar(pos+1) == _('/') && is_substr(str, pos + 2, static_cast(tag.c_str())+1)) {
+ } else if (pos + 2 < size && str.GetChar(pos+1) == _('/') && is_substr(str, pos + 2, static_cast(tag.c_str())+1) && pos+1+tag.size() < str.size() && is_tag_end_char(str[pos+1+tag.size()])) {
--taglevel; // close tag
}
pos = skip_tag(str,pos);
diff --git a/src/util/tagged_string.hpp b/src/util/tagged_string.hpp
index bf52e7e3..95b414d3 100644
--- a/src/util/tagged_string.hpp
+++ b/src/util/tagged_string.hpp
@@ -72,6 +72,10 @@ String fix_old_tags(const String&);
/** If not found returns String::npos */
[[nodiscard]] size_t last_start_tag_before(const String& str, const String& tag, size_t start);
+/// Does a string contain a tag at the given location?
+/** Only matches if the tag ends one of ">-: " */
+[[nodiscard]] bool is_tag(const String& str, size_t pos, const String& tag);
+
/// Is the given range entirely contained in a given tagged block?
/** If so: return the start position of that tag, otherwise returns String::npos
* A tagged block is everything between ...