-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
205 lines (189 loc) · 6.04 KB
/
Copy pathmain.cpp
File metadata and controls
205 lines (189 loc) · 6.04 KB
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
// Code by Cevat Sonmez Yucel
#include <iostream>
#include <fstream>
#include <string>
#include "MD.h"
using std::cout;
using std::string;
using std::cin;
using std::ws;
int main() {
MD myMD;
cout << "Welcome to Markdown Generator.\n";
// Interface to generate Markdown
while (true) {
cout << "---------------------------------------\n";
cout << "nb -- Type in default formatted text\n";
cout << "h -- Type a heading\n";
cout << "i -- Type in italics\n";
cout << "s -- Type strong (usually bold) text\n";
cout << "st -- Type strikethrough ( ̶e̶x̶a̶m̶p̶l̶e̶) text\n";
cout << "hl -- Add a horizontal line\n";
cout << "bq -- Type inside a blockquote\n";
cout << "l -- Type a link\n";
cout << "ul -- Type an unordered list\n";
cout << "ol -- Type an ordered list\n";
cout << "im -- Add an image\n";
cout << "p -- Preview contents\n";
cout << "r -- Remove item\n";
cout << "cl -- Change location of item\n";
cout << "done -- Generate Markdown\n";
cout << "---------------------------------------\n";
string command;
cin >> command;
if (command == "done") {
break;
}
if (command == "nb") {
cout << "Please type in desired text: ";
string userInput;
getline(cin >> ws, userInput);
myMD.body(userInput);
}
if (command == "h") {
cout << "1 being largest and 6 being smallest, choose size of heading: ";
string size;
cin >> size;
cout << "Please type in desired text: ";
string userInput;
getline(cin >> ws, userInput);
if (size == "1") {
myMD.headings1(userInput);
}
else if (size == "2") {
myMD.headings2(userInput);
}
else if (size == "3") {
myMD.headings3(userInput);
}
else if (size == "4") {
myMD.headings4(userInput);
}
else if (size == "5") {
myMD.headings5(userInput);
}
else if (size == "6") {
myMD.headings6(userInput);
}
else {
cout << "INVALID SIZE\n";
}
}
if (command == "i") {
cout << "Please type in desired text: ";
string userInput;
getline(cin >> ws, userInput);
myMD.italics(userInput);
}
if (command == "s") {
cout << "Please type in desired text: ";
string userInput;
getline(cin >> ws, userInput);
myMD.strong(userInput);
}
if (command == "st") {
cout << "Please type in desired text: ";
string userInput;
getline(cin >> ws, userInput);
myMD.strikeThrough(userInput);
}
if (command == "hl") {
myMD.horizontalRule();
}
if (command == "bq") {
cout << "Please type in desired text: ";
string userInput;
getline(cin >> ws, userInput);
myMD.blockQuote(userInput);
}
if (command == "l") {
cout << "URL: ";
string url;
cin >> url;
cout << "Name: ";
string name;
getline(cin >> ws, name);
cout << "Add hovering name to link? (y/n) ";
string option;
cin >> option;
if (option == "y") {
cout << "Hovering Name: ";
string hover;
cin >> hover;
myMD.link(url, name, hover);
}
if (option == "n") {
myMD.link(url, name);
}
else {
cout << "Invalid option\n";
}
}
if (command == "ul") {
cout << "Number of elements: ";
int numberOfElements;
cin >> numberOfElements;
for (int i = 0; i < numberOfElements; i++) {
cout << "Please type in desired text for element " << i + 1 << ": ";
string userInput;
getline(cin >> ws, userInput);
myMD.unorderedList(userInput);
}
}
if (command == "ol") {
cout << "Number of elements: ";
int numberOfElements;
cin >> numberOfElements;
for (int i = 0; i < numberOfElements; i++) {
cout << "Please type in desired text for element " << i + 1 << ": ";
string userInput;
getline(cin >> ws, userInput);
myMD.orderedList(userInput);
}
}
if (command == "im") {
cout << "Link to image: ";
string url;
cin >> url;
cout << "Name: ";
string name;
getline(cin >> ws, name);
myMD.image(name, url);
}
if (command == "p") {
myMD.preview();
}
if (command == "r") {
cout << "Item to remove: ";
int index;
cin >> index;
index--;
myMD.removeElement(index);
}
if (command == "cl") {
cout << "Item to move: ";
int itemIndex;
cin >> itemIndex;
cout << "Location to move to: ";
int targetIndex;
cin >> targetIndex,
itemIndex--;
targetIndex--;
myMD.changeElementLocation(itemIndex, targetIndex);
}
}
// Generates file with user specified name and places it in the same directory as the code
cout << "File name (without .md): ";
string fileName;
getline(cin >> ws, fileName);
fileName += ".md";
std::ofstream myfile;
myfile.open(fileName);
for (int i = 0; i < myMD.toPrint.size(); i++) {
myfile << myMD.toPrint[i];
myfile << "\n";
myfile << "\n";
}
myfile.close();
return 0;
}