django-summernote 帮助添加代码镜像

django-summernote Help Adding Code Mirror

我访问了 http://summernote.org/examples/#codemirror-as-codeview,但我仍然无法让 codemirror 工作。我从所有 codemirror css 和 javascript 收到了 200 个响应,但是当我按代码视图时我仍然得到空白。这是我的 SUMMER_NOTE 配置。

SUMMERNOTE_CONFIG = {
    'toolbar': [
        ['cmds', ['undo', 'redo', 'clear']],
        ['style', ['style']],
        ['font', ['bold', 'italic', 'underline', 'strikethrough']],
        ['font2', ['superscript', 'subscript']],
        ['color', ['color']],
        ['para', ['ul','ol']],
        ['layout', ['hr', 'table']],
        ['insert', ['link', 'picture']],
        ['misc', ['codeview']],
    ],
    'width': '100%',
    'css': (
        '//cdnjs.cloudflare.com/ajax/libs/codemirror/3.20.0/codemirror.css',
        '//cdnjs.cloudflare.com/ajax/libs/codemirror/3.20.0/theme/monokai.css',
    ),
    'js': (
        '//cdnjs.cloudflare.com/ajax/libs/codemirror/3.20.0/codemirror.js',
        '//cdnjs.cloudflare.com/ajax/libs/codemirror/3.20.0/mode/xml/xml.js',
        '//cdnjs.cloudflare.com/ajax/libs/codemirror/2.36.0/formatting.js',
    ),
    'codemirror': {
        'theme': 'monokai',
    }
}

这是正确的配置方式吗?

我发现 jsdefault_js 之后加载,所以你必须在 summernote.min.js 之前加载所有 codemirror 脚本。这是 <iframe> 中的 <head> 标签以两种方式加载这些文件,我添加了注释。

<!-- Loaded via js and css (doesn't work) -->
<head>
  <title>django-summernote frame</title>
  <!-- From default_css -->
    <link href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet">
    <link href="/static/django_summernote/summernote.css" rel="stylesheet">
    <link href="/static/django_summernote/django_summernote.css" rel="stylesheet">
  <!-- End default_css -->
  <!-- From css -->
    <link href="//cdnjs.cloudflare.com/ajax/libs/codemirror/3.20.0/codemirror.css" rel="stylesheet">
    <link href="//cdnjs.cloudflare.com/ajax/libs/codemirror/3.20.0/theme/monokai.css" rel="stylesheet">
  <!-- end css -->
  <!-- From default_js -->
    <script src="//code.jquery.com/jquery-1.9.1.min.js"></script>
    <script src="//netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>
    <script src="/static/django_summernote/jquery.ui.widget.js"></script>
    <script src="/static/django_summernote/jquery.iframe-transport.js"></script>
    <script src="/static/django_summernote/jquery.fileupload.js"></script>
    <script src="/static/django_summernote/summernote.min.js"></script>
  <!-- end default_js -->
  <!-- From js -->
    <script src="//cdnjs.cloudflare.com/ajax/libs/codemirror/3.20.0/codemirror.js"></script>
    <script src="//cdnjs.cloudflare.com/ajax/libs/codemirror/3.20.0/mode/xml/xml.js"></script>
    <script src="//cdnjs.cloudflare.com/ajax/libs/codemirror/2.36.0/formatting.js"></script>
  <!-- end js -->
</head>

<!-- Loaded via default_js and default_css (works) -->
<head>
  <title>django-summernote frame</title>
  <!-- From default_css -->
    <link href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet">
    <link href="//cdnjs.cloudflare.com/ajax/libs/codemirror/3.20.0/codemirror.css" rel="stylesheet">
    <link href="//cdnjs.cloudflare.com/ajax/libs/codemirror/3.20.0/theme/monokai.css" rel="stylesheet">
    <link href="/static/django_summernote/summernote.css" rel="stylesheet">
    <link href="/static/django_summernote/django_summernote.css" rel="stylesheet">
  <!-- end default_css -->
  <!-- From default_js -->  
    <script src="//code.jquery.com/jquery-1.9.1.min.js"></script>
    <script src="//netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>
    <script src="//cdnjs.cloudflare.com/ajax/libs/codemirror/3.20.0/codemirror.js"></script>
    <script src="//cdnjs.cloudflare.com/ajax/libs/codemirror/3.20.0/mode/xml/xml.js"></script>
    <script src="//cdnjs.cloudflare.com/ajax/libs/codemirror/2.36.0/formatting.js"></script>
    <script src="/static/django_summernote/jquery.ui.widget.js"></script>
    <script src="/static/django_summernote/jquery.iframe-transport.js"></script>
    <script src="/static/django_summernote/jquery.fileupload.js"></script>
    <script src="/static/django_summernote/summernote.min.js"></script>
  <!-- end default_js -->
</head>

所以我能够通过构建我的 SUMMERNOTE_CONFIG 使其工作:

SUMMERNOTE_CONFIG = {
    'toolbar': [
        ['cmds', ['undo', 'redo', 'clear']],
        ['style', ['style']],
        ['font', ['bold', 'italic', 'underline', 'strikethrough']],
        ['font2', ['superscript', 'subscript']],
        ['color', ['color']],
        ['para', ['ul','ol']],
        ['layout', ['hr', 'table']],
        ['insert', ['link', 'picture']],
        ['misc', ['codeview']],
    ],
    'width': '100%',
    'css': (
        '//cdnjs.cloudflare.com/ajax/libs/codemirror/3.20.0/codemirror.css',
        '//cdnjs.cloudflare.com/ajax/libs/codemirror/3.20.0/theme/monokai.css',
    ),
    'default_js': (
        '//code.jquery.com/jquery-1.9.1.min.js',
        '//netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js',
        '//cdnjs.cloudflare.com/ajax/libs/codemirror/3.20.0/codemirror.js',
        '//cdnjs.cloudflare.com/ajax/libs/codemirror/3.20.0/mode/xml/xml.js',
        '//cdnjs.cloudflare.com/ajax/libs/codemirror/2.36.0/formatting.js',
        static_url('django_summernote/jquery.ui.widget.js'),
        static_url('django_summernote/jquery.iframe-transport.js'),
        static_url('django_summernote/jquery.fileupload.js'),
        static_url('django_summernote/summernote.min.js'),
    ),
    'codemirror': {
        'theme': 'monokai',
    }
}

P.S。 static_url is defined locally.