Open cespare opened 11 years ago
Can't youtube links also have the host youtu.be
?
Sure. Extending the regex is the easy part. Hooking into the link processing part of the markdown is the f'ing annoying part.
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.
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:
Unfortunately this approach will walk all over youtube links in ``` defined code blocks.
Too much of a hack.
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.
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: