Skip to content

Commit 9372327

Browse files
committed
added feature dractags & demo
1 parent bc1b072 commit 9372327

File tree

7 files changed

+145
-14
lines changed

7 files changed

+145
-14
lines changed

README.rst

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,9 @@ Setting Configurations ``settings.py``
114114
'markdown.extensions.fenced_code',
115115

116116
# Custom markdown extensions.
117-
'draceditor.utils.extensions.urlize',
118-
'draceditor.utils.extensions.mention', # require for mention
119-
'draceditor.utils.extensions.emoji', # require for emoji
117+
'draceditor.extensions.urlize',
118+
'draceditor.extensions.mention', # require for mention
119+
'draceditor.extensions.emoji', # require for emoji
120120
]
121121

122122
# Markdown Extensions Configs
@@ -174,6 +174,36 @@ Usage
174174
admin.site.register(YourModel, YourModelAdmin)
175175

176176

177+
**Template**
178+
179+
Simply safe the markdown content as html ouput with loading the templatetags from ``draceditor/templatetags/dractags.py``.
180+
181+
::
182+
183+
{% load dractags %}
184+
{{ field_name|safe_markdown }}
185+
186+
# example
187+
{{ post.description|safe_markdown }}
188+
189+
190+
Test Draceditor from this Repository
191+
-------------------------------------
192+
193+
I assume you already setup with virtual enviroment (virtualenv).
194+
195+
::
196+
197+
$ git clone https://github.com/agusmakmun/dracos-markdown-editor.git
198+
$ cd dracos-markdown-editor/ && python setup.py install
199+
$ cd draceditor_demo/
200+
$ python manage.py makemigrations && python manage.py migrate
201+
$ python manage.py runserver
202+
203+
204+
And let checkout at http://127.0.0.1:8000/simple-form/ to your browser.
205+
206+
177207
Draceditor Commands Refference
178208
--------------------------------
179209

draceditor/templatetags/__init__.py

Whitespace-only changes.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
from django import template
2+
from django.utils.safestring import mark_safe
3+
4+
from ..utils import markdownify
5+
6+
register = template.Library()
7+
8+
9+
@register.filter
10+
def safe_markdown(field_name):
11+
"""
12+
Safe the markdown text as html ouput.
13+
14+
Usage:
15+
{% load dractags %}
16+
{{ field_name|safe_markdown }}
17+
18+
Example:
19+
{{ post.description|safe_markdown }}
20+
"""
21+
return mark_safe(markdownify(field_name))

draceditor_demo/app/templates/base.html

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
<title>{% block title %}{% endblock %} :: DracEditor</title>
55

66
<link href="{% static 'plugins/css/ace.min.css' %}" type="text/css" media="all" rel="stylesheet" />
7-
<link href="{% static 'plugins/css/atwho.css' %}" type="text/css" media="all" rel="stylesheet" />
87
<link href="{% static 'plugins/css/semantic.min.css' %}" type="text/css" media="all" rel="stylesheet" />
98
<link href="{% static 'css/draceditor.css' %}" type="text/css" media="all" rel="stylesheet" />
109
<style>
@@ -22,16 +21,12 @@
2221
<i class="github icon"></i> Github
2322
</a>
2423
<a class="item" href="https://dracos-linux.org"><i class="spy icon"></i> Dracos Linux</a>
25-
<div class="ui dropdown item" tabindex="0">Dropdown
24+
<div class="ui dropdown item" tabindex="0">Choice Demo
2625
<i class="dropdown icon"></i>
2726
<div class="menu transition hidden" tabindex="-1">
28-
<div class="item">Action</div>
29-
<div class="item">Another Action</div>
30-
<div class="item">Something else here</div>
31-
<div class="divider"></div>
32-
<div class="item">Separated Link</div>
33-
<div class="divider"></div>
34-
<div class="item">One more separated link</div>
27+
<a href="{% url 'simple_form' %}" class="item">Simple Form</a>
28+
<a href="{% url 'post_form' %}" class="item">Post Form</a>
29+
<a href="{% url 'test_markdownify' %}" class="item">Test Markdownify</a>
3530
</div>
3631
</div>
3732
<div class="right menu">
@@ -58,7 +53,6 @@
5853
<script type="text/javascript" src="{% static 'plugins/js/mode-markdown.js' %}"></script>
5954
<script type="text/javascript" src="{% static 'plugins/js/ext-language_tools.js' %}"></script>
6055
<script type="text/javascript" src="{% static 'plugins/js/theme-github.js' %}"></script>
61-
<script type="text/javascript" src="{% static 'plugins/js/marked.min.js' %}"></script>
6256
<script type="text/javascript" src="{% static 'plugins/js/highlight.min.js' %}"></script>
6357
<script type="text/javascript" src="{% static 'plugins/js/emojis.min.js' %}"></script>
6458
<script type="text/javascript" src="{% static 'js/draceditor.js' %}"></script>
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
{% load staticfiles %}
2+
{% load dractags %}
3+
<!DOCTYPE html>
4+
<html lang="en-us">
5+
<head>
6+
<title>Test Markdonify :: DracEditor</title>
7+
<link href="{% static 'plugins/css/ace.min.css' %}" type="text/css" media="all" rel="stylesheet" />
8+
<link href="{% static 'plugins/css/semantic.min.css' %}" type="text/css" media="all" rel="stylesheet" />
9+
<style>
10+
.main-container {margin-top: 7em}
11+
</style>
12+
13+
<script type="text/javascript" src="{% static 'plugins/js/jquery.min.js' %}"></script>
14+
</head>
15+
<body>
16+
<header>
17+
<div class="ui fixed inverted menu">
18+
<div class="ui container">
19+
<div class="header item">DracEditor</div>
20+
<a class="item" href="https://github.com/agusmakmun/dracos-markdown-editor" target="_blank">
21+
<i class="github icon"></i> Github
22+
</a>
23+
<a class="item" href="https://dracos-linux.org"><i class="spy icon"></i> Dracos Linux</a>
24+
<div class="ui dropdown item" tabindex="0">Choice Demo
25+
<i class="dropdown icon"></i>
26+
<div class="menu transition hidden" tabindex="-1">
27+
<a href="{% url 'simple_form' %}" class="item">Simple Form</a>
28+
<a href="{% url 'post_form' %}" class="item">Post Form (login require)</a>
29+
<a href="{% url 'test_markdownify' %}" class="item">Test Markdownify</a>
30+
</div>
31+
</div>
32+
<div class="right menu">
33+
<div class="item">
34+
<div class="ui transparent inverted icon input">
35+
<i class="search icon"></i>
36+
<input type="text" placeholder="Search">
37+
</div>
38+
</div>
39+
<a class="item">Link</a>
40+
</div>
41+
</div>
42+
</div>
43+
</header>
44+
45+
<div class="ui container main-container">
46+
<div class="ui segment">
47+
<h1>Title: {{ post.title }}</h1>
48+
<p><b>Description:</b></p>
49+
<hr />
50+
{{ post.description|safe_markdown }}
51+
</div>
52+
</div>
53+
54+
<script type="text/javascript" src="{% static 'plugins/js/semantic.min.js' %}"></script>
55+
<script type="text/javascript" src="{% static 'plugins/js/highlight.min.js' %}"></script>
56+
<script>
57+
$('pre').each(function(i, block){
58+
hljs.highlightBlock(block);
59+
});
60+
$('.ui.dropdown').dropdown();
61+
</script>
62+
</body>
63+
</html>

draceditor_demo/app/urls.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
11
from django.conf.urls import url
22

3-
from app.views import (simple_form_view, post_form_view)
3+
from app.views import (
4+
simple_form_view,
5+
post_form_view,
6+
test_markdownify
7+
)
48

59
urlpatterns = [
610
url(r'^simple-form/$', simple_form_view, name='simple_form'),
711

812
# require to logged in
913
url(r'^post-form/$', post_form_view, name='post_form'),
14+
15+
# test markdownify
16+
url(r'^test-markdownify/$', test_markdownify, name='test_markdownify'),
1017
]

draceditor_demo/app/views.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from django.contrib.auth.decorators import login_required
44

55
from app.forms import (SimpleForm, PostForm)
6+
from app.models import Post
67

78

89
def simple_form_view(request):
@@ -24,3 +25,18 @@ def post_form_view(request):
2425
form = PostForm()
2526
context = {'form': form, 'title': 'Post Form'}
2627
return render(request, 'custom_form.html', context)
28+
29+
30+
def test_markdownify(request):
31+
post = Post.objects.last()
32+
33+
if post is not None:
34+
context = {'post': post}
35+
else:
36+
context = {
37+
'post': {
38+
'title': 'Fake Post',
39+
'description': """It **working**! :smile: [Python Learning](https://python.web.id)"""
40+
}
41+
}
42+
return render(request, 'test_markdownify.html', context)

0 commit comments

Comments
 (0)