This repository was archived by the owner on Apr 14, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathyart.js
67 lines (67 loc) · 2.52 KB
/
yart.js
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
var resumeMarkdownParser = function (rawInput) {
String.prototype._parseMarkdownAnchor = function () {
return this.replace(/\[(.*?)\]\((.*?)\)/g, '<a href="$2" target="_blank">$1</a>');
};
String.prototype.beginWith = function (__sub) {
if (this.indexOf(__sub) == 0) {
return true;
} else {
return false;
};
};
Array.prototype.add = function(x) {
if (typeof(x) === 'number') {
this.push('_num-' + x);
} else if (typeof(x) === 'string') {
this.push(x);
} else {
for (var i = 0; i < x.length; i++) {
this.push(x[i]);
};
};
};
var _ast = rawInput.trim().replace(/</g, '<').replace(/>/g, '>').replace(/\n\n/g, '\n').replace(/\n\n/g, '\n').split('\n');
for (var i = 0; i < _ast.length; i++) {
var _htmlTag = '';
var _htmlTagClassList = ['lazy-display-animation'];
var _htmlText = '';
_ast[i] = _ast[i].trim();
if (_ast[i].beginWith('@ ')) {
_htmlTag = 'h1';
_htmlText = _ast[i].slice(2);
} else if (_ast[i].beginWith('@@ ')) {
_htmlTag = 'div';
_htmlTagClassList.add('contact');
_htmlText = _ast[i].slice(3).replace(/(.*?)(:|:) /i, '<em>$1</em>')._parseMarkdownAnchor();
} else if (_ast[i].beginWith('# ')) {
_htmlTag = 'h2';
_htmlTagClassList.add('section-heading');
_htmlText = _ast[i].slice(2)._parseMarkdownAnchor();
} else if (_ast[i].beginWith('## ')) {
_htmlTag = 'h3';
_htmlText = _ast[i].slice(3).replace(/(.*) \{/i, '<span class="job">$1</span> {').replace(/ \{(.*)\}/, ' <span class="duration">$1</span>')._parseMarkdownAnchor();
} else if (_ast[i].beginWith(':: ')) {
_htmlTag = 'div';
_htmlTagClassList.add('ref');
_htmlText = _ast[i].slice(3)._parseMarkdownAnchor();
} else if (_ast[i].beginWith('// ')) {
_htmlTag = 'div';
_htmlTagClassList.add('subsection-tagline');
_htmlText = _ast[i].slice(3)._parseMarkdownAnchor();
} else if (_ast[i].beginWith('====')) {
_htmlTag = 'div';
_htmlTagClassList.add(['page-break', 'page-start']);
_htmlText = '';
} else {
_htmlTag = 'p';
_htmlText = _ast[i]._parseMarkdownAnchor();
}
// console.log(_htmlTag);
// console.log(_htmlText);
// console.log(_htmlTagClassList);
var _htmlElementGenerated = document.createElement(_htmlTag);
_htmlElementGenerated.setAttribute('class', _htmlTagClassList.join(' '));
_htmlElementGenerated.innerHTML = _htmlText;
document.getElementById('cont').appendChild(_htmlElementGenerated);
};
};