From b873a40cedb31980d35c691a8aff94f4ef3d9e6c Mon Sep 17 00:00:00 2001 From: jasmaa Date: Sat, 14 May 2022 18:30:45 -0400 Subject: [PATCH] Support square brackets in link text --- imgui_markdown.h | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/imgui_markdown.h b/imgui_markdown.h index d3f8198..619da08 100644 --- a/imgui_markdown.h +++ b/imgui_markdown.h @@ -441,6 +441,7 @@ namespace ImGui TextBlock text; TextBlock url; bool isImage = false; + int num_square_brackets_open = 0; int num_brackets_open = 0; }; @@ -602,6 +603,7 @@ namespace ImGui { link.state = Link::HAS_SQUARE_BRACKET_OPEN; link.text.start = i + 1; + link.num_square_brackets_open = 1; if( i > 0 && markdown_[i - 1] == '!' ) { link.isImage = true; @@ -609,7 +611,15 @@ namespace ImGui } break; case Link::HAS_SQUARE_BRACKET_OPEN: - if( c == ']' ) + if( c == '[' ) + { + ++link.num_square_brackets_open; + } + else if( c == ']' ) + { + --link.num_square_brackets_open; + } + if( link.num_square_brackets_open == 0 ) { link.state = Link::HAS_SQUARE_BRACKETS; link.text.stop = i;