Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added docs/html/.gitkeep
Empty file.
Empty file added docs/md/.gitkeep
Empty file.
6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"dependencies": {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bitte gern geschehen.

"highlight.js": "^9.12.0",
"marked": "^0.3.7"
}
}
21 changes: 18 additions & 3 deletions parse.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
const fs = require('fs')
const marked = require('marked');
const highlight = require('highlight.js');

marked.setOptions({
highlight: code => highlight.highlightAuto(code).value
});

fs.readFile('js_protocol.pdl', 'utf8', (err, data) => {
const js_schema = parse(data);
Expand All @@ -7,6 +13,7 @@ fs.readFile('js_protocol.pdl', 'utf8', (err, data) => {
const schema = {domains: js_schema.domains.concat(browser_schema.domains)};
traceUsages(schema);
markdown(schema);
html(schema);
});
});

Expand Down Expand Up @@ -323,7 +330,7 @@ function markdown(schema) {
const usages = type.usages.get(usageType);
for (const {item, prefix} of usages) {
const domainName = item.domain.name;
result.push(`[${domainName}.${item.name}]: ${domainName.toLowerCase()}.md#${prefix}-${domainName.toLowerCase()}${item.name.toLowerCase()} "${domainName}.${item.name}"`);
result.push(`[${domainName}.${item.name}]: ${domainName.toLowerCase()}.html#${prefix}-${domainName.toLowerCase()}-${item.name.toLowerCase()} "${domainName}.${item.name}"`);
}
}
}
Expand All @@ -332,7 +339,7 @@ function markdown(schema) {
for (const type of domain.usedTypes) {
const domainName = type.domain.name.toLowerCase();
const name = type.name.toLowerCase();
result.push(`[${type.domain.name}.${type.name}]: ${domainName}.md#type-${domainName}${name} "${type.domain.name}.${type.name}"`);
result.push(`[${type.domain.name}.${type.name}]: ${domainName}.html#type-${domainName}-${name} "${type.domain.name}.${type.name}"`);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this breaks md links

}

result.push(`[boolean]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON "JSON boolean"`);
Expand All @@ -342,6 +349,14 @@ function markdown(schema) {
result.push(`[object]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON "JSON object"`);
result.push(`[any]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON "JSON any"`);

fs.writeFileSync(`docs/${domain.name.toLowerCase()}.md`, result.join('\n'));
fs.writeFileSync(`docs/md/${domain.name.toLowerCase()}.md`, result.join('\n'));
}
}

function html(schema) {
for (const domain of schema.domains) {
const md = fs.readFileSync(`docs/md/${domain.name.toLowerCase()}.md`, 'utf8');
debugger;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

debugging Node just because we can 👍

fs.writeFileSync(`docs/html/${domain.name.toLowerCase()}.html`, marked(md));
}
}