Markdown support.
parent
1c68c72a1d
commit
0df159ae92
|
@ -511,6 +511,11 @@ article.snipt div.container section.code a.expand:focus {
|
|||
article.snipt div.container section.code textarea.raw {
|
||||
display: none;
|
||||
}
|
||||
article.snipt div.container section.code div.markdown {
|
||||
margin: 0 15px;
|
||||
min-height: 173px;
|
||||
padding: 13px 0 4px 0;
|
||||
}
|
||||
article.snipt div.container section.emacs a.expand, article.snipt div.container section.default a.expand {
|
||||
-webkit-box-shadow: 0 -25px 25px #f8f8f8;
|
||||
-moz-box-shadow: 0 -25px 25px #f8f8f8;
|
||||
|
@ -562,6 +567,9 @@ article.snipt div.container:after {
|
|||
width: 318px;
|
||||
z-index: 51;
|
||||
}
|
||||
article.snipt div.container div.markdown h1, article.snipt div.container div.markdown h2, article.snipt div.container div.markdown h3, article.snipt div.container div.markdown h4, article.snipt div.container div.markdown h5, article.snipt div.container div.markdown h6 {
|
||||
margin-bottom: 9px;
|
||||
}
|
||||
article.snipt aside {
|
||||
float: right;
|
||||
margin: 23px 30px 0 0;
|
||||
|
@ -695,6 +703,9 @@ article.snipt div.expanded section.code {
|
|||
article.snipt div.expanded section.code div.highlight pre {
|
||||
padding-bottom: 60px;
|
||||
}
|
||||
article.snipt div.expanded section.code div.markdown {
|
||||
padding-bottom: 52px;
|
||||
}
|
||||
article.snipt div.expanded section.code a.expand {
|
||||
background-image: url("/static/images/collapse.png");
|
||||
-webkit-box-shadow: none;
|
||||
|
|
|
@ -586,6 +586,11 @@ article.snipt {
|
|||
textarea.raw {
|
||||
display: none;
|
||||
}
|
||||
div.markdown {
|
||||
margin: 0 15px;
|
||||
min-height: 173px;
|
||||
padding: 13px 0 4px 0;
|
||||
}
|
||||
}
|
||||
section.emacs, section.default {
|
||||
a.expand {
|
||||
|
@ -638,6 +643,11 @@ article.snipt {
|
|||
width: 318px;
|
||||
z-index: 51;
|
||||
}
|
||||
div.markdown {
|
||||
h1, h2, h3, h4, h5, h6 {
|
||||
margin-bottom: 9px;
|
||||
}
|
||||
}
|
||||
}
|
||||
aside {
|
||||
float: right;
|
||||
|
@ -787,6 +797,9 @@ article.snipt {
|
|||
padding-bottom: 60px;
|
||||
}
|
||||
}
|
||||
div.markdown {
|
||||
padding-bottom: 52px;
|
||||
}
|
||||
a.expand {
|
||||
background-image: url('/static/images/collapse.png');
|
||||
-webkit-box-shadow: none;
|
||||
|
|
|
@ -144,6 +144,7 @@ INSTALLED_APPS = (
|
|||
'compressor',
|
||||
'django_bcrypt',
|
||||
'haystack',
|
||||
'markdown_deux',
|
||||
'pagination',
|
||||
'postmark',
|
||||
'registration',
|
||||
|
|
|
@ -6,6 +6,7 @@ from django.db import models
|
|||
from taggit.managers import TaggableManager
|
||||
from taggit.utils import edit_string_for_tags
|
||||
|
||||
from markdown_deux import markdown
|
||||
from pygments import highlight
|
||||
from pygments.lexers import get_lexer_by_name
|
||||
from pygments.formatters import HtmlFormatter
|
||||
|
@ -46,13 +47,21 @@ class Snipt(models.Model):
|
|||
if not self.key:
|
||||
self.key = md5.new(self.slug).hexdigest()
|
||||
|
||||
self.stylized = highlight(self.code,
|
||||
get_lexer_by_name(self.lexer, encoding='UTF-8'),
|
||||
HtmlFormatter())
|
||||
if self.lexer == 'markdown':
|
||||
self.stylized = markdown(self.code, 'default')
|
||||
else:
|
||||
self.stylized = highlight(self.code,
|
||||
get_lexer_by_name(self.lexer, encoding='UTF-8'),
|
||||
HtmlFormatter())
|
||||
self.line_count = len(self.code.split('\n'))
|
||||
|
||||
if self.lexer == 'markdown':
|
||||
lexer_for_embedded = 'text'
|
||||
else:
|
||||
lexer_for_embedded = self.lexer
|
||||
|
||||
embedded = highlight(self.code,
|
||||
get_lexer_by_name(self.lexer, encoding='UTF-8'),
|
||||
get_lexer_by_name(lexer_for_embedded, encoding='UTF-8'),
|
||||
HtmlFormatter(
|
||||
style='native',
|
||||
noclasses=True,
|
||||
|
@ -113,7 +122,10 @@ class Snipt(models.Model):
|
|||
|
||||
@property
|
||||
def lexer_name(self):
|
||||
return get_lexer_by_name(self.lexer).name
|
||||
if self.lexer == 'markdown':
|
||||
return 'Markdown'
|
||||
else:
|
||||
return get_lexer_by_name(self.lexer).name
|
||||
|
||||
class Favorite(models.Model):
|
||||
snipt = models.ForeignKey(Snipt)
|
||||
|
|
|
@ -10,7 +10,13 @@
|
|||
<h1><a href="<%= snipt.absolute_url %>"><% if (snipt.title) { %><%= snipt.title %><% } else { %>Untitled <% } %></a></h1>
|
||||
</header>
|
||||
<section class="code autumn">
|
||||
<%= snipt.stylized %>
|
||||
<% if (snipt.lexer == 'markdown') { %>
|
||||
<div class="markdown">
|
||||
<%= snipt.stylized %>
|
||||
</div>
|
||||
<% } else { %>
|
||||
<%= snipt.stylized %>
|
||||
<% } %>
|
||||
<% if (snipt.line_count > 8 && !window.detail) { %>
|
||||
<a href="#" class="expand">
|
||||
<span class="expand">Expand</span>
|
||||
|
|
|
@ -11,7 +11,13 @@
|
|||
<h1><a href="{{ snipt.get_absolute_url }}">{% if snipt.title %}{{ snipt.title }}{% else %}Untitled{% endif %}</a></h1>
|
||||
</header>
|
||||
<section class="code {% if request.GET.style %}{{ request.GET.style }}{% else %}autumn{% endif %}">
|
||||
{{ snipt.stylized|safe }}
|
||||
{% if snipt.lexer == 'markdown' %}
|
||||
<div class="markdown">
|
||||
{{ snipt.stylized|safe }}
|
||||
</div>
|
||||
{% else %}
|
||||
{{ snipt.stylized|safe }}
|
||||
{% endif %}
|
||||
{% if snipt.line_count > 8 and not detail %}
|
||||
<a href="#" class="expand">
|
||||
<span class="expand">Expand</span>
|
||||
|
|
|
@ -45,7 +45,11 @@ def snipts_count_for_user(context):
|
|||
@tag(register, [Constant('as'), Variable()])
|
||||
def get_lexers(context, asvar):
|
||||
|
||||
context[asvar] = sorted(get_all_lexers())
|
||||
lexers = list(get_all_lexers())
|
||||
lexers.append(('Markdown', ('markdown',),))
|
||||
lexers = sorted(lexers)
|
||||
|
||||
context[asvar] = lexers
|
||||
|
||||
return ''
|
||||
|
||||
|
|
Loading…
Reference in New Issue