【问题标题】:How to show code blocks for programming snippets in Django Summernote?如何在 Django Summernote 中显示编程片段的代码块?
【发布时间】:2020-12-09 11:34:49
【问题描述】:

我在 website 上使用 Django Summernote。这就是编辑器的外观。 您可以在下面找到我的 Summernote 编辑器的 django 设置。

SUMMERNOTE_CONFIG = {
    # Or, you can set it as False to use SummernoteInplaceWidget by default - no iframe mode
    # In this case, you have to load Bootstrap/jQuery stuff by manually.
    # Use this when you're already using Bootstraip/jQuery based themes.
    'iframe': False,

    # You can put custom Summernote settings
    'summernote': {
        # As an example, using Summernote Air-mode
        'airMode': False,

        # Change editor size
        'width': '100%',
        'height': '480',

        'toolbar': [
            ['style', ['style']],
            ['font', ['bold', 'underline', 'clear']],
            ['fontname', ['fontname']],
            ['color', ['color']],
            ['para', ['ul', 'ol', 'paragraph']],
            ['table', ['table']],
            ['insert', ['link', 'picture', 'video']],
            ['view', ['fullscreen', 'codeview', 'help']],
        ],

        

        'codemirror': {
            'mode': 'htmlmixed',
            'lineNumbers': 'true',
            # You have to include theme file in 'css' or 'css_for_inplace' before using it.
            'theme': 'monokai',
        },

    }
}

但遗憾的是,它没有代码块选项来显示编程sn-ps。我在这里做错了什么?

【问题讨论】:

    标签: django summernote


    【解决方案1】:

    我遇到了同样的问题,您必须在 settings.py 文件中切换(降级)以引导 3:

        SUMMERNOTE_THEME = 'bs3'
    

    我不知道为什么 bs4 没有这种内置风格。如果你坚持使用 bs4,你必须使用 django summernote 的外部插件,并在你的 settings.py 中再次编辑 Summernote 配置:

    SUMMERNOTE_CONFIG = { 
        
        'summernote' : {
            'width': '100%',
            'height': '720',
    
        'codemirror': {
            'mode': 'htmlmixed',
            'lineNumbers': 'true',
    }
    }
    }
    

    此示例用于将 codemirror 外部插件与 Summernote 一起使用(并更改字段的大小)

    【讨论】:

      【解决方案2】:

      Django Summernote 已经有一个内置的代码格式

      尝试在您的 django 项目中重新安装 django summernote,并确保您在他们的GitHub Repository 中获得了正确说明的所有设置说明

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2018-03-02
        • 1970-01-01
        • 2022-10-05
        • 2017-03-24
        • 1970-01-01
        • 2021-06-22
        • 1970-01-01
        • 2021-08-14
        相关资源
        最近更新 更多