3

atom-shell only has a method to load HTML from a URL

window.loadUrl('file://...')

But I want to use Jade

var html = jade.renderFile('file://...');

Is there a way to use the compiled html in atom-shell window? Something like loadHtml(html)?

I suppose I could run an express server that serves compiled html but that would be rather inefficient..

0

2 Answers 2

3

In case of a mac:

/usr/bin/open -a "/Applications/Google Chrome.app" --args 'data:text/html,<html><body><h1>title</h1><p>text</p></body></html>'

Details about URI

https://developer.mozilla.org/en-US/docs/Web/HTTP/data_URIs

1
  • 2
    It worked, thanks! window.loadUrl('data:text/html,' + encodeURIComponent(jade.renderFile('file://...'))) Commented Jan 2, 2015 at 17:29
2

An alternative is to use the executeJavaScript function with something like

mainWindow.loadUrl('about:blank');
var s = '<DOCTYPE html><html><head><title>Written!</title></head><body><h1>Hello!</h1></body></html>';
mainWindow.webContents.executeJavaScript('document.write("' + s + '");');

Not the answer you're looking for? Browse other questions tagged or ask your own question.