forked from progsource/maddy
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmain.cpp
More file actions
37 lines (30 loc) · 912 Bytes
/
main.cpp
File metadata and controls
37 lines (30 loc) · 912 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include <fstream>
#include <iostream>
#include <memory>
#include <string>
#include "maddy/parser.h"
int main( int argc, char** argv )
{
if ( argc < 3 ) {
std::cout << "Usage maddy input.md output.html" << std::endl;
return 1;
}
std::ifstream markdownInput{ argv[ 1 ], std::ifstream::in };
if ( !markdownInput ) {
std::cerr << "Failed to open " << argv[ 1 ] << std::endl;
return 1;
}
std::stringstream markdown;
markdown << markdownInput.rdbuf();
markdownInput.close();
std::shared_ptr<maddy::Parser> parser = std::make_shared<maddy::Parser>();
std::string html = parser->Parse( markdown );
std::ofstream htmlOutput{ argv[ 2 ], std::ofstream::out };
if ( !htmlOutput ) {
std::cerr << "Failed to open " << argv[ 2 ] << std::endl;
return 1;
}
htmlOutput << html;
htmlOutput.close();
return 0;
}