Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP


Provide a synchronous API #43

philc opened this Issue · 5 comments

6 participants


It makes sense that the API is asynchronous by default, but it would be nice to have another API which is synchronous (it returns the highlighted text and doesn't take a callback). This is particularly useful for server-side usage of Rainbow. Otherwise setTimeout gymnastics are required (see #7).

@philc philc referenced this issue

node.js support? #7



this also makes sense in the browser, when parsing small snippets of code, a lot of gymnastics have to be made for an unnecessary (in my particular case) asynchronous API whereas a simple synchronous API would suffice.


Somewhat related: I have a script which modifies the DOM after the rainbowcode highlighting is completed by adding tooltips and a Table of Contents.

Right now I'm doing a setTimeout because when I tried an onload listener it was called before the rainbow code was completed. Doing Rainbow.color(callback) means that the highlighting happens twice (once when called by my code and once by the document 'onload' listener). Any further suggestions? Really want a Rainbow.ready(callback) jQuery-type of function that will call the function immediately if Rainbow code has already completed parsing the DOM.

Any further suggestions? Should I add it to the code and make a pull request?


@josher19 I have created another ticket for this. See #93


+1 for a synchronous API. It would be great to be able to hook up the library with marked.js (e.g., see this issue).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.