forked from goldsborough/markdownpp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
119 lines (95 loc) · 2.28 KB
/
main.cpp
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#include "markdown-parser.hpp"
#include "include/markdown-abstract-math.hpp"
#include <boost/program_options.hpp>
#include <iostream>
int main(int argc, const char* argv[])
{
namespace po = boost::program_options;
po::options_description description("Usage");
std::string markdown_style;
std::string code_style;
std::string include_mode;
std::string stylesheet;
std::string root;
std::string input;
std::string output;
description.add_options()
("help", "show help")
(
"markdown,m",
po::value<std::string>(&markdown_style)
->default_value("solarized-dark")
->value_name("STYLE"),
"set the markdown-style"
)
(
"code,c",
po::value<std::string>(&code_style)
->default_value("xcode")
->value_name("STYLE"),
"set the code-style"
)
(
"include-mode,l",
po::value<std::string>(&include_mode)
->default_value("network")
->value_name("MODE"),
"set the include-mode"
)
(
"stylesheet,s",
po::value<std::string>(&stylesheet)
->value_name("PATH"),
"add a stylesheet"
)
(
"root,r",
po::value<std::string>(&root)
->default_value(".")
->value_name("PATH"),
"set the root path"
)
(
"input,i",
po::value<std::string>(&input)
->required(),
"the input markdown file"
)
(
"output,o",
po::value<std::string>(&output)
->default_value("output.html"),
"the output html file"
);
po::positional_options_description positional;
positional.add("input", 1);
positional.add("output", 1);
po::variables_map variables;
try
{
auto arguments = po::command_line_parser(argc, argv)
.options(description)
.positional(positional)
.run();
po::store(arguments, variables);
if (variables.count("help"))
{
std::cout << description;
return EXIT_SUCCESS;
}
po::notify(variables);
Markdown::Parser parser(root, stylesheet);
parser.configure("include-mode", include_mode);
parser.configure("markdown-style", markdown_style);
parser.configure("code-style", code_style);
parser.render_file(input, output);
std::cout << "Success \033[91m<3\033[0m\n";
}
catch(po::error& error)
{
std::cerr << "\033[91mError\033[0m: " << error.what() << "\n";
std::cerr << description;
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}