I am making a C++ wxWidgets application, I am making a markdown styled wxrichtextbox, and so far I have everything set, but there is one problem I need you to help me fix, currently the entire text box is parsed and styled as a markdown, so I want to remove or avoid the markdown codeblock, which means three backsticks with markdown as a language should be removed and not shown. I amanage to add an if language == "markdown" don't do anything but it ends up not writing the text in a markdown format.

here is my current code snippet, commenting out the unnecesary parts:

void Markdown::WriteText(wxRichTextCtrl* richTextChatBox, const wxString& message, const wxTextAttr& style)
{
    richTextChatBox->BeginStyle(style);

    wxString formattedMessage = Markdown::FormatMessage(message);

    wxString::size_type pos = 0;

    while (pos < formattedMessage.Length() && pos != wxString::npos)
    {
        wxString::size_type startBoldItalic = formattedMessage.find(BOLD_ITALIC_MARKER, pos);
        wxString::size_type startBold = formattedMessage.find(BOLD_MARKER, pos);
        wxString::size_type startItalic = formattedMessage.find(ITALIC_MARKER, pos);
        //...
        wxString::size_type startCodeBlock = formattedMessage.find(CODE_BLOCK_MARKER, pos);

        std::vector<std::pair<wxString::size_type, int>> markers = {
            { startBoldItalic, 3 },
            { startBold, 2 },
            { startItalic, 1 },
            //...
            { startCodeBlock, 3 },
        };

        // Ignore inline code if a code block is found earlier
        if (startCodeBlock != wxString::npos && (startCode == wxString::npos || startCodeBlock <= startCode))
        {
            startCode = wxString::npos;
        }

        // Find the earliest marker
        auto earliestIt = std::min_element(markers.begin(), markers.end(), [](const auto& lhs, const auto& rhs){
            return (lhs.first != wxString::npos && (rhs.first == wxString::npos || lhs.first < rhs.first));
        });

        if (earliestIt->first != wxString::npos)
        {
            wxString::size_type markerPos = earliestIt->first;
            int markerLength = earliestIt->second;

            wxString::size_type endMarker;

            if (startBoldItalic == markerPos)
            {
                endMarker = formattedMessage.find(BOLD_ITALIC_MARKER, markerPos + markerLength);
            }
            else if (startBold == markerPos)
            {
                endMarker = formattedMessage.find(BOLD_MARKER, markerPos + markerLength);
            }
            else if (startItalic == markerPos)
            {
                endMarker = formattedMessage.find(ITALIC_MARKER, markerPos + markerLength);
            }
            //...
            else if (startCodeBlock == markerPos)  // here is the problematic part!
            {
                wxString::size_type startLang = markerPos + 3;
                wxString::size_type endLang = formattedMessage.find('\n', startLang);
                wxString language = formattedMessage.substr(startLang, endLang - startLang).Trim().MakeLower();
                wxString::size_type codeStart = endLang + 1;
                endMarker = formattedMessage.find("```", codeStart);

                if (endMarker != wxString::npos)
                {
                    wxString codeBlockText = formattedMessage.substr(codeStart, endMarker - codeStart);
                    wxString beforeMarker = formattedMessage.substr(pos, markerPos - pos);

                    richTextChatBox->WriteText(beforeMarker);
                    HighlightSyntax(richTextChatBox, codeBlockText, language, style);

                    pos = endMarker + 3;
                    continue;
                }
                else
                {
                    richTextChatBox->WriteText(formattedMessage.substr(pos));
                    pos = wxString::npos;
                    continue;
                }
            }

            if (endMarker != wxString::npos)
            {
                wxString beforeMarker = formattedMessage.substr(pos, markerPos - pos);
                richTextChatBox->WriteText(beforeMarker);
                wxString styledText = formattedMessage.substr(markerPos + markerLength, endMarker - markerPos - markerLength);

                if (startBoldItalic == markerPos)
                {
                    wxRichTextAttr textAttr = style;
                    SetBoldStyle(textAttr);
                    SetItalicStyle(textAttr);
                    richTextChatBox->BeginStyle(textAttr);
                    richTextChatBox->WriteText(styledText);
                    richTextChatBox->EndStyle();
                }
                else if (startBold == markerPos)
                {
                    wxRichTextAttr textAttr = style;
                    SetBoldStyle(textAttr);
                    richTextChatBox->BeginStyle(textAttr);
                    richTextChatBox->WriteText(styledText);
                    richTextChatBox->EndStyle();
                }
                else if (startItalic == markerPos)
                {
                    wxRichTextAttr textAttr = style;
                    SetItalicStyle(textAttr);
                    richTextChatBox->BeginStyle(textAttr);
                    richTextChatBox->WriteText(styledText);
                    richTextChatBox->EndStyle();
                }
                //...

                pos = endMarker + markerLength;
            }
            else
            {
                richTextChatBox->WriteText(formattedMessage.substr(pos));
                pos = wxString::npos;
            }
        }
        else
        {
            richTextChatBox->WriteText(formattedMessage.substr(pos));
            pos = wxString::npos;
        }
    }

    richTextChatBox->EndStyle();
}