-
Notifications
You must be signed in to change notification settings - Fork 43
/
Copy pathextract.js
29 lines (26 loc) · 1.03 KB
/
extract.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
// Assertion extractor
// Usage:
// % npm i cheerio
// % node extract.js > manual.csv
const https = require('https');
const cheerio = require('cheerio');
const docUrl = 'https://raw.githubusercontent.com/w3c/wot-architecture/main/index.html'
const addAssertionTxt = true; // set true to add assertion text on fourth column
const req = https.get(docUrl, (res) => {
let data = '';
res.on('data', (chunk) => { data += chunk; });
res.on('end', () => {
const $ = cheerio.load(data);
console.log(`"ID","Status","Comment"${addAssertionTxt?',"Assertion"':''}`);
$('.rfc2119-assertion').each(function (i) {
const id = $(this).attr('id');
let assertionTxt = "";
if (addAssertionTxt) {
assertionTxt = ',"'+$(this).text().trim().replace(/\r?\n/g,'').replace(/\s+/g,' ').replace(/"/g, '""')+'"';
}
console.log(`"${id}","null","not testable with Assertion Tester"${assertionTxt}`);
});
});
}).on('error', (e) => {
console.error(e);
});