Pastebin onebox?

Is anyone thinking about or working on a onebox for Pastebin? The Gist onebox is pretty good but it seems many more of our people (and here too, I think) are going with pastebin instead.

3 Likes

Sure, can you research that @techapj and see what’s involved to make that work with Oneboxer?

2 Likes

For the raw contents, all you need to do is take the Paste ID and make a request to /raw.php?i=<paste id>. I’m not sure how to get the language, date, author, etc.

2 Likes

@techapj Did you happen to find an easy solution for this? I’ve tried to encourage GitHub gists but old habits die hard. :slight_smile:

2 Likes

Okay, I just created a custom onebox engine for Pastebin! :tada:

http://pastebin.com/raw/YH8wQDi8

Enjoy, and thanks for nudging me about this @downey :slightly_smiling:


https://github.com/discourse/onebox/commit/29400bcb7ac74f902bed24ac8da175f953b01c56

7 Likes

This works great. Thanks @techAPJ!

1 Like

And the open source clone hastebin?
:smiley:

It seems like hastebin.com does not provide any API access, nor any oEmbed endpoint.

1 Like

Yes not an embed point but it has the same /raw/ function as pastebin.

You’d need to lobby them to support oEmbed or OpenGraph…

4 Likes

Wouldn’t it be better to remove the max-height: 100px though? Only 3 lines are shown even if there are more…

http://pastebin.com/awq7Zhs9

2 Likes

Thats’s because if max-height property is not provided then the one line pastes takes up 150px height by default. Adding max-height: 100px limits that to 100px. See:

http://pastebin.com/bLQcKwjy

1 Like

Shouldn’t that be min-height then?

1 Like

Not exactly. Something is forcing iframes to be 150px tall. Need to figure out where that is happening to figure out how to properly fix it.

3 Likes

Okay, big thanks to @RyanReese (who found the spec for me and solidified that I was on the right track), but unfortunately this is part of the CSS2 spec.

Visual formatting model details (search for 150)

In short, Chrome or whatever browser you are using is enforcing the 150px iframe size (so long as they follow the CSS2 spec).

So how do you reduce it or enlarge it based on the content of the iframe? With JavaScript :frowning: There isn’t a CSS solution that can tell you the height of the iframe content (as that data exists on another page/site). So unless you can execute some JavaScript to get the inner height of the iframe before it is cooked, Discourse just has to pick a happy medium to ship with.

If you can, the idea would be to detect if it is greater than 100px, if it is, set the height style and max-height to 300px (to give it some room to show the user what data is there. Otherwise, set it to 100px for both attributes.

4 Likes

Also, it would be ideal to handle these max-height/min-height/height styles in a class labelled pastebin-onebox so it is easier to override versus attaching it to the iframe via inline styles.

Maybe have a pastebin-onebox (which is the 100px setting) and a pastebin-onebox-large for the 300px setting

You could have the oneboxing code download raw.php and use the ‘large’ if there’s more than 1 line.

2 Likes

Okay I fixed this issue by removing Pastebin iframe and instead extracting first 10 lines of a paste, similar to GitHub Gist onebox.


See the improved pastebin onebox demo here:

5 Likes

This looks nice but it seems to struggle with long lines. The old one wrapped, but the new one does not. Anything that can be done for that?

Old one here until an update installed and the post is rebaked:

http://pastebin.com/5HAC1rHc