-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCODE SAVE.txt
60 lines (54 loc) · 1.39 KB
/
CODE SAVE.txt
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
#include <iostream>
using namespace std;
int AvoidLastSpaces(string markdown){
int Lindex = markdown.size()-1;
while(markdown.at(Lindex)== ' ')
Lindex--;
return Lindex;
}
int AvoidSpaces(int i, string markdown){
while (markdown.at(i) == ' ')
i++;
return i;
}
string getmarkdown(int index, string markdown, int Lindex){
string header;
int tick=0;
while (index != Lindex+1){
// figure out if the '*' closes.
if(markdown.at(index)== '*'){
if(tick <1){
header += "<strong>";
tick++;
}
else {header +="</strong>";
tick=0;}
index+=2;
continue;
}
header += markdown.at(index);
index++;
}
return header;
}
int countTags(int i, string markdown){
int tags = i;
while (tags < tags + 7){
if (markdown.at(tags) != '#')
break;
tags++;
}
return tags-i;
}
bool isValid(int i, string markdown, int numHTags){
return (markdown.at(i)== ' ')?(numHTags>=7)?false:true:false;
}
std::string markdownparser(std::string markdown)
{
int index= AvoidSpaces(0,markdown),
numHTags = countTags(index,markdown),
Lindex = AvoidLastSpaces(markdown);
if(isValid(index+numHTags, markdown, numHTags))
return "<h" + to_string(numHTags) + ">" + getmarkdown(AvoidSpaces(index+numHTags,markdown), markdown, Lindex) + "</h" + to_string(numHTags) + ">";
else return getmarkdown(index,markdown, Lindex);
}