SDK -> Plugin Dev -> Open Preview Dynamically

sdk

#1

I’m trying to open a preview using a string as the data source. See code below in screenshot:

It opens a preview tab, but the tab is blank. What am I doing wrong here? (I know its probably a rookie mistake)

Thanks!


#2

This is not supported by preview editor
You can add a new previewer similar to the https://github.com/c9/c9.ide.preview/blob/master/previewers/raw.js

Or use Blob and URL.createObjectURL to do something like

blob = new Blob(["<button>click me</button>"], {"type": "text/html"});
blobURL = URL.createObjectURL(blob);
app.tabManager.open({
    active: true,
    editorType: "preview",
    url: blobURL
})

right now this doesn’t work due to a bug in url parsing but that is easy to fix.

A drawback of this method is that blobURL needs to be recreated after window reload.

What are you trying to do? Using html directly in a new editor instead of preview, may be easier.


#3

Ok that makes sense.

I’m extending my pigments plugin to add a new command that generates a report of all the colors in a file and the report will have the swatches and color info. This will be good for generating documents to give to clients or to keep on record for future changes.

The report I figured could just be HTML that is loaded into the preview pane.

edit: I’ve thought about generating the html into a file and then loading that like normal. That way they have a saved copy of it as well. That would probably be best practice too…


#5

I fixed this issue and now a new one has popped up… I am unable to publish the new version and my old version is gone off the c9 list.

Here is the solution to my problem for future reference: