Skip to content

Commit e18e2b8

Browse files
author
yangxg
committed
Step9: markdown and code highlight supported
1 parent 02f1d95 commit e18e2b8

File tree

4 files changed

+71
-1
lines changed

4 files changed

+71
-1
lines changed

blog/static/blog/css/friendly.css

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
.codehilite .hll { background-color: #ffffcc }
2+
.codehilite .c { color: #60a0b0; font-style: italic } /* Comment */
3+
.codehilite .err { border: 1px solid #FF0000 } /* Error */
4+
.codehilite .k { color: #007020; font-weight: bold } /* Keyword */
5+
.codehilite .o { color: #666666 } /* Operator */
6+
.codehilite .cm { color: #60a0b0; font-style: italic } /* Comment.Multiline */
7+
.codehilite .cp { color: #007020 } /* Comment.Preproc */
8+
.codehilite .c1 { color: #60a0b0; font-style: italic } /* Comment.Single */
9+
.codehilite .cs { color: #60a0b0; background-color: #fff0f0 } /* Comment.Special */
10+
.codehilite .gd { color: #A00000 } /* Generic.Deleted */
11+
.codehilite .ge { font-style: italic } /* Generic.Emph */
12+
.codehilite .gr { color: #FF0000 } /* Generic.Error */
13+
.codehilite .gh { color: #000080; font-weight: bold } /* Generic.Heading */
14+
.codehilite .gi { color: #00A000 } /* Generic.Inserted */
15+
.codehilite .go { color: #808080 } /* Generic.Output */
16+
.codehilite .gp { color: #c65d09; font-weight: bold } /* Generic.Prompt */
17+
.codehilite .gs { font-weight: bold } /* Generic.Strong */
18+
.codehilite .gu { color: #800080; font-weight: bold } /* Generic.Subheading */
19+
.codehilite .gt { color: #0040D0 } /* Generic.Traceback */
20+
.codehilite .kc { color: #007020; font-weight: bold } /* Keyword.Constant */
21+
.codehilite .kd { color: #007020; font-weight: bold } /* Keyword.Declaration */
22+
.codehilite .kn { color: #007020; font-weight: bold } /* Keyword.Namespace */
23+
.codehilite .kp { color: #007020 } /* Keyword.Pseudo */
24+
.codehilite .kr { color: #007020; font-weight: bold } /* Keyword.Reserved */
25+
.codehilite .kt { color: #902000 } /* Keyword.Type */
26+
.codehilite .m { color: #40a070 } /* Literal.Number */
27+
.codehilite .s { color: #4070a0 } /* Literal.String */
28+
.codehilite .na { color: #4070a0 } /* Name.Attribute */
29+
.codehilite .nb { color: #007020 } /* Name.Builtin */
30+
.codehilite .nc { color: #0e84b5; font-weight: bold } /* Name.Class */
31+
.codehilite .no { color: #60add5 } /* Name.Constant */
32+
.codehilite .nd { color: #555555; font-weight: bold } /* Name.Decorator */
33+
.codehilite .ni { color: #d55537; font-weight: bold } /* Name.Entity */
34+
.codehilite .ne { color: #007020 } /* Name.Exception */
35+
.codehilite .nf { color: #06287e } /* Name.Function */
36+
.codehilite .nl { color: #002070; font-weight: bold } /* Name.Label */
37+
.codehilite .nn { color: #0e84b5; font-weight: bold } /* Name.Namespace */
38+
.codehilite .nt { color: #062873; font-weight: bold } /* Name.Tag */
39+
.codehilite .nv { color: #bb60d5 } /* Name.Variable */
40+
.codehilite .ow { color: #007020; font-weight: bold } /* Operator.Word */
41+
.codehilite .w { color: #bbbbbb } /* Text.Whitespace */
42+
.codehilite .mf { color: #40a070 } /* Literal.Number.Float */
43+
.codehilite .mh { color: #40a070 } /* Literal.Number.Hex */
44+
.codehilite .mi { color: #40a070 } /* Literal.Number.Integer */
45+
.codehilite .mo { color: #40a070 } /* Literal.Number.Oct */
46+
.codehilite .sb { color: #4070a0 } /* Literal.String.Backtick */
47+
.codehilite .sc { color: #4070a0 } /* Literal.String.Char */
48+
.codehilite .sd { color: #4070a0; font-style: italic } /* Literal.String.Doc */
49+
.codehilite .s2 { color: #4070a0 } /* Literal.String.Double */
50+
.codehilite .se { color: #4070a0; font-weight: bold } /* Literal.String.Escape */
51+
.codehilite .sh { color: #4070a0 } /* Literal.String.Heredoc */
52+
.codehilite .si { color: #70a0d0; font-style: italic } /* Literal.String.Interpol */
53+
.codehilite .sx { color: #c65d09 } /* Literal.String.Other */
54+
.codehilite .sr { color: #235388 } /* Literal.String.Regex */
55+
.codehilite .s1 { color: #4070a0 } /* Literal.String.Single */
56+
.codehilite .ss { color: #517918 } /* Literal.String.Symbol */
57+
.codehilite .bp { color: #007020 } /* Name.Builtin.Pseudo */
58+
.codehilite .vc { color: #bb60d5 } /* Name.Variable.Class */
59+
.codehilite .vg { color: #bb60d5 } /* Name.Variable.Global */
60+
.codehilite .vi { color: #bb60d5 } /* Name.Variable.Instance */
61+
.codehilite .il { color: #40a070 } /* Literal.Number.Integer.Long */

blog/views.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import markdown
2+
13
from django.shortcuts import render, get_object_or_404
24

35
from .models import Post
@@ -25,4 +27,10 @@ def index(request):
2527

2628
def detail(request, pk):
2729
post = get_object_or_404(Post, pk=pk)
30+
post.body = markdown.markdown(post.body,
31+
extensions=[
32+
'markdown.extensions.extra',
33+
'markdown.extensions.codehilite',
34+
'markdown.extensions.toc',
35+
])
2836
return render(request, 'blog/detail.html', context={'post': post})

templates/base.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
<link rel="stylesheet" href="http://code.ionicframework.com/ionicons/2.0.1/css/ionicons.min.css">
1414
<link rel="stylesheet" href="{% static 'blog/css/pace.css' %}">
1515
<link rel="stylesheet" href="{% static 'blog/css/custom.css' %}">
16+
<link rel="stylesheet" href="{% static 'blog/css/friendly.css' %}">
1617
<!-- js -->
1718
<script src="{% static 'blog/js/jquery-2.1.3.min.js' %}"></script>
1819
<script src="{% static 'blog/js/bootstrap.min.js' %}"></script>

templates/blog/detail.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ <h1 class="entry-title">{{ post.title }}</h1>
1616
</div>
1717
</header>
1818
<div class="entry-content clearfix">
19-
{{ post.body }}
19+
{{ post.body|safe }}
2020
</div>
2121
</article>
2222
{% endblock main %}

0 commit comments

Comments
 (0)