Allow access to the rendered html + css
jantimon opened this issue · 4 comments
Hey @AriaMinaei
I am using pretty-error
for the html-webpack-plugin
.
The error is logged to the console and also added to the result html file.
Would it be possible to render the error message also as a html (including a style tag)?
The code that you're looking for is here:
pretty-error/src/PrettyError.coffee
Line 220 in ba54889
Calling pe.getObject()
would return an object describing the structure of the final rendered error object:
const e = new Error('blah')
const obj = pe.getObject(e)
If you inspect obj
, you'll see that it has all the information there is about the original error object.
Now, since your goal is to ultimately print the error as an html document, you'll basically have two options:
- Write a convertor function that takes
obj
and returns"<html>...</html>"
. This is what I would do. - There is a private method on
RenderKid
that takes theobj
and refines it further. It works like this:const renderKid = pe._renderer; const refinedDom = renderKid._toDom(obj)
. In this method,refinedDom
is actually a DOM tree compatible with htmlparser2. What you can do with it is to stringify it (similar toHTMLElement#innerHTML
) using this function. Just take note that_toDom()
and_renderer
are private properties, so they may change or be removed in the future.
Isn't that sth you could easily provide so I don't have to build a large code around pretty-error?
If enough people wanted this, then it might make sense to provide it out of the box. Otherwise, it's just wasted effort that complicates the code base.
the html-webpack-plugin which makes heavy use of pretty error is downloaded million times a week so it would aid many users and javascript is very web focused so providing a html presentation might also help other use cases