-
Notifications
You must be signed in to change notification settings - Fork 109
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
69 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
# -*- coding:utf-8 -*- | ||
from django.conf import settings | ||
from django.core.exceptions import ImproperlyConfigured | ||
|
||
|
||
DEFAULT_CONFIG = { | ||
'width': '90%', | ||
'heigth': 500, | ||
'toolbar': ["undo", "redo", "|", | ||
"bold", "del", "italic", "quote", "ucwords", "uppercase", "lowercase", "|", | ||
"h1", "h2", "h3", "h5", "h6", "|", | ||
"list-ul", "list-ol", "hr", "|", | ||
"link", "reference-link", "image", "code", "preformatted-text", "code-block", "table", "datetime", | ||
"emoji", "html-entities", "pagebreak", "goto-line", "|", | ||
"help", "info", | ||
"||", "preview", "watch", "fullscreen"], | ||
'upload_image_formats': ["jpg", "JPG", "jpeg", "JPEG", "gif", "GIF", "png", | ||
"PNG", "bmp", "BMP", "webp", "WEBP"], | ||
'image_floder': 'editor', | ||
'theme': 'default', # dark / default | ||
'preview_theme': 'default', # dark / default | ||
'editor_theme': 'default', # pastel-on-dark / default | ||
'toolbar_autofixed': True, | ||
'search_replace': True, | ||
'emoji': True, | ||
'tex': True, | ||
'flow_chart': True, | ||
'sequence': True | ||
} | ||
|
||
|
||
class MDConfig(dict): | ||
|
||
def __init__(self, config_name='default'): | ||
self.update(DEFAULT_CONFIG) | ||
self.set_configs(config_name) | ||
|
||
def set_configs(self, config_name='default'): | ||
""" | ||
set config item | ||
:param config_name: | ||
:return: | ||
""" | ||
# Try to get valid config from settings. | ||
configs = getattr(settings, 'MDEDITOR_CONFIGS', None) | ||
if configs: | ||
if isinstance(configs, dict): | ||
# Make sure the config_name exists. | ||
if config_name in configs: | ||
config = configs[config_name] | ||
# Make sure the configuration is a dictionary. | ||
if not isinstance(config, dict): | ||
raise ImproperlyConfigured('MDEDITOR_CONFIGS["%s"] \ | ||
setting must be a dictionary type.' % | ||
config_name) | ||
# Override defaults with settings config. | ||
self.update(config) | ||
else: | ||
raise ImproperlyConfigured("No configuration named '%s' \ | ||
found in your CKEDITOR_CONFIGS setting." % | ||
config_name) | ||
else: | ||
raise ImproperlyConfigured('MDEDITOR_CONFIGS setting must be a\ | ||
dictionary type.') | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters