transformime
Transforms MIMEtype+data to HTML Elements
Intended to be used in context of Jupyter and IPython projects, particularly by display areas.
Installation
npm install transformime
Usage
Transformime works in the browser (via browserify), converting a mimebundle (MIME type + data) into HTML Elements. transformime.transform
returns promises for all the HTMLElements.
createTransform
Using the helper function var transformime = ; var transform = transformime; ;
Transform a single mimetype
> t = ;> p1 = tPromise <pending> > p1Promise mimetype: 'text/html' el: _events: {} _childNodes: Object _childNodesList: null _ownerDocument: Object _childrenList: null _version: 1 _parentNode: null _memoizedQueries: {} _readonly: false _namespaceURI: 'http://www.w3.org/1999/xhtml' _prefix: null _localName: 'div' _attributes: {} _settingCssText: false _style: Object > p1;Promise <pending> > <h1>Woo</h1>Woo
Images get handled as base64 encoded data and become embedded elements.
> // Send an image over> p2 = t> p2data:image/png;base64R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7
Transform the richest element
> var mimes = 'text/html': '<code>import this</code>' 'text/plain': 'import this'> var p3 = t;> p3text/html: <code>
Working with iframes
> // Create an arbitrary iframe and slap it in the body of the document> var iframe = document;> document;> var idoc = iframecontentDocument;> // Pass the iframe's document as the document context for the created element> var p5 = t;> p5> idocinnerHTML'<div><h1>mimetic</h1></div>'
Documentation
The full API documentation can be found here.
Development
git clone https://github.com/nteract/transformime
cd transformime
npm install
npm run build