bkad / prat

group chat with markdown served over websockets
11 stars 6 forks source link

Video embeds #50

Open cespare opened 11 years ago

cespare commented 11 years ago

Youtube, vimeo, etc.

I started doing this but then realized it's a pain in the ass because of how callbacks work with sundown.

Here's a regex for youtube.com links to get started:

r"(https?://)?(www\.)?youtube\.com/watch\?\w*v=(?P<id>[0-9A-Za-z+)\w*"
mdietz commented 11 years ago

Can't youtube links also have the host youtu.be?

cespare commented 11 years ago

Sure. Extending the regex is the easy part. Hooking into the link processing part of the markdown is the f'ing annoying part.

bkad commented 11 years ago

As a reference, in order to add the target="_blank" attribute for autolinks, I had to modify the C code directly. https://github.com/bkad/misaka/commit/ccb20ee19113232b07ab3d7869a7533737c4a230

The reason for it is because the library only allows you to override the callback directly. You can't, for example, take the output of the autolink output that Sundown generates, modify it Python, and pass it back into the buffer. If you want to keep most of the native logic but modify it slightly, you have two choices: 1.) Duplicate all the native code in the Python override method. or 2.) Modify the Sundown code directly. I went with the latter option, just because it wasn't too complicated for my particular modification.

mdietz commented 11 years ago

There might be a third option. We can add in pre and post processors to the renderer in python, so it's possible to do a regex match for something like youtube links, replace them with a token (e.g. youtube:) so that the autolinker doesn't try and apply formatting to the url, then output the embedded iframe in the post processing pass. See https://github.com/bkad/oochat/tree/video_embedding for a prototype of this.

Unfortunately this approach will walk all over youtube links in ``` defined code blocks.

bkad commented 11 years ago

Too much of a hack.

mdietz commented 11 years ago

Having found several ways to break my code in the last 5 minutes. I agree with @bkad. This is going to be a pain to do right.