Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conditionally add break after multiline code block #208

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion libdiscord.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -1634,9 +1646,14 @@ discord_convert_markdown(const gchar *html)
out = g_string_append(out, "<br/><span style='font-family: monospace; white-space: pre'>");
} else {
out = g_string_append(out, "</span>");
i += 2;

/* Ensure no text on same line after code. */
if (discord_has_nonspace_before_newline(html, i + 3)) {
out = g_string_append(out, "<br/>");
}
}

i += 2;
s_codeblock = !s_codeblock;
} else {
HTML_TOGGLE_OUT(s_codebit, "<span style='font-family: monospace; white-space: pre'>", "</span>");
Expand Down