Skip to content

Commit 64a2f3b

Browse files
authored
Merge branch 'master' into master
2 parents e50ca06 + eb2d3a8 commit 64a2f3b

File tree

9 files changed

+86
-42
lines changed

9 files changed

+86
-42
lines changed

martor/extensions/emoji.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import markdown
2-
from ..settings import (
3-
MARTOR_MARKDOWN_BASE_EMOJI_URL,
4-
MARTOR_MARKDOWN_BASE_EMOJI_USE_STATIC)
2+
53
try:
64
from django.contrib.staticfiles.templatetags.staticfiles import static
75
except ModuleNotFoundError:
86
from django.templatetags.static import static
97

8+
from ..settings import (MARTOR_MARKDOWN_BASE_EMOJI_URL,
9+
MARTOR_MARKDOWN_BASE_EMOJI_USE_STATIC)
10+
1011
"""
1112
>>> import markdown
1213
>>> md = markdown.Markdown(extensions=['martor.utils.extensions.emoji'])

martor/locale/en/LC_MESSAGES/django.po

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ msgstr ""
4949
#, python-format
5050
msgid ""
5151
"This site is powered by Markdown. For full documentation, <a href="
52-
"\"%(doc_url)s\" target=\"_blank\">click here</a>"
52+
"\"%(doc_url)s\" target=\"_blank\">click here</a>."
5353
msgstr ""
5454

5555
#: templates/martor/guide.html:10 templates/martor/toolbar.html:26

martor/locale/id/LC_MESSAGES/django.po

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,10 @@ msgstr "Bantuan Penggunaan Markdown"
4949
#, python-format
5050
msgid ""
5151
"This site is powered by Markdown. For full documentation, <a href="
52-
"\"%(doc_url)s\" target=\"_blank\">click here</a>"
52+
"\"%(doc_url)s\" target=\"_blank\">click here</a>."
5353
msgstr ""
5454
"Situs ini menggunakan Markdown. Untuk dokumentasi lengkapnya <a href="
55-
"\"%(doc_url)s\" target=\"_blank\">klik disini</a>"
55+
"\"%(doc_url)s\" target=\"_blank\">klik disini</a>."
5656

5757
#: templates/martor/guide.html:10 templates/martor/toolbar.html:26
5858
msgid "Code"

martor/settings.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
'mention': 'false', # to enable/disable mention
99
'jquery': 'true', # to include/revoke jquery (require for admin default django)
1010
'living': 'false', # to enable/disable live updates in preview
11-
'spellcheck': 'true', # to enable/disable spellcheck in form textareas
11+
'spellcheck': 'true', # to enable/disable spellcheck in form textareas
12+
'hljs': 'true', # to enable/disable hljs highlighting in preview
1213
}
1314
)
1415

martor/static/martor/css/martor.css

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,11 @@ form .martor-preview pre tt{margin:0;padding:0;background-color:transparent;bord
209209
.section-martor {
210210

211211
}
212+
213+
.section-martor div[data-tab="editor-tab-description"] {
214+
padding: 0 !important;
215+
}
216+
212217
.martor {
213218
height: 500px;
214219
max-height: 500px;
@@ -225,6 +230,10 @@ form .martor-preview {
225230
background: #F9F9F9;
226231
}
227232

233+
form .martor-preview-stale {
234+
background: repeating-linear-gradient(-45deg, #fff, #fff 10px, #f8f8f8 10px, #f8f8f8 20px) !important;
235+
}
236+
228237
.icon.expand-editor {
229238
position: absolute;
230239
bottom: .8em;

martor/static/martor/css/martor.min.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

martor/static/martor/js/martor.js

Lines changed: 61 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,7 @@
1111
$ = django.jQuery;
1212
}
1313
$.fn.martor = function() {
14-
15-
var martor = $(this);
16-
var mainMartor = $('.main-martor');
17-
18-
martor.trigger('martor.init');
14+
$('.martor').trigger('martor.init');
1915

2016
// CSRF code
2117
var getCookie = function(name) {
@@ -33,11 +29,12 @@
3329
}
3430
}
3531
return cookieValue;
36-
}
32+
};
3733

3834
// Each multiple editor fields
39-
mainMartor.each(function(i, obj) {
40-
var field_name = $(obj).data('field-name');
35+
this.each(function(i, obj) {
36+
var mainMartor = $(obj);
37+
var field_name = mainMartor.data('field-name');
4138
var textareaId = $('#id_'+field_name);
4239
var editorId = 'martor-'+field_name;
4340
var editor = ace.edit(editorId);
@@ -145,11 +142,17 @@
145142
// update the preview if this menu is clicked
146143
var currentTab = $('.tab.segment[data-tab=preview-tab-'+field_name+']');
147144
var previewTabButton = $('.item[data-tab=preview-tab-'+field_name+']');
145+
var needsRefresh = true;
148146
var refreshPreview = function() {
149-
var value = editor.getValue();
147+
if (!needsRefresh) {
148+
return;
149+
}
150+
151+
var value = textareaId.val();
150152
var form = new FormData();
151153
form.append('content', value);
152154
form.append('csrfmiddlewaretoken', getCookie('csrftoken'));
155+
currentTab.addClass('martor-preview-stale');
153156

154157
$.ajax({
155158
url: textareaId.data('markdownfy-url'),
@@ -158,22 +161,40 @@
158161
processData: false,
159162
contentType: false,
160163
success: function(response) {
161-
if(response){
162-
currentTab.html(response);
163-
$('pre').each(function(i, block){
164-
hljs.highlightBlock(block);
165-
});
166-
}else {currentTab.html('<p>Nothing to preview</p>');}
164+
if (response) {
165+
currentTab.html(response).removeClass('martor-preview-stale');
166+
if (editorConfig.hljs == 'true') {
167+
$('pre').each(function (i, block) {
168+
hljs.highlightBlock(block);
169+
});
170+
}
171+
needsRefresh = false;
172+
} else {
173+
currentTab.html('<p>Nothing to preview</p>');
174+
}
167175
},
168176
error: function(response) {
169177
console.log("error", response);
170178
}
171179
});
172180
};
173181

174-
if (editorConfig.living === 'true') {
175-
editor.on('change', refreshPreview);
176-
}else {
182+
// Refresh the preview unconditionally on first load.
183+
refreshPreview();
184+
185+
// Set if editor has changed.
186+
editor.on('change', function (evt) {
187+
var value = editor.getValue();
188+
if (value !== textareaId.val()) {
189+
textareaId.val(value);
190+
needsRefresh = true;
191+
if (editorConfig.living === 'true') {
192+
refreshPreview();
193+
}
194+
}
195+
});
196+
197+
if (editorConfig.living !== 'true') {
177198
previewTabButton.click(function(){
178199
// hide the `.martor-toolbar` for this current editor if under preview.
179200
$(this).closest('.tab-martor-menu').find('.martor-toolbar').hide();
@@ -760,8 +781,11 @@
760781
$('.modal-help-guide[data-field-name='+field_name+']').modal('show');
761782
});
762783

784+
// Handle tabs.
785+
mainMartor.find('.ui.martor-toolbar .ui.dropdown').dropdown();
786+
mainMartor.find('.ui.tab-martor-menu .item').tab();
787+
763788
// Toggle editor, preview, maximize
764-
var mainMartor = $(obj);
765789
var martorField = $('.martor-field-'+field_name);
766790
var btnToggleMaximize = $('.markdown-toggle-maximize[data-field-name='+field_name+']');
767791

@@ -837,14 +861,22 @@
837861
editor.setValue(textareaId.val(), -1);
838862
}
839863
});// end each `mainMartor`
840-
};
841-
$(function() {
842-
$('.martor').martor();
843-
});
864+
};
865+
866+
$(function() {
867+
$('.main-martor').martor();
868+
});
869+
870+
if ('django' in window && 'jQuery' in window.django)
871+
django.jQuery(document).on('formset:added', function (event, $row) {
872+
$row.find('.main-martor').each(function () {
873+
var id = $row.attr('id');
874+
id = id.substr(id.lastIndexOf('-') + 1);
875+
// Notice here we are using our jQuery instead of Django's.
876+
// This is because plugins are only loaded for ours.
877+
var fixed = $(this.outerHTML.replace(/__prefix__/g, id));
878+
$(this).replaceWith(fixed);
879+
fixed.martor();
880+
});
881+
});
844882
})(jQuery);
845-
846-
$( document ).ready(function(){
847-
// Semantic UI
848-
$('.ui.martor-toolbar .ui.dropdown').dropdown();
849-
$('.ui.tab-martor-menu .item').tab();
850-
});

martor/templates/martor/guide.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<i class="close icon"></i>
44
<div class="header"><i class="help circle icon"></i> {% trans "Markdown Guide" %}</div>
55
<div class="content">
6-
<p>{% blocktrans with doc_url='http://commonmark.org/help/' %}This site is powered by Markdown. For full documentation, <a href="{{ doc_url }}" target="_blank">click here</a>{% endblocktrans %}</p>
6+
<p>{% blocktrans with doc_url='http://commonmark.org/help/' %}This site is powered by Markdown. For full documentation, <a href="{{ doc_url }}" target="_blank">click here</a>.{% endblocktrans %}</p>
77
<table class="ui celled table markdown-reference">
88
<thead>
99
<tr>

martor_demo/martor_demo/settings.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,11 @@
2727
DEBUG = True
2828
ALLOWED_HOSTS = ['*']
2929
MARTOR_ENABLE_CONFIGS = {
30-
'imgur': 'true', # to enable/disable imgur/custom uploader.
31-
'mention': 'true', # to enable/disable mention
32-
'jquery': 'true', # to include/revoke jquery (require for admin default django)
33-
'living': 'false' # to enable/disable live updates in preview
30+
'imgur': 'true', # to enable/disable imgur/custom uploader.
31+
'mention': 'true', # to enable/disable mention
32+
'jquery': 'true', # to include/revoke jquery (require for admin default django)
33+
'living': 'false', # to enable/disable live updates in preview
34+
'spellcheck': 'true', # to enable/disable spellcheck in the editor.
3435
}
3536

3637
# Application definition

0 commit comments

Comments
 (0)