diff options
Diffstat (limited to 'markdown.cpp')
-rw-r--r-- | markdown.cpp | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/markdown.cpp b/markdown.cpp index 63f293d..3f2eb4e 100644 --- a/markdown.cpp +++ b/markdown.cpp @@ -1,9 +1,13 @@ #include <unistd.h> +#include <array> +#include <cstdio> #include <fstream> #include <iostream> #include <iterator> +#include <memory> #include <string> +#include <string_view> #include <GL/glew.h> #include <GLFW/glfw3.h> @@ -36,6 +40,41 @@ struct Markdown : public imgui_md return g_font_bold; } } + + void open_url() const override + { + std::array<char, 512> 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<FILE, decltype(&pclose)> 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) |