Skip to content

Commit f9d3c3c

Browse files
committed
Add markdown rendering for post content with professional styling
1 parent 6676291 commit f9d3c3c

5 files changed

Lines changed: 85 additions & 3 deletions

File tree

portfolio/static/post_details.css

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,65 @@ main code {
135135
background-color: #f4f4f4;
136136
padding: 0.2rem 0.4rem;
137137
border-radius: 4px;
138-
font-family: monospace;
138+
font-family: 'Courier New', monospace;
139+
font-size: 0.95rem;
140+
}
141+
142+
main pre {
143+
background-color: #1e1e1e;
144+
color: #d4d4d4;
145+
padding: 1rem;
146+
border-radius: 8px;
147+
overflow-x: auto;
148+
margin: 1.5rem 0;
149+
}
150+
151+
main pre code {
152+
background-color: transparent;
153+
color: inherit;
154+
padding: 0;
155+
}
156+
157+
main blockquote {
158+
border-left: 4px solid #390281;
159+
margin: 1.5rem 0;
160+
padding: 0.5rem 1rem;
161+
background-color: #f9f9f9;
162+
font-style: italic;
163+
}
164+
165+
main table {
166+
width: 100%;
167+
border-collapse: collapse;
168+
margin: 1.5rem 0;
169+
}
170+
171+
main th, main td {
172+
border: 1px solid #ddd;
173+
padding: 0.75rem;
174+
text-align: left;
175+
}
176+
177+
main th {
178+
background-color: #390281;
179+
color: white;
180+
}
181+
182+
main tr:nth-child(even) {
183+
background-color: #f9f9f9;
184+
}
185+
186+
main hr {
187+
border: none;
188+
border-top: 2px solid #eee;
189+
margin: 2rem 0;
190+
}
191+
192+
.post-content img {
193+
max-width: 100%;
194+
height: auto;
195+
border-radius: 8px;
196+
margin: 1rem 0;
139197
}
140198

141199
.tag {

portfolio/templates/portfolio/post_details.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{% extends 'base.html' %}
22

33
{% load static %}
4+
{% load markdown_extras %}
45

56
{% block title %}{{post.title}}{% endblock %}
67

@@ -56,8 +57,8 @@ <h2>{{post.title}}</h2>
5657
</address>
5758
</article>
5859
</section>
59-
<main>
60-
{{post.content|urlize|linebreaks}}
60+
<main class="post-content">
61+
{{post.content|markdown}}
6162
<br><br>
6263
<a href ="{% url 'posts' %}" class="center">Back to all posts</a>
6364
</main>

portfolio/templatetags/__init__.py

Whitespace-only changes.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import markdown
2+
from django import template
3+
from django.utils.safestring import mark_safe
4+
5+
register = template.Library()
6+
7+
8+
@register.filter(name='markdown')
9+
def markdown_format(text):
10+
"""Convert markdown text to HTML."""
11+
if not text:
12+
return ''
13+
14+
# Configure markdown with useful extensions
15+
md = markdown.Markdown(extensions=[
16+
'markdown.extensions.fenced_code',
17+
'markdown.extensions.tables',
18+
'markdown.extensions.nl2br',
19+
'markdown.extensions.sane_lists',
20+
])
21+
22+
return mark_safe(md.convert(text))

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@ sqlparse==0.5.1
1414
typing_extensions==4.12.2
1515
urllib3==2.2.2
1616
whitenoise==6.4.0
17+
markdown==3.5.1

0 commit comments

Comments
 (0)