diff --git a/legacy/evas/ChangeLog b/legacy/evas/ChangeLog
index fc11c96f18..44fac01f2d 100644
--- a/legacy/evas/ChangeLog
+++ b/legacy/evas/ChangeLog
@@ -566,3 +566,4 @@
* Textblock: Made "br" and "tab" default tags for newline and tab.
* Textblock: Added "b" and "i" as default tags that can be overridden
by style, and added the infra to support this.
+ * Textblock: Added evas_textblock_text_utf8_to_markup
diff --git a/legacy/evas/src/lib/Evas.h b/legacy/evas/src/lib/Evas.h
index 544fa3d264..de1cb78d7e 100644
--- a/legacy/evas/src/lib/Evas.h
+++ b/legacy/evas/src/lib/Evas.h
@@ -8120,11 +8120,25 @@ EAPI const char *evas_textblock_escape_string_range_get(const c
* the actual char and etc.
*
* @param obj the textblock object to work with.
- * @param text the markup text
+ * @param text the markup text (if NULL, return NULL)
* @return an allocated plain text version of the markup
* @since 1.2.0
*/
-EAPI char *evas_textblock_text_markup_to_utf8(const Evas_Object *obj, const char *text) EINA_WARN_UNUSED_RESULT EINA_MALLOC EINA_ARG_NONNULL(1, 2);
+EAPI char *evas_textblock_text_markup_to_utf8(const Evas_Object *obj, const char *text) EINA_WARN_UNUSED_RESULT EINA_MALLOC EINA_ARG_NONNULL(1);
+
+/**
+ * Return the markup version of the plain text.
+ *
+ * Replaces \n ->
\t -> and etc. Generally needed before you pass
+ * plain text to be set in a textblock.
+ *
+ * @param obj the textblock object to work with (if NULL, it just does the
+ * default behaviour, i.e with no extra object information).
+ * @param text the markup text (if NULL, return NULL)
+ * @return an allocated plain text version of the markup
+ * @since 1.2.0
+ */
+EAPI char *evas_textblock_text_utf8_to_markup(const Evas_Object *obj, const char *text) EINA_WARN_UNUSED_RESULT EINA_MALLOC;
/**
* Creates a new textblock style.
diff --git a/legacy/evas/src/lib/canvas/evas_object_textblock.c b/legacy/evas/src/lib/canvas/evas_object_textblock.c
index b14af7a934..60254b7292 100644
--- a/legacy/evas/src/lib/canvas/evas_object_textblock.c
+++ b/legacy/evas/src/lib/canvas/evas_object_textblock.c
@@ -5123,6 +5123,8 @@ evas_object_textblock_text_markup_get(const Evas_Object *obj)
EAPI char *
evas_textblock_text_markup_to_utf8(const Evas_Object *obj, const char *text)
{
+ if (!text) return NULL;
+
/* FIXME: Can be done better, this is the least redundant way of doing it,
* but by far the slowest, when the time comes, this should be
* re-implemented. */
@@ -5150,6 +5152,50 @@ evas_textblock_text_markup_to_utf8(const Evas_Object *obj, const char *text)
return ret;
}
+EAPI char *
+evas_textblock_text_utf8_to_markup(const Evas_Object *obj, const char *text)
+{
+ Eina_Strbuf *sbuf;
+ char *str = NULL;
+ int ch, pos = 0, pos2 = 0;
+
+ (void) obj;
+
+ if (!text) return NULL;
+
+ sbuf = eina_strbuf_new();
+
+ for (;;)
+ {
+ pos = pos2;
+ pos2 = evas_string_char_next_get(text, pos2, &ch);
+ if ((ch <= 0) || (pos2 <= 0)) break;
+
+ if (ch == '\n')
+ eina_strbuf_append(sbuf, "
");
+ else if (ch == '\t')
+ eina_strbuf_append(sbuf, "");
+ else if (ch == '<')
+ eina_strbuf_append(sbuf, "<");
+ else if (ch == '>')
+ eina_strbuf_append(sbuf, ">");
+ else if (ch == '&')
+ eina_strbuf_append(sbuf, "&");
+ else if (ch == 0x2029) /* PS */
+ eina_strbuf_append(sbuf, "");
+ else if (ch == 0xFFFC ) /* Object Replacement Char */
+ eina_strbuf_append(sbuf, "");
+ else
+ {
+ eina_strbuf_append_length(sbuf, text + pos, pos2 - pos);
+ }
+ }
+ str = eina_strbuf_string_steal(sbuf);
+ eina_strbuf_free(sbuf);
+ return str;
+
+}
+
/* cursors */
/**