-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparser.js
59 lines (54 loc) · 1.75 KB
/
parser.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
var validate = require('./validator')
var parser = {
getTags: function(content) {
content = String(content)
var tag = ""
var tags = []
for (let index = 0; index < content.length; index++) {
if (content.substr(index, 2) == "<a") {
tag = "<a"
index = index + 2
while (content.substr(index, 1) !== ">") {
tag += content.substr(index, 1)
index++
}
tag = tag + ">"
tags.push(tag)
}
}
return tags
},
getLinks: function(tag, code, callback) {
var link = ""
for (let index = 0; index < tag.length; index++) {
if (tag.substr(index, 4) == "href") {
index = index + 6
while (tag.substr(index, 2) !== "\'" & tag.substr(index, 1) !== "'" & tag.substr(index, 1) !== '"') {
link += tag.substr(index, 1)
index++
}
}
}
// console.log(link)
if (validate.isValidSubjectLink(link, code)) {
callback(link)
}
},
getPDFs: function(tag, filterData, callback) {
tag = String(tag)
var link = ""
for (let index = 0; index < tag.length; index++) {
if (tag.substr(index, 4) == "href") {
index = index + 6
while (tag.substr(index, 2) !== "\'" & tag.substr(index, 1) !== "'" & tag.substr(index, 1) !== '"') {
link += tag.substr(index, 1)
index++
}
}
}
if (validate.isValidPaperLink(link, filterData)) {
callback(link)
}
}
}
module.exports = parser