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