From 460e065d6856b3752f5fa2377a055f33d1c844ae Mon Sep 17 00:00:00 2001 From: Aki Date: Sat, 17 Jul 2021 20:31:17 +0200 Subject: Added basic links support --- markdown.cpp | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/markdown.cpp b/markdown.cpp index 63f293d..3f2eb4e 100644 --- a/markdown.cpp +++ b/markdown.cpp @@ -1,9 +1,13 @@ #include +#include +#include #include #include #include +#include #include +#include #include #include @@ -36,6 +40,41 @@ struct Markdown : public imgui_md return g_font_bold; } } + + void open_url() const override + { + std::array buffer; + std::string command = "browse -f markdown "; + std::string_view prefix(m_href.data(), 4); + if (prefix == "http") + command += m_href; + else + { + prefix.remove_suffix(2); + if (prefix == "//") + command += "https:" + m_href; + else + { + prefix.remove_suffix(1); + if (prefix == "/") + { + if (g_base_address.empty()) + return; // TODO: an error + else + command += g_base_address + m_href; + } + else + return; // TODO: also an error + } + } + std::unique_ptr opener(popen(command.c_str(), "r"), pclose); + if (!opener) + return; // TODO: time to do some error handling + while (nullptr != fgets(buffer.data(), buffer.size(), opener.get())) + { + // TODO: Support reopening + } + } }; static void glfw_error_callback(int error, const char * description) -- cgit v1.1