summaryrefslogtreecommitdiff
path: root/markdown.cpp
diff options
context:
space:
mode:
authorAki <please@ignore.pl>2021-07-24 15:41:55 +0200
committerAki <please@ignore.pl>2021-07-24 15:41:55 +0200
commitdd402258e7bf3e57e2ca074854433c59509e185b (patch)
tree2eba299b6ba2b2973283bf56862c0b3fe7efd43e /markdown.cpp
parent5a34b7f589650dd4b7e2cf98cc8a35f7e69656bc (diff)
downloadmarkdown-master.zip
markdown-master.tar.gz
markdown-master.tar.bz2
Changed to open markdown files in the same viewHEADmaster
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();