w3c / webidl2.js

WebIDL parser
https://w3c.github.io/webidl2.js/checker/
MIT License
249 stars 63 forks source link

Modify writer to be ReSpec compatible #210

Closed saschanaz closed 5 years ago

saschanaz commented 6 years ago

188 removed opt parameter for write. write(ast, { type }) will use callback for every IDL type, so we can use it as a hook to add HTML class for them.

I haven't really been played with ReSpec webidl writer deep enough, but I think reviving the optional callback may allow ReSpec to replace the current writer with the new webidl2.js one.

marcoscaceres commented 6 years ago

Would be great. There is some trickiness with linking, but that could be resolved on the ReSpec side... so long as we get back the correct HTML structure, and the right IDs, can definitely work with that.

saschanaz commented 6 years ago

Currently I'm thinking about a writer API that doesn't directly couple with ReSpec:


import * as webidl2 from "webidl2";
import hyperHTML from "hyperhtml";

webidl2.writer(ast, {
  // Customizes trivia output. The raw string will be used if absent
  trivia(text) {
    return hyperHTML`<span class="idlComment">${text}</span>`;
  }
  // Customizes type reference output
  reference(name) {
    return hyperHTML`<a>${name}</a>`
  }
  interface(obj, components) {
    const idlId = ""; // ReSpec somehow generates this
    return hyperHTML`<span class="idlInterface" id="${idlId}" data-idl data-title="${obj.name}">${components}</span>`;
  }
  // ... some more similar functions ...
});
saschanaz commented 5 years ago

Closed by #241