Debian Codegraph @

linkify-it/support/demodata.js

raw
1 #!/usr/bin/env node
2
3 // Build demo data for embedding into html
4
5 /*eslint no-console:0*/
6
7 'use strict';
8
9 var fs = require('fs');
10 var path = require('path');
11
12 function isComment(str) { return /^%.*/.test(str); }
13 function isEmpty(str) { return !(str && str.trim()); }
14
15 var result = [], lines, line, i;
16
17 // Read links fixture
18 lines = fs.readFileSync(path.join(__dirname, '../test/fixtures/links.txt'), 'utf8').split(/\r?\n/g);
19
20 // Cleanup
21 for (i = 0; i < lines.length; i++) {
22 line = lines[i];
23
24 if (isComment(line)) {
25 result.push(line);
26 continue;
27 }
28
29 if (isEmpty(line)) {
30 if (isComment(lines[i + 1])) {
31 result.push('');
32 }
33 continue;
34 }
35
36 result.push(line);
37
38 if (!isComment(lines[i + 1]) && !isEmpty(lines[i + 1])) {
39 i++;
40 }
41 }
42
43 result.push('');
44 result.push('');
45
46 // Read non-links fixture
47 lines = fs.readFileSync(path.join(__dirname, '../test/fixtures/not_links.txt'), 'utf8').split(/\r?\n/g);
48
49 result = result.concat(lines);
50
51 // Join lines
52 result = result.join('\n');
53
54 console.log(JSON.stringify({
55 self: {
56 demo: {
57 source: result
58 }
59 }
60 }, null, 2));