forked from mozilla/readability
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.js
40 lines (35 loc) · 1.08 KB
/
utils.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
var path = require("path");
var fs = require("fs");
var prettyPrint = require("js-beautify").html;
function readFile(filePath) {
return fs.readFileSync(filePath, {encoding: "utf-8"}).trim();
}
function readJSON(jsonPath) {
return JSON.parse(readFile(jsonPath));
}
var testPageRoot = path.join(__dirname, "test-pages");
exports.getTestPages = function() {
return fs.readdirSync(testPageRoot).map(function(dir) {
return {
dir: dir,
source: readFile(path.join(testPageRoot, dir, "source.html")),
expectedContent: readFile(path.join(testPageRoot, dir, "expected.html")),
expectedMetadata: readJSON(path.join(testPageRoot, dir, "expected-metadata.json")),
};
});
};
exports.prettyPrint = function(html) {
return prettyPrint(html, {
"indent_size": 4,
"indent_char": " ",
"indent_level": 0,
"indent_with_tabs": false,
"preserve_newlines": false,
"break_chained_methods": false,
"eval_code": false,
"unescape_strings": false,
"wrap_line_length": 0,
"wrap_attributes": "auto",
"wrap_attributes_indent_size": 4
});
};