Browse Source

Added markdown view support

merge-requests/365/head
eidheim 10 years ago
parent
commit
c62beeb4af
  1. 7
      src/notebook.cc
  2. 33
      src/project.cc
  3. 9
      src/project.h

7
src/notebook.cc

@ -359,6 +359,12 @@ std::unique_ptr<Project> Notebook::get_project() {
if(get_current_page()!=-1) if(get_current_page()!=-1)
file_path=get_current_view()->file_path; file_path=get_current_view()->file_path;
if(get_current_page()!=-1) {
if(get_current_view()->language->get_id()=="markdown") {
return std::unique_ptr<Project>(new ProjectMarkDown(file_path));
}
}
return std::unique_ptr<Project>(new ProjectClang(file_path)); return std::unique_ptr<Project>(new ProjectClang(file_path));
} }
@ -378,4 +384,3 @@ bool Notebook::save_modified_dialog(int page) {
return false; return false;
} }
} }

33
src/project.cc

@ -2,6 +2,7 @@
#include "config.h" #include "config.h"
#include "terminal.h" #include "terminal.h"
#include "filesystem.h" #include "filesystem.h"
#include <fstream>
std::unordered_map<std::string, std::string> Project::run_arguments; std::unordered_map<std::string, std::string> Project::run_arguments;
std::unordered_map<std::string, std::string> Project::debug_run_arguments; std::unordered_map<std::string, std::string> Project::debug_run_arguments;
@ -111,3 +112,35 @@ void ProjectClang::compile_and_run() {
} }
}); });
} }
ProjectMarkDown::~ProjectMarkDown() {
if(!last_temp_path.empty()) {
boost::filesystem::remove(last_temp_path);
last_temp_path=boost::filesystem::path();
}
}
void ProjectMarkDown::compile_and_run() {
if(!last_temp_path.empty()) {
boost::filesystem::remove(last_temp_path);
last_temp_path=boost::filesystem::path();
}
std::stringstream stdin_stream, stdout_stream;
auto exit_status=Terminal::get().process(stdin_stream, stdout_stream, "markdown "+file_path.string(), this->file_path.parent_path());
if(exit_status==0) {
boost::system::error_code ec;
auto temp_path=boost::filesystem::temp_directory_path(ec);
if(!ec) {
temp_path/=boost::filesystem::unique_path();
temp_path+=".html";
if(!boost::filesystem::exists(temp_path)) {
last_temp_path=temp_path;
std::ofstream file_stream(temp_path.string(), std::fstream::binary);
file_stream << stdout_stream.rdbuf();
file_stream.close();
Terminal::get().async_process("open "+temp_path.string());
}
}
}
}

9
src/project.h

@ -47,4 +47,13 @@ public:
void compile_and_run() override; void compile_and_run() override;
}; };
class ProjectMarkDown : public Project {
public:
ProjectMarkDown(const boost::filesystem::path &file_path) : Project(file_path) {}
~ProjectMarkDown();
boost::filesystem::path last_temp_path;
void compile_and_run() override;
};
#endif // JUCI_PROJECT_H_ #endif // JUCI_PROJECT_H_

Loading…
Cancel
Save