Snipt codes

'
master
Nick Sergeant 2012-05-29 22:57:23 -04:00
parent d62c5cdff2
commit 1261ad70b0
4 changed files with 17 additions and 2 deletions

View File

@ -490,6 +490,10 @@ article.snipt div.container section.code div.highlight pre {
min-height: 173px;
padding: 13px 0;
}
article.snipt div.container section.code div.markdown pre {
min-height: 0;
margin: 20px 0 !important;
}
article.snipt div.container section.code a.expand {
background: white url("/static/images/expand.png") 15px 18px no-repeat;
border-top: 1px solid #F1F1EE;

View File

@ -566,6 +566,12 @@ article.snipt {
padding: 13px 0;
}
}
div.markdown {
pre {
min-height: 0;
margin: 20px 0 !important;
}
}
a.expand {
background: #FFF url('/static/images/expand.png') 15px 18px no-repeat;
border-top: 1px solid #F1F1EE;

View File

@ -13,7 +13,7 @@ from pygments.formatters import HtmlFormatter
from snipts.utils import slugify_uniquely
import datetime, md5
import datetime, md5, re
site = Site.objects.all()[0]
@ -52,6 +52,9 @@ class Snipt(models.Model):
if self.lexer == 'markdown':
self.stylized = markdown(self.code, 'default')
for match in re.findall('\[\[(.*)\]\]', self.stylized):
self.stylized = self.stylized.replace('[[' + str(match) + ']]',
'<script type="text/javascript" src="https://snipt.net/embed/{}"></script><div id="snipt-embed-{}"></div>'.format(match, match))
else:
self.stylized = highlight(self.code,
get_lexer_by_name(self.lexer, encoding='UTF-8'),

View File

@ -1 +1,3 @@
document.open();document.writeln('<div onmouseover="document.getElementById(\'snipt-{{ snipt.id }}\').style.display = \'block\'; return false;" onmouseout="document.getElementById(\'snipt-{{ snipt.id }}\').style.display = \'none\'; return false;" style="position: relative;">');{% for line in lines %}document.writeln('{{ line|safe }}');{% endfor %}document.writeln('<div style="background-color: #111; color: #D0D0D0; float: right; padding: 5px 10px; -moz-border-radius-topleft: 5px; -webkit-border-top-left-radius: 5px; border-top-left-radius: 5px; -moz-border-radius-bottomright: 5px; -webkit-border-bottom-right-radius: 5px; border-bottom-right-radius: 5px; font: 11px Arial,Sans-Serif; display: none; position: absolute; bottom: 0; right: 0;" id="snipt-{{ snipt.id }}">code hosted by <a href="https://snipt.net/{{ snipt.user }}/{{ snipt.slug }}{% if not snipt.public %}?key={{ snipt.key }}{% endif %}" style="color: #0084FF; text-decoration: none;">snipt.net</a></div>');document.writeln('</div>');document.close();
{% if 'snipt.net' or 'snipt.localhost' in request.HTTP_REFERER %}$(function() {
$('div#snipt-embed-{{ snipt.key }}').html('<div onmouseover="document.getElementById(\'snipt-flag-{{ snipt.id }}\').style.display = \'block\'; return false;" onmouseout="document.getElementById(\'snipt-flag-{{ snipt.id }}\').style.display = \'none\'; return false;" style="position: relative;">{% for line in lines %}{{ line|safe }}\n{% endfor %}<div style="background-color: #111; color: #D0D0D0; float: right; padding: 5px 10px; -moz-border-radius-topleft: 5px; -webkit-border-top-left-radius: 5px; border-top-left-radius: 5px; -moz-border-radius-bottomright: 5px; -webkit-border-bottom-right-radius: 5px; border-bottom-right-radius: 5px; font: 11px Arial,Sans-Serif; display: none; position: absolute; bottom: 0; right: 0;" id="snipt-flag-{{ snipt.id }}">code hosted by <a href="https://snipt.net/{{ snipt.user }}/{{ snipt.slug }}{% if not snipt.public %}?key={{ snipt.key }}{% endif %}" style="color: #0084FF; text-decoration: none;">snipt.net</a></div></div>');
});{% else %}document.open();document.writeln('<div onmouseover="document.getElementById(\'snipt-{{ snipt.id }}\').style.display = \'block\'; return false;" onmouseout="document.getElementById(\'snipt-{{ snipt.id }}\').style.display = \'none\'; return false;" style="position: relative;">');{% for line in lines %}document.writeln('{{ line|safe }}');{% endfor %}document.writeln('<div style="background-color: #111; color: #D0D0D0; float: right; padding: 5px 10px; -moz-border-radius-topleft: 5px; -webkit-border-top-left-radius: 5px; border-top-left-radius: 5px; -moz-border-radius-bottomright: 5px; -webkit-border-bottom-right-radius: 5px; border-bottom-right-radius: 5px; font: 11px Arial,Sans-Serif; display: none; position: absolute; bottom: 0; right: 0;" id="snipt-{{ snipt.id }}">code hosted by <a href="https://snipt.net/{{ snipt.user }}/{{ snipt.slug }}{% if not snipt.public %}?key={{ snipt.key }}{% endif %}" style="color: #0084FF; text-decoration: none;">snipt.net</a></div>');document.writeln('</div>');document.close();{% endif %}