diff --git a/libdiscord.c b/libdiscord.c index 1b05900..d17944d 100644 --- a/libdiscord.c +++ b/libdiscord.c @@ -1579,6 +1579,18 @@ discord_underscore_match(const gchar *html, int i) return FALSE; } +static gboolean +discord_has_nonspace_before_newline(const gchar *html, int i) +{ + while (html[i] && html[i] != '\n') { + if (!g_ascii_isspace(html[i++])) { + return TRUE; + } + } + + return FALSE; +} + static gchar * discord_convert_markdown(const gchar *html) { @@ -1634,9 +1646,14 @@ discord_convert_markdown(const gchar *html) out = g_string_append(out, "
"); } else { out = g_string_append(out, ""); - i += 2; + + /* Ensure no text on same line after code. */ + if (discord_has_nonspace_before_newline(html, i + 3)) { + out = g_string_append(out, "
"); + } } + i += 2; s_codeblock = !s_codeblock; } else { HTML_TOGGLE_OUT(s_codebit, "", "");