Skip to content

Commit 1981e6a

Browse files
committed
update readme docs template
1 parent d91d01c commit 1981e6a

File tree

9 files changed

+128
-22
lines changed

9 files changed

+128
-22
lines changed

README.rst

Lines changed: 83 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,11 +172,11 @@ to get ``IMGUR_CLIENT_ID`` and ``IMGUR_API_KEY``.
172172
MARTOR_MARKDOWN_BASE_EMOJI_URL = 'https://github.githubassets.com/images/icons/emoji/' # default from github
173173
MARTOR_MARKDOWN_BASE_MENTION_URL = 'https://python.web.id/author/' # please change this to your domain
174174

175-
# If you need to use your own themed semantic ui dependency
175+
# If you need to use your own themed "bootstrap" or "semantic ui" dependency
176176
# replace the values with the file in your static files dir
177177
MARTOR_ALTERNATIVE_JS_FILE_THEME = "semantic-themed/semantic.min.js" # default None
178178
MARTOR_ALTERNATIVE_CSS_FILE_THEME = "semantic-themed/semantic.min.css" # default None
179-
MARTOR_ALTERNATIVE_JQUERY_JS_FILE = "jquery/dist/jquery.js" # default None
179+
MARTOR_ALTERNATIVE_JQUERY_JS_FILE = "jquery/dist/jquery.min.js" # default None
180180

181181
Check this setting is not set else csrf will not be sent over ajax calls:
182182

@@ -229,7 +229,7 @@ Usage
229229
admin.site.register(YourModel, YourModelAdmin)
230230

231231

232-
**Template**
232+
**Template Renderer**
233233

234234
Simply safely parse markdown content as html ouput by loading templatetags from ``martor/templatetags/martortags.py``.
235235

@@ -242,6 +242,85 @@ Simply safely parse markdown content as html ouput by loading templatetags from
242242
{{ post.description|safe_markdown }}
243243

244244

245+
Don't miss to include the required css & js files before use.
246+
You can take a look at this folder `martor_demo/app/templates`_ for more details.
247+
The below example is a one of the way to implement it when you choose the ``MARTOR_THEME = 'bootstrap'``:
248+
249+
::
250+
251+
{% extends "bootstrap/base.html" %}
252+
{% load static %}
253+
{% load martortags %}
254+
255+
{% block css %}
256+
<link href="{% static 'plugins/css/ace.min.css' %}" type="text/css" media="all" rel="stylesheet" />
257+
<link href="{% static 'martor/css/martor.bootstrap.min.css' %}" type="text/css" media="all" rel="stylesheet" />
258+
{% endblock %}
259+
260+
{% block content %}
261+
<div class="martor-preview">
262+
<h1>Title: {{ post.title }}</h1>
263+
<p><b>Description:</b></p>
264+
<hr />
265+
{{ post.description|safe_markdown }}
266+
</div>
267+
{% endblock %}
268+
269+
{% block js %}
270+
<script type="text/javascript" src="{% static 'plugins/js/highlight.min.js' %}"></script>
271+
<script>
272+
$('.martor-preview pre').each(function(i, block){
273+
hljs.highlightBlock(block);
274+
});
275+
</script>
276+
{% endblock %}
277+
278+
279+
**Template Editor Form**
280+
281+
Different with *Template Renderer*, the *Template Editor Form* have more css & javascript dependencies.
282+
283+
::
284+
285+
{% extends "bootstrap/base.html" %}
286+
{% load static %}
287+
288+
{% block css %}
289+
<link href="{% static 'plugins/css/ace.min.css' %}" type="text/css" media="all" rel="stylesheet" />
290+
<link href="{% static 'plugins/css/resizable.min.css' %}" type="text/css" media="all" rel="stylesheet" />
291+
<link href="{% static 'martor/css/martor.bootstrap.min.css' %}" type="text/css" media="all" rel="stylesheet" />
292+
{% endblock %}
293+
294+
{% block content %}
295+
<form class="form" method="post">{% csrf_token %}
296+
<div class="form-group">
297+
{{ form.title }}
298+
</div>
299+
<div class="form-group">
300+
{{ form.description }}
301+
</div>
302+
<div class="form-group">
303+
<button class="btn btn-success">
304+
<i class="save icon"></i> Save Post
305+
</button>
306+
</div>
307+
</form>
308+
{% endblock %}
309+
310+
{% block js %}
311+
<script type="text/javascript" src="{% static 'plugins/js/ace.js' %}"></script>
312+
<script type="text/javascript" src="{% static 'plugins/js/mode-markdown.js' %}"></script>
313+
<script type="text/javascript" src="{% static 'plugins/js/ext-language_tools.js' %}"></script>
314+
<script type="text/javascript" src="{% static 'plugins/js/theme-github.js' %}"></script>
315+
<script type="text/javascript" src="{% static 'plugins/js/typo.js' %}"></script>
316+
<script type="text/javascript" src="{% static 'plugins/js/spellcheck.js' %}"></script>
317+
<script type="text/javascript" src="{% static 'plugins/js/highlight.min.js' %}"></script>
318+
<script type="text/javascript" src="{% static 'plugins/js/resizable.min.js' %}"></script>
319+
<script type="text/javascript" src="{% static 'plugins/js/emojis.min.js' %}"></script>
320+
<script type="text/javascript" src="{% static 'martor/js/martor.bootstrap.min.js' %}"></script>
321+
{% endblock %}
322+
323+
245324
Custom Uploader
246325
-----------------
247326

@@ -285,5 +364,6 @@ Notes
285364
.. _Python Markdown: https://github.com/waylan/Python-Markdown
286365
.. _Online reStructuredText editor: http://rst.ninjs.org
287366
.. _WIKI: https://github.com/agusmakmun/django-markdown-editor/wiki
367+
.. _martor_demo/app/templates: https://github.com/agusmakmun/django-markdown-editor/tree/master/martor_demo/app/templates
288368
.. _fixed this issue: https://github.com/agusmakmun/django-markdown-editor/issues/3
289369
.. _custom uploader: https://github.com/agusmakmun/django-markdown-editor/wiki

martor_demo/app/admin.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,5 @@ class PostAdmin(admin.ModelAdmin):
1414
models.TextField: {'widget': AdminMartorWidget},
1515
}
1616

17+
1718
admin.site.register(Post, PostAdmin)

martor_demo/app/templates/bootstrap/test_markdownify.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ <h1>Title: {{ post.title }}</h1>
2020
{% block js %}
2121
<script type="text/javascript" src="{% static 'plugins/js/highlight.min.js' %}"></script>
2222
<script>
23-
$('pre').each(function(i, block){
23+
$('.martor-preview pre').each(function(i, block){
2424
hljs.highlightBlock(block);
2525
});
2626
</script>

martor_demo/app/templates/semantic/test_markdownify.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ <h1>Title: {{ post.title }}</h1>
2222
{% block js %}
2323
<script type="text/javascript" src="{% static 'plugins/js/highlight.min.js' %}"></script>
2424
<script>
25-
$('pre').each(function(i, block){
25+
$('.martor-preview pre').each(function(i, block){
2626
hljs.highlightBlock(block);
2727
});
2828
</script>

martor_demo/manage.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
#!/usr/bin/env python
2+
"""Django's command-line utility for administrative tasks."""
23
import os
34
import sys
45

5-
if __name__ == "__main__":
6-
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "martor_demo.settings")
6+
7+
def main():
8+
"""Run administrative tasks."""
9+
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'martor_demo.settings')
710
try:
811
from django.core.management import execute_from_command_line
912
except ImportError as exc:
@@ -13,3 +16,7 @@
1316
"forget to activate a virtual environment?"
1417
) from exc
1518
execute_from_command_line(sys.argv)
19+
20+
21+
if __name__ == '__main__':
22+
main()

martor_demo/martor_demo/asgi.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
"""
2+
ASGI config for martor_demo project.
3+
4+
It exposes the ASGI callable as a module-level variable named ``application``.
5+
6+
For more information on this file, see
7+
https://docs.djangoproject.com/en/3.1/howto/deployment/asgi/
8+
"""
9+
10+
import os
11+
12+
from django.core.asgi import get_asgi_application
13+
14+
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'martor_demo.settings')
15+
16+
application = get_asgi_application()

martor_demo/martor_demo/settings.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,28 @@
11
"""
22
Django settings for martor_demo project.
33
4-
Generated by 'django-admin startproject' using Django 3.0.2.
4+
Generated by 'django-admin startproject' using Django 3.1.1.
55
66
For more information on this file, see
7-
https://docs.djangoproject.com/en/3.0/topics/settings/
7+
https://docs.djangoproject.com/en/3.1/topics/settings/
88
99
For the full list of settings and their values, see
10-
https://docs.djangoproject.com/en/3.0/ref/settings/
10+
https://docs.djangoproject.com/en/3.1/ref/settings/
1111
"""
1212

1313
import os
1414
import tempfile
15+
from pathlib import Path
1516

16-
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
17-
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
17+
# Build paths inside the project like this: BASE_DIR / 'subdir'.
18+
BASE_DIR = Path(__file__).resolve().parent.parent
1819

1920

2021
# Quick-start development settings - unsuitable for production
21-
# See https://docs.djangoproject.com/en/3.0/howto/deployment/checklist/
22+
# See https://docs.djangoproject.com/en/3.1/howto/deployment/checklist/
2223

2324
# SECURITY WARNING: keep the secret key used in production secret!
24-
SECRET_KEY = '93fs*#h77*vj&2#2f+!y=kifg0s&63768398a(kx126itq(*6r'
25+
SECRET_KEY = '+1zhx_fpkkyj&z+3n!63fx0)og)@h5^7qyr8e0s%c@p8_&t&+l'
2526

2627
# SECURITY WARNING: don't run with debug turned on in production!
2728
DEBUG = True
@@ -91,18 +92,18 @@
9192

9293

9394
# Database
94-
# https://docs.djangoproject.com/en/3.0/ref/settings/#databases
95+
# https://docs.djangoproject.com/en/3.1/ref/settings/#databases
9596

9697
DATABASES = {
9798
'default': {
9899
'ENGINE': 'django.db.backends.sqlite3',
99-
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
100+
'NAME': BASE_DIR / 'db.sqlite3',
100101
}
101102
}
102103

103104

104105
# Password validation
105-
# https://docs.djangoproject.com/en/3.0/ref/settings/#auth-password-validators
106+
# https://docs.djangoproject.com/en/3.1/ref/settings/#auth-password-validators
106107

107108
AUTH_PASSWORD_VALIDATORS = [
108109
{
@@ -121,7 +122,7 @@
121122

122123

123124
# Internationalization
124-
# https://docs.djangoproject.com/en/3.0/topics/i18n/
125+
# https://docs.djangoproject.com/en/3.1/topics/i18n/
125126

126127
LANGUAGE_CODE = 'en-us'
127128

@@ -135,7 +136,8 @@
135136

136137

137138
# Static files (CSS, JavaScript, Images)
138-
# https://docs.djangoproject.com/en/3.0/howto/static-files/
139+
# https://docs.djangoproject.com/en/3.1/howto/static-files/
140+
139141

140142
STATIC_URL = '/static/'
141143
MEDIA_URL = '/media/'

martor_demo/martor_demo/urls.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""martor_demo URL Configuration
22
33
The `urlpatterns` list routes URLs to views. For more information please see:
4-
https://docs.djangoproject.com/en/3.0/topics/http/urls/
4+
https://docs.djangoproject.com/en/3.1/topics/http/urls/
55
Examples:
66
Function views
77
1. Add an import: from my_app import views

martor_demo/martor_demo/wsgi.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
It exposes the WSGI callable as a module-level variable named ``application``.
55
66
For more information on this file, see
7-
https://docs.djangoproject.com/en/3.0/howto/deployment/wsgi/
7+
https://docs.djangoproject.com/en/3.1/howto/deployment/wsgi/
88
"""
99

1010
import os
1111

1212
from django.core.wsgi import get_wsgi_application
1313

14-
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "martor_demo.settings")
14+
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'martor_demo.settings')
1515

1616
application = get_wsgi_application()

0 commit comments

Comments
 (0)