summaryrefslogtreecommitdiff
path: root/markdown.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'markdown.cpp')
-rw-r--r--markdown.cpp15
1 files changed, 12 insertions, 3 deletions
diff --git a/markdown.cpp b/markdown.cpp
index 454db63..c96de7a 100644
--- a/markdown.cpp
+++ b/markdown.cpp
@@ -25,6 +25,7 @@
#include <stb_image.h>
std::string g_base_address;
+std::string g_text;
ImFont * g_font_regular;
ImFont * g_font_bold;
ImFont * g_font_bold_large;
@@ -124,10 +125,18 @@ struct Markdown : public imgui_md
void open_url() const override
{
- std::string command = "browse -f markdown " + expand_url(m_href);
+ std::string command = "browse -f ./markdown " + expand_url(m_href);
std::packaged_task<std::string (const std::string &)> task(get);
+ auto future = task.get_future();
std::thread t(std::move(task), command);
t.detach();
+ const auto result = future.get();
+ const auto n = result.find(" ");
+ const auto filename = result.substr(n + 1, result.size() - n - 2);
+ std::ifstream in;
+ in.open(filename);
+ g_text = std::string(std::istreambuf_iterator<char>(in), {});
+ in.close();
}
bool get_image(image_info & nfo) const override
@@ -239,7 +248,7 @@ int main(int argc, char ** argv)
std::ifstream in;
in.open(argv[optind]);
- std::string text(std::istreambuf_iterator<char>(in), {});
+ g_text = std::string(std::istreambuf_iterator<char>(in), {});
in.close();
while (!glfwWindowShouldClose(window))
@@ -257,7 +266,7 @@ int main(int argc, char ** argv)
ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove |
ImGuiWindowFlags_NoSavedSettings
);
- markdown(text.data(), text.data() + text.size());
+ markdown(g_text.data(), g_text.data() + g_text.size());
ImGui::End();
ImGui::Render();