YouTube embeds in Markdown posts.

master
Nick Sergeant 2012-06-11 15:53:56 -04:00
parent e8d29139ec
commit 180f710381
1 changed files with 9 additions and 1 deletions

View File

@ -52,9 +52,17 @@ class Snipt(models.Model):
if self.lexer == 'markdown':
self.stylized = markdown(self.code, 'default')
# Snipt embeds
for match in re.findall('\[\[(\w{32})\]\]', self.stylized):
self.stylized = self.stylized.replace('[[' + str(match) + ']]',
'<script type="text/javascript" src="https://snipt.net/embed/{}/?snipt"></script><div id="snipt-embed-{}"></div>'.format(match, match))
'<script type="text/javascript" src="https://snipt.net/embed/{}/?snipt"></script><div id="snipt-embed-{}"></div>'.format(match, match))
# YouTube embeds
for match in re.findall('\[\[youtube-(\w{11})\-(\d+)x(\d+)\]\]', self.stylized):
self.stylized = self.stylized.replace('[[youtube-{}-{}x{}]]'.format(str(match[0]), str(match[1]), str(match[2])),
'<iframe width="{}" height="{}" src="http://www.youtube.com/embed/{}" frameborder="0" allowfullscreen></iframe>'.format(match[1], match[2], match[0]))
else:
self.stylized = highlight(self.code,
get_lexer_by_name(self.lexer, encoding='UTF-8'),