From f212fa5936175b57671d653f7325908add707260 Mon Sep 17 00:00:00 2001 From: eidheim Date: Mon, 23 Jan 2023 10:53:31 +0100 Subject: [PATCH] Improved newline support for markdown annotated tooltips: two spaces followed by newline will now produce newline within a paragraph --- src/tooltips.cpp | 5 +++++ tests/tooltips_test.cpp | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/src/tooltips.cpp b/src/tooltips.cpp index 8186ff2..ce7dec2 100644 --- a/src/tooltips.cpp +++ b/src/tooltips.cpp @@ -741,6 +741,11 @@ void Tooltip::insert_markdown(const std::string &input) { i += 5; continue; } + else if(starts_with(input, i, " \n")) { + partial += '\n'; + i += 2; + continue; + } else if(insert_code() || insert_emphasis() || insert_strikethrough() || insert_link()) continue; if(input[i] == '\n' && i + 1 < to) diff --git a/tests/tooltips_test.cpp b/tests/tooltips_test.cpp index 6a04118..cab3618 100644 --- a/tests/tooltips_test.cpp +++ b/tests/tooltips_test.cpp @@ -65,6 +65,10 @@ int main() { auto tooltip = get_markdown_tooltip("test  test"); g_assert(tooltip->buffer->get_text() == "test test"); } + { + auto tooltip = get_markdown_tooltip("test \ntest"); + g_assert(tooltip->buffer->get_text() == "test\ntest"); + } { auto tooltip = get_markdown_tooltip("test\n\n---\ntest"); g_assert(tooltip->buffer->get_text() == "test\n\n---\ntest");