Setup features for richtext
This commit is contained in:
parent
bda2773b3d
commit
38c4c695cf
3 changed files with 206 additions and 1 deletions
|
@ -0,0 +1,94 @@
|
|||
# Generated by Django 4.0.5 on 2022-06-27 18:57
|
||||
|
||||
import wagtail.blocks
|
||||
import wagtail.embeds.blocks
|
||||
import wagtail.fields
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("blog", "0004_bloglistpage_body_blogpostpage_body"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name="bloglistpage",
|
||||
name="body",
|
||||
field=wagtail.fields.StreamField(
|
||||
[
|
||||
("embed", wagtail.embeds.blocks.EmbedBlock()),
|
||||
(
|
||||
"rich_text",
|
||||
wagtail.blocks.RichTextBlock(
|
||||
features=[
|
||||
"h1",
|
||||
"h2",
|
||||
"h3",
|
||||
"h4",
|
||||
"h5",
|
||||
"h6",
|
||||
"bold",
|
||||
"italic",
|
||||
"ol",
|
||||
"ul",
|
||||
"link",
|
||||
"document-link",
|
||||
"code",
|
||||
"strikethrough",
|
||||
]
|
||||
),
|
||||
),
|
||||
(
|
||||
"lorem",
|
||||
wagtail.blocks.StructBlock(
|
||||
[("paragraphs", wagtail.blocks.IntegerBlock(min_value=1))]
|
||||
),
|
||||
),
|
||||
("html", wagtail.blocks.RawHTMLBlock()),
|
||||
],
|
||||
blank=True,
|
||||
use_json_field=True,
|
||||
),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name="blogpostpage",
|
||||
name="body",
|
||||
field=wagtail.fields.StreamField(
|
||||
[
|
||||
("embed", wagtail.embeds.blocks.EmbedBlock()),
|
||||
(
|
||||
"rich_text",
|
||||
wagtail.blocks.RichTextBlock(
|
||||
features=[
|
||||
"h1",
|
||||
"h2",
|
||||
"h3",
|
||||
"h4",
|
||||
"h5",
|
||||
"h6",
|
||||
"bold",
|
||||
"italic",
|
||||
"ol",
|
||||
"ul",
|
||||
"link",
|
||||
"document-link",
|
||||
"code",
|
||||
"strikethrough",
|
||||
]
|
||||
),
|
||||
),
|
||||
(
|
||||
"lorem",
|
||||
wagtail.blocks.StructBlock(
|
||||
[("paragraphs", wagtail.blocks.IntegerBlock(min_value=1))]
|
||||
),
|
||||
),
|
||||
("html", wagtail.blocks.RawHTMLBlock()),
|
||||
],
|
||||
blank=True,
|
||||
use_json_field=True,
|
||||
),
|
||||
),
|
||||
]
|
|
@ -0,0 +1,94 @@
|
|||
# Generated by Django 4.0.5 on 2022-06-27 18:57
|
||||
|
||||
import wagtail.blocks
|
||||
import wagtail.embeds.blocks
|
||||
import wagtail.fields
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("common", "0005_contentpage_body_listingpage_body"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name="contentpage",
|
||||
name="body",
|
||||
field=wagtail.fields.StreamField(
|
||||
[
|
||||
("embed", wagtail.embeds.blocks.EmbedBlock()),
|
||||
(
|
||||
"rich_text",
|
||||
wagtail.blocks.RichTextBlock(
|
||||
features=[
|
||||
"h1",
|
||||
"h2",
|
||||
"h3",
|
||||
"h4",
|
||||
"h5",
|
||||
"h6",
|
||||
"bold",
|
||||
"italic",
|
||||
"ol",
|
||||
"ul",
|
||||
"link",
|
||||
"document-link",
|
||||
"code",
|
||||
"strikethrough",
|
||||
]
|
||||
),
|
||||
),
|
||||
(
|
||||
"lorem",
|
||||
wagtail.blocks.StructBlock(
|
||||
[("paragraphs", wagtail.blocks.IntegerBlock(min_value=1))]
|
||||
),
|
||||
),
|
||||
("html", wagtail.blocks.RawHTMLBlock()),
|
||||
],
|
||||
blank=True,
|
||||
use_json_field=True,
|
||||
),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name="listingpage",
|
||||
name="body",
|
||||
field=wagtail.fields.StreamField(
|
||||
[
|
||||
("embed", wagtail.embeds.blocks.EmbedBlock()),
|
||||
(
|
||||
"rich_text",
|
||||
wagtail.blocks.RichTextBlock(
|
||||
features=[
|
||||
"h1",
|
||||
"h2",
|
||||
"h3",
|
||||
"h4",
|
||||
"h5",
|
||||
"h6",
|
||||
"bold",
|
||||
"italic",
|
||||
"ol",
|
||||
"ul",
|
||||
"link",
|
||||
"document-link",
|
||||
"code",
|
||||
"strikethrough",
|
||||
]
|
||||
),
|
||||
),
|
||||
(
|
||||
"lorem",
|
||||
wagtail.blocks.StructBlock(
|
||||
[("paragraphs", wagtail.blocks.IntegerBlock(min_value=1))]
|
||||
),
|
||||
),
|
||||
("html", wagtail.blocks.RawHTMLBlock()),
|
||||
],
|
||||
blank=True,
|
||||
use_json_field=True,
|
||||
),
|
||||
),
|
||||
]
|
|
@ -8,6 +8,23 @@ from wagtail.embeds.blocks import EmbedBlock
|
|||
|
||||
IGNORE_PLAINTEXT_BLOCKS = (blocks.RawHTMLBlock, EmbedBlock)
|
||||
|
||||
RICH_TEXT_FEATURES = [
|
||||
"h1",
|
||||
"h2",
|
||||
"h3",
|
||||
"h4",
|
||||
"h5",
|
||||
"h6",
|
||||
"bold",
|
||||
"italic",
|
||||
"ol",
|
||||
"ul",
|
||||
"link",
|
||||
"document-link",
|
||||
"code",
|
||||
"strikethrough",
|
||||
]
|
||||
|
||||
|
||||
class LoremBlock(blocks.StructBlock):
|
||||
paragraphs = blocks.IntegerBlock(min_value=1)
|
||||
|
@ -27,7 +44,7 @@ class LoremBlock(blocks.StructBlock):
|
|||
def get_blocks() -> list[tuple[str, blocks.BaseBlock]]:
|
||||
return [
|
||||
("embed", EmbedBlock()),
|
||||
("rich_text", blocks.RichTextBlock()),
|
||||
("rich_text", blocks.RichTextBlock(features=RICH_TEXT_FEATURES)),
|
||||
("lorem", LoremBlock()),
|
||||
("html", blocks.RawHTMLBlock()),
|
||||
]
|
||||
|
|
Loading…
Reference in a new issue