Fixed some bugs in pango renderer

This commit is contained in:
Markus Koch 2017-03-15 18:20:47 +01:00
parent 07baf34a71
commit 684b1a4687

View File

@ -6,50 +6,68 @@ gchar *md_pango_render(gchar *markup, gint length)
gchar *str2;
GRegex *regex;
regex = g_regex_new("\\>", 0, 0, NULL);
str = g_regex_replace(regex, markup, -1, 0, ">", 0, NULL);
str = markup;
regex = g_regex_new("\\&", 0, 0, NULL);
str2 = g_regex_replace(regex, str, -1, 0, "&", 0, NULL);
g_regex_unref(regex);
// Must not g_free(str)
str = str2;
regex = g_regex_new("\\>", 0, 0, NULL);
str2 = g_regex_replace(regex, str, -1, 0, ">", 0, NULL);
g_regex_unref(regex);
g_free(str);
str = str2;
regex = g_regex_new("\\<", 0, 0, NULL);
str2 = g_regex_replace(regex, str, -1, 0, "&lt;", 0, NULL);
g_regex_unref(regex);
g_free(str);
str = str2;
regex = g_regex_new("\\*{2}([^\\*]*)\\*{2}", 0, 0, NULL);
str = g_regex_replace(regex, str2, -1, 0, "<b>\\1</b>", 0, NULL);
str2 = g_regex_replace(regex, str, -1, 0, "<b>\\1</b>", 0, NULL);
g_regex_unref(regex);
g_free(str2);
g_free(str);
str = str2;
regex = g_regex_new("\\*([^\\*]*)\\*", 0, 0, NULL);
str2 = g_regex_replace(regex, str, -1, 0, "<i>\\1</i>", 0, NULL);
g_free(str);
str = str2;
/* TODO: This also matches inline # */
regex = g_regex_new("\\#{4}(.*)", 0, 0, NULL);
str2 = g_regex_replace(regex, str, -1, 0, "<span font-size=\"large\">\\1</span>", 0, NULL);
g_regex_unref(regex);
g_free(str);
regex = g_regex_new("\\#{4}(.*)", 0, 0, NULL);
str = g_regex_replace(regex, str2, -1, 0, "<span font-size=\"large\">\\1</span>", 0, NULL);
g_regex_unref(regex);
g_free(str2);
str = str2;
regex = g_regex_new("\\#{3}(.*)", 0, 0, NULL);
str2 = g_regex_replace(regex, str, -1, 0, "<span font-size=\"x-large\">\\1</span>", 0, NULL);
g_regex_unref(regex);
g_free(str);
str = str2;
regex = g_regex_new("\\#{2}(.*)", 0, 0, NULL);
str = g_regex_replace(regex, str2, -1, 0, "<span font-size=\"xx-large\">\\1</span>", 0, NULL);
str2 = g_regex_replace(regex, str, -1, 0, "<span font-size=\"xx-large\">\\1</span>", 0, NULL);
g_regex_unref(regex);
g_free(str2);
g_free(str);
str = str2;
regex = g_regex_new("\\#{1}(.*)", 0, 0, NULL);
str2 = g_regex_replace(regex, str, -1, 0, "<span font_weight=\"bold\" font-size=\"xx-large\">\\1</span>",
0, NULL);
g_regex_unref(regex);
g_free(str);
str = str2;
regex = g_regex_new("\\!\\[([^\\]]*)\\]\\(([^\\)]*)\\)", 0, 0, NULL);
str = g_regex_replace(regex, str2, -1, 0, "-- Image \\1 (\\2) --", 0, NULL);
str2 = g_regex_replace(regex, str2, -1, 0, "-- Image \\1 (\\2) --", 0, NULL);
g_regex_unref(regex);
g_free(str2);
g_free(str);
str = str2;
return str;
}