社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
Py学习  »  问与答

Django中我使用markdown2+pygments没有代码块效果

永不停息的恐龙哥-weibo • 10 年前 • 8035 次点击  

为了能够使用```语法, 四个空格实在是太反人类了, 我使用了markdown2,(这个语法是GFM中的)

然后使用了pygments css样式, 但是最终效果是只能代码高亮, 还没有明显的代码块效果,

背景颜色无法区分

import markdown2

from django import template
from django.template.defaultfilters import stringfilter
from django.utils.encoding import force_text
from django.utils.safestring import mark_safe

register = template.Library()


@register.filter(is_safe=True)
@stringfilter
def custom_markdown(value):
   return mark_safe(markdown2.markdown(force_text(value),
          extras=["fenced-code-blocks", "cuddled-lists", "metadata", "tables", "spoiler"]))

最后是生成效果, 生成后是下图左边的情况, 但是我希望是下图右边的情况,

为什么没有了背景色

enter image description here

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/874
 
8035 次点击  
文章 [ 2 ]  |  最新文章 10 年前