使用 wagtail BlockQuoteBlock 时如何断行? [英] How to break lines when using wagtail BlockQuoteBlock?
问题描述
我有这个模型:
from wagtail.wagtailcore import blocks
class BlogPage(Page):
date = models.DateField("Post date")
intro = RichTextField(blank=True)
body = StreamField([
('heading', blocks.CharBlock(classname="full title")),
('paragraph', blocks.RichTextBlock()),
('image', ImageChooserBlock()),
('code', CodeBlock()),
('markdown', MarkDownBlock()),
('media', TestMediaBlock(icon='media')),
('blockquote', blocks.BlockQuoteBlock())
])
当我使用 blockquote
保存带有一些文本的页面时,我使用了一些换行符甚至 <br>
标签:
When I'm saving page with some text using blockquote
I use some line breakes and even <br>
tags:
但是在页面上,它后面没有换行符:
But on the page there are no line breaks after it:
那么如何进行这项工作并保存换行符?我正在使用 wagtail 1.13.1
.
So how to make this work and save line breaks? I'm using wagtail 1.13.1
.
推荐答案
我认为这样做是出于安全原因.但是有可能解决这个问题 - 例如像这样重新定义 BlockQuoteBlock
:
I think it was done because of security reasons. But It is possible to solve the problem - redefine BlockQuoteBlock
for example like this:
from django.utils.safestring import mark_safe
from django.utils.html import format_html
from wagtail.wagtailcore import blocks
class BlockQuoteBlock(blocks.TextBlock):
def render_basic(self, value, context=None):
if value:
return format_html(
'<blockquote>{0}</blockquote>', mark_safe(value))
else:
return ''
class Meta:
icon = "openquote"
我已将 mark_safe()
函数添加到 原始实现.然后在模型中使用这个块,如果你这样做了,那么 <br>
标签开始工作
I've added mark_safe()
function to the original implementation. And then use this block in the model, if you do so, then <br>
tags begin to work
这篇关于使用 wagtail BlockQuoteBlock 时如何断行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!