diff options
author | Aki <please@ignore.pl> | 2021-07-17 20:31:17 +0200 |
---|---|---|
committer | Aki <please@ignore.pl> | 2021-07-17 20:31:54 +0200 |
commit | 460e065d6856b3752f5fa2377a055f33d1c844ae (patch) | |
tree | d2189049a80e0c0fc4480ff1f936f3219c4cdb4b /markdown.cpp | |
parent | 8dbeec4824bc619a4eb05d1c6fcc6d21620fdbd0 (diff) | |
download | markdown-460e065d6856b3752f5fa2377a055f33d1c844ae.zip markdown-460e065d6856b3752f5fa2377a055f33d1c844ae.tar.gz markdown-460e065d6856b3752f5fa2377a055f33d1c844ae.tar.bz2 |
Added basic links support
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) |