48 lines
1 KiB
C++
48 lines
1 KiB
C++
|
#include <filesystem>
|
||
|
#include <iostream>
|
||
|
#include <fstream>
|
||
|
#include <ostream>
|
||
|
#include "CommandLineArgs.h"
|
||
|
#include "MarkdownParser.h"
|
||
|
#include "HtmlDocument.h"
|
||
|
#include "HtmlWriter.h"
|
||
|
|
||
|
int main(int argc, char *argv[])
|
||
|
{
|
||
|
CommandLineArgs command_line_args;
|
||
|
command_line_args.Process(argc, argv);
|
||
|
|
||
|
if(command_line_args.GetNumberOfArgs() < 2)
|
||
|
{
|
||
|
std::cerr << "Expected a filepath argument" << std::endl;
|
||
|
return -1;
|
||
|
}
|
||
|
|
||
|
MarkdownParser parser;
|
||
|
const auto filepath = command_line_args.GetArg(1);
|
||
|
|
||
|
if(!std::filesystem::exists(filepath))
|
||
|
{
|
||
|
std::cerr << "Couldn't find file: " << filepath << std::endl;
|
||
|
return -1;
|
||
|
}
|
||
|
|
||
|
std::ifstream md_file;
|
||
|
md_file.open(filepath, std::ifstream::in);
|
||
|
while(md_file.good())
|
||
|
{
|
||
|
std::string line;
|
||
|
std::getline(md_file, line);
|
||
|
parser.ProcessLine(line);
|
||
|
}
|
||
|
md_file.close();
|
||
|
|
||
|
auto html_document = parser.GetHtml();
|
||
|
HtmlWriter writer;
|
||
|
std::string html_string = writer.ToString(html_document);
|
||
|
std::ofstream out("/home/james/test.html");
|
||
|
out << html_string;
|
||
|
out.close();
|
||
|
return 0;
|
||
|
}
|