From 4f673fc081f6e5b0d0b6f322fc500fab26fb0336 Mon Sep 17 00:00:00 2001 From: Olaf Wintermann Date: Tue, 10 Mar 2026 20:52:06 +0100 Subject: [PATCH] fix markdown link text generation --- application/gtk-text.c | 5 +++-- application/tests/test-editor.c | 6 ++++++ application/tests/test-editor.h | 1 + application/tests/testmain.c | 1 + 4 files changed, 11 insertions(+), 2 deletions(-) diff --git a/application/gtk-text.c b/application/gtk-text.c index b747251..003822c 100644 --- a/application/gtk-text.c +++ b/application/gtk-text.c @@ -1263,9 +1263,10 @@ cxmutstr editor_get_markdown(UiText *text, const CxAllocator *a) { } if(name[0] == '_') { GtkTextTag *tag = entry->value; - link = g_object_get_data(G_OBJECT(tag), "link"); - if(link) { + TextLink *islink = g_object_get_data(G_OBJECT(tag), "link"); + if(islink) { cxBufferPut(&out, '['); + link = islink; } } } diff --git a/application/tests/test-editor.c b/application/tests/test-editor.c index 04e4c54..0baadd3 100644 --- a/application/tests/test-editor.c +++ b/application/tests/test-editor.c @@ -488,3 +488,9 @@ CX_TEST(test_editor_load_markdown_span1) { CX_TEST_CALL_SUBROUTINE(test_editor_markdown_load_get, cx_mutstr("Text **bold** and _underline_\n\nText *italic*\n")); } } + +CX_TEST(test_editor_load_markdown_link) { + CX_TEST_DO { + CX_TEST_CALL_SUBROUTINE(test_editor_markdown_load_get, cx_mutstr("Link [link1](https://example.com/link1)\n[link2][1]\n\n[1]: https://example.com/link2")); + } +} diff --git a/application/tests/test-editor.h b/application/tests/test-editor.h index 5be3653..ba3ba13 100644 --- a/application/tests/test-editor.h +++ b/application/tests/test-editor.h @@ -46,6 +46,7 @@ CX_TEST(test_editor_load_markdown_para1); CX_TEST(test_editor_load_markdown_heading_para); CX_TEST(test_editor_load_markdown_list1); CX_TEST(test_editor_load_markdown_span1); +CX_TEST(test_editor_load_markdown_link); #ifdef __cplusplus } diff --git a/application/tests/testmain.c b/application/tests/testmain.c index 67cfd03..13cec75 100644 --- a/application/tests/testmain.c +++ b/application/tests/testmain.c @@ -87,6 +87,7 @@ int main(int argc, char **argv) { cx_test_register(suite, test_editor_load_markdown_heading_para); cx_test_register(suite, test_editor_load_markdown_list1); cx_test_register(suite, test_editor_load_markdown_span1); + cx_test_register(suite, test_editor_load_markdown_link); cx_test_register(suite, test_text_search_strcasestr); cx_test_register(suite, test_text_search_cs); -- 2.47.3