Add filename and header show checkbox to code block

This commit is contained in:
Jake Howard 2022-08-31 22:29:14 +01:00
parent 55f15bc974
commit 488369a247
Signed by: jake
GPG key ID: 57AFB45680EDD477
8 changed files with 1841 additions and 7 deletions

View file

@ -55,7 +55,7 @@ div.block-mermaid {
} }
div.block-code { div.block-code {
.filename { .code-header {
font-family: $family-code; font-family: $family-code;
background-color: $grey-lighter; background-color: $grey-lighter;
font-size: 80%; font-size: 80%;
@ -68,7 +68,7 @@ div.block-code {
} }
} }
&:not(:hover) .filename { &:not(:hover) .code-header:not(.always-show) {
visibility: hidden; visibility: hidden;
} }

View file

@ -0,0 +1,962 @@
# Generated by Django 4.0.6 on 2022-08-31 21:28
import wagtail.blocks
import wagtail.contrib.typed_table_block.blocks
import wagtail.embeds.blocks
import wagtail.fields
import wagtail.images.blocks
from django.db import migrations
import website.contrib.code_block.blocks
class Migration(migrations.Migration):
dependencies = [
("blog", "0021_remove_blogpostcollectionlistpage_subtitle_and_more"),
]
operations = [
migrations.AlterField(
model_name="blogpostcollectionlistpage",
name="body",
field=wagtail.fields.StreamField(
[
("embed", wagtail.embeds.blocks.EmbedBlock()),
(
"rich_text",
wagtail.blocks.RichTextBlock(
features=[
"h2",
"h3",
"h4",
"h5",
"h6",
"bold",
"italic",
"ol",
"ul",
"link",
"document-link",
"code",
"strikethrough",
"snippet-link",
"snippet-embed",
]
),
),
(
"lorem",
wagtail.blocks.StructBlock(
[("paragraphs", wagtail.blocks.IntegerBlock(min_value=1))]
),
),
("html", wagtail.blocks.RawHTMLBlock()),
(
"image",
wagtail.blocks.StructBlock(
[
("image", wagtail.images.blocks.ImageChooserBlock()),
(
"caption",
wagtail.blocks.RichTextBlock(
features=[
"bold",
"italic",
"link",
"document-link",
"code",
"strikethrough",
"snippet-link",
],
required=False,
),
),
]
),
),
(
"code",
wagtail.blocks.StructBlock(
[
(
"filename",
wagtail.blocks.CharBlock(
max_length=128, required=False
),
),
(
"language",
wagtail.blocks.ChoiceBlock(
choices=website.contrib.code_block.blocks.get_language_choices
),
),
("source", wagtail.blocks.TextBlock()),
(
"always_show_header",
wagtail.blocks.BooleanBlock(default=False),
),
]
),
),
(
"tangent",
wagtail.blocks.StructBlock(
[
("name", wagtail.blocks.CharBlock(max_length=64)),
(
"content",
wagtail.blocks.RichTextBlock(
features=[
"bold",
"italic",
"ol",
"ul",
"link",
"document-link",
"code",
"strikethrough",
"snippet-link",
]
),
),
]
),
),
(
"mermaid",
wagtail.blocks.StructBlock(
[
("source", wagtail.blocks.TextBlock()),
(
"caption",
wagtail.blocks.RichTextBlock(
features=[
"bold",
"italic",
"link",
"document-link",
"code",
"strikethrough",
"snippet-link",
],
required=False,
),
),
]
),
),
(
"table",
wagtail.contrib.typed_table_block.blocks.TypedTableBlock(
[
(
"rich_text",
wagtail.blocks.RichTextBlock(
features=[
"bold",
"italic",
"link",
"document-link",
"code",
"strikethrough",
"snippet-link",
]
),
),
("numeric", wagtail.blocks.FloatBlock()),
("text", wagtail.blocks.CharBlock()),
]
),
),
],
blank=True,
use_json_field=True,
),
),
migrations.AlterField(
model_name="blogpostcollectionpage",
name="body",
field=wagtail.fields.StreamField(
[
("embed", wagtail.embeds.blocks.EmbedBlock()),
(
"rich_text",
wagtail.blocks.RichTextBlock(
features=[
"h2",
"h3",
"h4",
"h5",
"h6",
"bold",
"italic",
"ol",
"ul",
"link",
"document-link",
"code",
"strikethrough",
"snippet-link",
"snippet-embed",
]
),
),
(
"lorem",
wagtail.blocks.StructBlock(
[("paragraphs", wagtail.blocks.IntegerBlock(min_value=1))]
),
),
("html", wagtail.blocks.RawHTMLBlock()),
(
"image",
wagtail.blocks.StructBlock(
[
("image", wagtail.images.blocks.ImageChooserBlock()),
(
"caption",
wagtail.blocks.RichTextBlock(
features=[
"bold",
"italic",
"link",
"document-link",
"code",
"strikethrough",
"snippet-link",
],
required=False,
),
),
]
),
),
(
"code",
wagtail.blocks.StructBlock(
[
(
"filename",
wagtail.blocks.CharBlock(
max_length=128, required=False
),
),
(
"language",
wagtail.blocks.ChoiceBlock(
choices=website.contrib.code_block.blocks.get_language_choices
),
),
("source", wagtail.blocks.TextBlock()),
(
"always_show_header",
wagtail.blocks.BooleanBlock(default=False),
),
]
),
),
(
"tangent",
wagtail.blocks.StructBlock(
[
("name", wagtail.blocks.CharBlock(max_length=64)),
(
"content",
wagtail.blocks.RichTextBlock(
features=[
"bold",
"italic",
"ol",
"ul",
"link",
"document-link",
"code",
"strikethrough",
"snippet-link",
]
),
),
]
),
),
(
"mermaid",
wagtail.blocks.StructBlock(
[
("source", wagtail.blocks.TextBlock()),
(
"caption",
wagtail.blocks.RichTextBlock(
features=[
"bold",
"italic",
"link",
"document-link",
"code",
"strikethrough",
"snippet-link",
],
required=False,
),
),
]
),
),
(
"table",
wagtail.contrib.typed_table_block.blocks.TypedTableBlock(
[
(
"rich_text",
wagtail.blocks.RichTextBlock(
features=[
"bold",
"italic",
"link",
"document-link",
"code",
"strikethrough",
"snippet-link",
]
),
),
("numeric", wagtail.blocks.FloatBlock()),
("text", wagtail.blocks.CharBlock()),
]
),
),
],
blank=True,
use_json_field=True,
),
),
migrations.AlterField(
model_name="blogpostlistpage",
name="body",
field=wagtail.fields.StreamField(
[
("embed", wagtail.embeds.blocks.EmbedBlock()),
(
"rich_text",
wagtail.blocks.RichTextBlock(
features=[
"h2",
"h3",
"h4",
"h5",
"h6",
"bold",
"italic",
"ol",
"ul",
"link",
"document-link",
"code",
"strikethrough",
"snippet-link",
"snippet-embed",
]
),
),
(
"lorem",
wagtail.blocks.StructBlock(
[("paragraphs", wagtail.blocks.IntegerBlock(min_value=1))]
),
),
("html", wagtail.blocks.RawHTMLBlock()),
(
"image",
wagtail.blocks.StructBlock(
[
("image", wagtail.images.blocks.ImageChooserBlock()),
(
"caption",
wagtail.blocks.RichTextBlock(
features=[
"bold",
"italic",
"link",
"document-link",
"code",
"strikethrough",
"snippet-link",
],
required=False,
),
),
]
),
),
(
"code",
wagtail.blocks.StructBlock(
[
(
"filename",
wagtail.blocks.CharBlock(
max_length=128, required=False
),
),
(
"language",
wagtail.blocks.ChoiceBlock(
choices=website.contrib.code_block.blocks.get_language_choices
),
),
("source", wagtail.blocks.TextBlock()),
(
"always_show_header",
wagtail.blocks.BooleanBlock(default=False),
),
]
),
),
(
"tangent",
wagtail.blocks.StructBlock(
[
("name", wagtail.blocks.CharBlock(max_length=64)),
(
"content",
wagtail.blocks.RichTextBlock(
features=[
"bold",
"italic",
"ol",
"ul",
"link",
"document-link",
"code",
"strikethrough",
"snippet-link",
]
),
),
]
),
),
(
"mermaid",
wagtail.blocks.StructBlock(
[
("source", wagtail.blocks.TextBlock()),
(
"caption",
wagtail.blocks.RichTextBlock(
features=[
"bold",
"italic",
"link",
"document-link",
"code",
"strikethrough",
"snippet-link",
],
required=False,
),
),
]
),
),
(
"table",
wagtail.contrib.typed_table_block.blocks.TypedTableBlock(
[
(
"rich_text",
wagtail.blocks.RichTextBlock(
features=[
"bold",
"italic",
"link",
"document-link",
"code",
"strikethrough",
"snippet-link",
]
),
),
("numeric", wagtail.blocks.FloatBlock()),
("text", wagtail.blocks.CharBlock()),
]
),
),
],
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=[
"h2",
"h3",
"h4",
"h5",
"h6",
"bold",
"italic",
"ol",
"ul",
"link",
"document-link",
"code",
"strikethrough",
"snippet-link",
"snippet-embed",
]
),
),
(
"lorem",
wagtail.blocks.StructBlock(
[("paragraphs", wagtail.blocks.IntegerBlock(min_value=1))]
),
),
("html", wagtail.blocks.RawHTMLBlock()),
(
"image",
wagtail.blocks.StructBlock(
[
("image", wagtail.images.blocks.ImageChooserBlock()),
(
"caption",
wagtail.blocks.RichTextBlock(
features=[
"bold",
"italic",
"link",
"document-link",
"code",
"strikethrough",
"snippet-link",
],
required=False,
),
),
]
),
),
(
"code",
wagtail.blocks.StructBlock(
[
(
"filename",
wagtail.blocks.CharBlock(
max_length=128, required=False
),
),
(
"language",
wagtail.blocks.ChoiceBlock(
choices=website.contrib.code_block.blocks.get_language_choices
),
),
("source", wagtail.blocks.TextBlock()),
(
"always_show_header",
wagtail.blocks.BooleanBlock(default=False),
),
]
),
),
(
"tangent",
wagtail.blocks.StructBlock(
[
("name", wagtail.blocks.CharBlock(max_length=64)),
(
"content",
wagtail.blocks.RichTextBlock(
features=[
"bold",
"italic",
"ol",
"ul",
"link",
"document-link",
"code",
"strikethrough",
"snippet-link",
]
),
),
]
),
),
(
"mermaid",
wagtail.blocks.StructBlock(
[
("source", wagtail.blocks.TextBlock()),
(
"caption",
wagtail.blocks.RichTextBlock(
features=[
"bold",
"italic",
"link",
"document-link",
"code",
"strikethrough",
"snippet-link",
],
required=False,
),
),
]
),
),
(
"table",
wagtail.contrib.typed_table_block.blocks.TypedTableBlock(
[
(
"rich_text",
wagtail.blocks.RichTextBlock(
features=[
"bold",
"italic",
"link",
"document-link",
"code",
"strikethrough",
"snippet-link",
]
),
),
("numeric", wagtail.blocks.FloatBlock()),
("text", wagtail.blocks.CharBlock()),
]
),
),
],
blank=True,
use_json_field=True,
),
),
migrations.AlterField(
model_name="blogposttaglistpage",
name="body",
field=wagtail.fields.StreamField(
[
("embed", wagtail.embeds.blocks.EmbedBlock()),
(
"rich_text",
wagtail.blocks.RichTextBlock(
features=[
"h2",
"h3",
"h4",
"h5",
"h6",
"bold",
"italic",
"ol",
"ul",
"link",
"document-link",
"code",
"strikethrough",
"snippet-link",
"snippet-embed",
]
),
),
(
"lorem",
wagtail.blocks.StructBlock(
[("paragraphs", wagtail.blocks.IntegerBlock(min_value=1))]
),
),
("html", wagtail.blocks.RawHTMLBlock()),
(
"image",
wagtail.blocks.StructBlock(
[
("image", wagtail.images.blocks.ImageChooserBlock()),
(
"caption",
wagtail.blocks.RichTextBlock(
features=[
"bold",
"italic",
"link",
"document-link",
"code",
"strikethrough",
"snippet-link",
],
required=False,
),
),
]
),
),
(
"code",
wagtail.blocks.StructBlock(
[
(
"filename",
wagtail.blocks.CharBlock(
max_length=128, required=False
),
),
(
"language",
wagtail.blocks.ChoiceBlock(
choices=website.contrib.code_block.blocks.get_language_choices
),
),
("source", wagtail.blocks.TextBlock()),
(
"always_show_header",
wagtail.blocks.BooleanBlock(default=False),
),
]
),
),
(
"tangent",
wagtail.blocks.StructBlock(
[
("name", wagtail.blocks.CharBlock(max_length=64)),
(
"content",
wagtail.blocks.RichTextBlock(
features=[
"bold",
"italic",
"ol",
"ul",
"link",
"document-link",
"code",
"strikethrough",
"snippet-link",
]
),
),
]
),
),
(
"mermaid",
wagtail.blocks.StructBlock(
[
("source", wagtail.blocks.TextBlock()),
(
"caption",
wagtail.blocks.RichTextBlock(
features=[
"bold",
"italic",
"link",
"document-link",
"code",
"strikethrough",
"snippet-link",
],
required=False,
),
),
]
),
),
(
"table",
wagtail.contrib.typed_table_block.blocks.TypedTableBlock(
[
(
"rich_text",
wagtail.blocks.RichTextBlock(
features=[
"bold",
"italic",
"link",
"document-link",
"code",
"strikethrough",
"snippet-link",
]
),
),
("numeric", wagtail.blocks.FloatBlock()),
("text", wagtail.blocks.CharBlock()),
]
),
),
],
blank=True,
use_json_field=True,
),
),
migrations.AlterField(
model_name="blogposttagpage",
name="body",
field=wagtail.fields.StreamField(
[
("embed", wagtail.embeds.blocks.EmbedBlock()),
(
"rich_text",
wagtail.blocks.RichTextBlock(
features=[
"h2",
"h3",
"h4",
"h5",
"h6",
"bold",
"italic",
"ol",
"ul",
"link",
"document-link",
"code",
"strikethrough",
"snippet-link",
"snippet-embed",
]
),
),
(
"lorem",
wagtail.blocks.StructBlock(
[("paragraphs", wagtail.blocks.IntegerBlock(min_value=1))]
),
),
("html", wagtail.blocks.RawHTMLBlock()),
(
"image",
wagtail.blocks.StructBlock(
[
("image", wagtail.images.blocks.ImageChooserBlock()),
(
"caption",
wagtail.blocks.RichTextBlock(
features=[
"bold",
"italic",
"link",
"document-link",
"code",
"strikethrough",
"snippet-link",
],
required=False,
),
),
]
),
),
(
"code",
wagtail.blocks.StructBlock(
[
(
"filename",
wagtail.blocks.CharBlock(
max_length=128, required=False
),
),
(
"language",
wagtail.blocks.ChoiceBlock(
choices=website.contrib.code_block.blocks.get_language_choices
),
),
("source", wagtail.blocks.TextBlock()),
(
"always_show_header",
wagtail.blocks.BooleanBlock(default=False),
),
]
),
),
(
"tangent",
wagtail.blocks.StructBlock(
[
("name", wagtail.blocks.CharBlock(max_length=64)),
(
"content",
wagtail.blocks.RichTextBlock(
features=[
"bold",
"italic",
"ol",
"ul",
"link",
"document-link",
"code",
"strikethrough",
"snippet-link",
]
),
),
]
),
),
(
"mermaid",
wagtail.blocks.StructBlock(
[
("source", wagtail.blocks.TextBlock()),
(
"caption",
wagtail.blocks.RichTextBlock(
features=[
"bold",
"italic",
"link",
"document-link",
"code",
"strikethrough",
"snippet-link",
],
required=False,
),
),
]
),
),
(
"table",
wagtail.contrib.typed_table_block.blocks.TypedTableBlock(
[
(
"rich_text",
wagtail.blocks.RichTextBlock(
features=[
"bold",
"italic",
"link",
"document-link",
"code",
"strikethrough",
"snippet-link",
]
),
),
("numeric", wagtail.blocks.FloatBlock()),
("text", wagtail.blocks.CharBlock()),
]
),
),
],
blank=True,
use_json_field=True,
),
),
]

View file

@ -0,0 +1,334 @@
# Generated by Django 4.0.6 on 2022-08-31 21:28
import wagtail.blocks
import wagtail.contrib.typed_table_block.blocks
import wagtail.embeds.blocks
import wagtail.fields
import wagtail.images.blocks
from django.db import migrations
import website.contrib.code_block.blocks
class Migration(migrations.Migration):
dependencies = [
("common", "0020_remove_listingpage_subtitle"),
]
operations = [
migrations.AlterField(
model_name="contentpage",
name="body",
field=wagtail.fields.StreamField(
[
("embed", wagtail.embeds.blocks.EmbedBlock()),
(
"rich_text",
wagtail.blocks.RichTextBlock(
features=[
"h2",
"h3",
"h4",
"h5",
"h6",
"bold",
"italic",
"ol",
"ul",
"link",
"document-link",
"code",
"strikethrough",
"snippet-link",
"snippet-embed",
]
),
),
(
"lorem",
wagtail.blocks.StructBlock(
[("paragraphs", wagtail.blocks.IntegerBlock(min_value=1))]
),
),
("html", wagtail.blocks.RawHTMLBlock()),
(
"image",
wagtail.blocks.StructBlock(
[
("image", wagtail.images.blocks.ImageChooserBlock()),
(
"caption",
wagtail.blocks.RichTextBlock(
features=[
"bold",
"italic",
"link",
"document-link",
"code",
"strikethrough",
"snippet-link",
],
required=False,
),
),
]
),
),
(
"code",
wagtail.blocks.StructBlock(
[
(
"filename",
wagtail.blocks.CharBlock(
max_length=128, required=False
),
),
(
"language",
wagtail.blocks.ChoiceBlock(
choices=website.contrib.code_block.blocks.get_language_choices
),
),
("source", wagtail.blocks.TextBlock()),
(
"always_show_header",
wagtail.blocks.BooleanBlock(default=False),
),
]
),
),
(
"tangent",
wagtail.blocks.StructBlock(
[
("name", wagtail.blocks.CharBlock(max_length=64)),
(
"content",
wagtail.blocks.RichTextBlock(
features=[
"bold",
"italic",
"ol",
"ul",
"link",
"document-link",
"code",
"strikethrough",
"snippet-link",
]
),
),
]
),
),
(
"mermaid",
wagtail.blocks.StructBlock(
[
("source", wagtail.blocks.TextBlock()),
(
"caption",
wagtail.blocks.RichTextBlock(
features=[
"bold",
"italic",
"link",
"document-link",
"code",
"strikethrough",
"snippet-link",
],
required=False,
),
),
]
),
),
(
"table",
wagtail.contrib.typed_table_block.blocks.TypedTableBlock(
[
(
"rich_text",
wagtail.blocks.RichTextBlock(
features=[
"bold",
"italic",
"link",
"document-link",
"code",
"strikethrough",
"snippet-link",
]
),
),
("numeric", wagtail.blocks.FloatBlock()),
("text", wagtail.blocks.CharBlock()),
]
),
),
],
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=[
"h2",
"h3",
"h4",
"h5",
"h6",
"bold",
"italic",
"ol",
"ul",
"link",
"document-link",
"code",
"strikethrough",
"snippet-link",
"snippet-embed",
]
),
),
(
"lorem",
wagtail.blocks.StructBlock(
[("paragraphs", wagtail.blocks.IntegerBlock(min_value=1))]
),
),
("html", wagtail.blocks.RawHTMLBlock()),
(
"image",
wagtail.blocks.StructBlock(
[
("image", wagtail.images.blocks.ImageChooserBlock()),
(
"caption",
wagtail.blocks.RichTextBlock(
features=[
"bold",
"italic",
"link",
"document-link",
"code",
"strikethrough",
"snippet-link",
],
required=False,
),
),
]
),
),
(
"code",
wagtail.blocks.StructBlock(
[
(
"filename",
wagtail.blocks.CharBlock(
max_length=128, required=False
),
),
(
"language",
wagtail.blocks.ChoiceBlock(
choices=website.contrib.code_block.blocks.get_language_choices
),
),
("source", wagtail.blocks.TextBlock()),
(
"always_show_header",
wagtail.blocks.BooleanBlock(default=False),
),
]
),
),
(
"tangent",
wagtail.blocks.StructBlock(
[
("name", wagtail.blocks.CharBlock(max_length=64)),
(
"content",
wagtail.blocks.RichTextBlock(
features=[
"bold",
"italic",
"ol",
"ul",
"link",
"document-link",
"code",
"strikethrough",
"snippet-link",
]
),
),
]
),
),
(
"mermaid",
wagtail.blocks.StructBlock(
[
("source", wagtail.blocks.TextBlock()),
(
"caption",
wagtail.blocks.RichTextBlock(
features=[
"bold",
"italic",
"link",
"document-link",
"code",
"strikethrough",
"snippet-link",
],
required=False,
),
),
]
),
),
(
"table",
wagtail.contrib.typed_table_block.blocks.TypedTableBlock(
[
(
"rich_text",
wagtail.blocks.RichTextBlock(
features=[
"bold",
"italic",
"link",
"document-link",
"code",
"strikethrough",
"snippet-link",
]
),
),
("numeric", wagtail.blocks.FloatBlock()),
("text", wagtail.blocks.CharBlock()),
]
),
),
],
blank=True,
use_json_field=True,
),
),
]

View file

@ -0,0 +1,177 @@
# Generated by Django 4.0.6 on 2022-08-31 21:28
import wagtail.blocks
import wagtail.contrib.typed_table_block.blocks
import wagtail.embeds.blocks
import wagtail.fields
import wagtail.images.blocks
from django.db import migrations
import website.contrib.code_block.blocks
class Migration(migrations.Migration):
dependencies = [
("contact", "0005_alter_contactpage_body"),
]
operations = [
migrations.AlterField(
model_name="contactpage",
name="body",
field=wagtail.fields.StreamField(
[
("embed", wagtail.embeds.blocks.EmbedBlock()),
(
"rich_text",
wagtail.blocks.RichTextBlock(
features=[
"h2",
"h3",
"h4",
"h5",
"h6",
"bold",
"italic",
"ol",
"ul",
"link",
"document-link",
"code",
"strikethrough",
"snippet-link",
"snippet-embed",
]
),
),
(
"lorem",
wagtail.blocks.StructBlock(
[("paragraphs", wagtail.blocks.IntegerBlock(min_value=1))]
),
),
("html", wagtail.blocks.RawHTMLBlock()),
(
"image",
wagtail.blocks.StructBlock(
[
("image", wagtail.images.blocks.ImageChooserBlock()),
(
"caption",
wagtail.blocks.RichTextBlock(
features=[
"bold",
"italic",
"link",
"document-link",
"code",
"strikethrough",
"snippet-link",
],
required=False,
),
),
]
),
),
(
"code",
wagtail.blocks.StructBlock(
[
(
"filename",
wagtail.blocks.CharBlock(
max_length=128, required=False
),
),
(
"language",
wagtail.blocks.ChoiceBlock(
choices=website.contrib.code_block.blocks.get_language_choices
),
),
("source", wagtail.blocks.TextBlock()),
(
"always_show_header",
wagtail.blocks.BooleanBlock(default=False),
),
]
),
),
(
"tangent",
wagtail.blocks.StructBlock(
[
("name", wagtail.blocks.CharBlock(max_length=64)),
(
"content",
wagtail.blocks.RichTextBlock(
features=[
"bold",
"italic",
"ol",
"ul",
"link",
"document-link",
"code",
"strikethrough",
"snippet-link",
]
),
),
]
),
),
(
"mermaid",
wagtail.blocks.StructBlock(
[
("source", wagtail.blocks.TextBlock()),
(
"caption",
wagtail.blocks.RichTextBlock(
features=[
"bold",
"italic",
"link",
"document-link",
"code",
"strikethrough",
"snippet-link",
],
required=False,
),
),
]
),
),
(
"table",
wagtail.contrib.typed_table_block.blocks.TypedTableBlock(
[
(
"rich_text",
wagtail.blocks.RichTextBlock(
features=[
"bold",
"italic",
"link",
"document-link",
"code",
"strikethrough",
"snippet-link",
]
),
),
("numeric", wagtail.blocks.FloatBlock()),
("text", wagtail.blocks.CharBlock()),
]
),
),
],
blank=True,
use_json_field=True,
),
),
]

View file

@ -4,7 +4,14 @@ from django.utils.safestring import mark_safe
from pygments import highlight from pygments import highlight
from pygments.formatters.html import HtmlFormatter from pygments.formatters.html import HtmlFormatter
from pygments.lexers import get_all_lexers, get_lexer_by_name from pygments.lexers import get_all_lexers, get_lexer_by_name
from wagtail.blocks import ChoiceBlock, StructBlock, StructValue, TextBlock from wagtail.blocks import (
BooleanBlock,
CharBlock,
ChoiceBlock,
StructBlock,
StructValue,
TextBlock,
)
def get_language_choices() -> Iterator[tuple[str, str]]: def get_language_choices() -> Iterator[tuple[str, str]]:
@ -22,10 +29,12 @@ class CodeStructValue(StructValue):
class CodeBlock(StructBlock): class CodeBlock(StructBlock):
filename = CharBlock(max_length=128, required=False)
language = ChoiceBlock( language = ChoiceBlock(
choices=get_language_choices, choices=get_language_choices,
) )
source = TextBlock() source = TextBlock()
always_show_header = BooleanBlock(default=False)
class Meta: class Meta:
icon = "code" icon = "code"

View file

@ -1,7 +1,5 @@
<div class="filename"> <div class="code-header {% if value.always_show_header %}always-show{% endif %}">
<span> <span title="{{ value.language }}">{% firstof value.filename value.language %}</span>
{{ value.language }}
</span>
<span> <span>
<i class="fa-regular fa-clipboard is-clickable code-copy" title="Copy to clipboard"></i> <i class="fa-regular fa-clipboard is-clickable code-copy" title="Copy to clipboard"></i>
</span> </span>

View file

@ -0,0 +1,177 @@
# Generated by Django 4.0.6 on 2022-08-31 21:28
import wagtail.blocks
import wagtail.contrib.typed_table_block.blocks
import wagtail.embeds.blocks
import wagtail.fields
import wagtail.images.blocks
from django.db import migrations
import website.contrib.code_block.blocks
class Migration(migrations.Migration):
dependencies = [
("search", "0004_alter_searchpage_body"),
]
operations = [
migrations.AlterField(
model_name="searchpage",
name="body",
field=wagtail.fields.StreamField(
[
("embed", wagtail.embeds.blocks.EmbedBlock()),
(
"rich_text",
wagtail.blocks.RichTextBlock(
features=[
"h2",
"h3",
"h4",
"h5",
"h6",
"bold",
"italic",
"ol",
"ul",
"link",
"document-link",
"code",
"strikethrough",
"snippet-link",
"snippet-embed",
]
),
),
(
"lorem",
wagtail.blocks.StructBlock(
[("paragraphs", wagtail.blocks.IntegerBlock(min_value=1))]
),
),
("html", wagtail.blocks.RawHTMLBlock()),
(
"image",
wagtail.blocks.StructBlock(
[
("image", wagtail.images.blocks.ImageChooserBlock()),
(
"caption",
wagtail.blocks.RichTextBlock(
features=[
"bold",
"italic",
"link",
"document-link",
"code",
"strikethrough",
"snippet-link",
],
required=False,
),
),
]
),
),
(
"code",
wagtail.blocks.StructBlock(
[
(
"filename",
wagtail.blocks.CharBlock(
max_length=128, required=False
),
),
(
"language",
wagtail.blocks.ChoiceBlock(
choices=website.contrib.code_block.blocks.get_language_choices
),
),
("source", wagtail.blocks.TextBlock()),
(
"always_show_header",
wagtail.blocks.BooleanBlock(default=False),
),
]
),
),
(
"tangent",
wagtail.blocks.StructBlock(
[
("name", wagtail.blocks.CharBlock(max_length=64)),
(
"content",
wagtail.blocks.RichTextBlock(
features=[
"bold",
"italic",
"ol",
"ul",
"link",
"document-link",
"code",
"strikethrough",
"snippet-link",
]
),
),
]
),
),
(
"mermaid",
wagtail.blocks.StructBlock(
[
("source", wagtail.blocks.TextBlock()),
(
"caption",
wagtail.blocks.RichTextBlock(
features=[
"bold",
"italic",
"link",
"document-link",
"code",
"strikethrough",
"snippet-link",
],
required=False,
),
),
]
),
),
(
"table",
wagtail.contrib.typed_table_block.blocks.TypedTableBlock(
[
(
"rich_text",
wagtail.blocks.RichTextBlock(
features=[
"bold",
"italic",
"link",
"document-link",
"code",
"strikethrough",
"snippet-link",
]
),
),
("numeric", wagtail.blocks.FloatBlock()),
("text", wagtail.blocks.CharBlock()),
]
),
),
],
blank=True,
use_json_field=True,
),
),
]

View file

@ -0,0 +1,177 @@
# Generated by Django 4.0.6 on 2022-08-31 21:28
import wagtail.blocks
import wagtail.contrib.typed_table_block.blocks
import wagtail.embeds.blocks
import wagtail.fields
import wagtail.images.blocks
from django.db import migrations
import website.contrib.code_block.blocks
class Migration(migrations.Migration):
dependencies = [
("spotify", "0005_alter_spotifyplaylistpage_body"),
]
operations = [
migrations.AlterField(
model_name="spotifyplaylistpage",
name="body",
field=wagtail.fields.StreamField(
[
("embed", wagtail.embeds.blocks.EmbedBlock()),
(
"rich_text",
wagtail.blocks.RichTextBlock(
features=[
"h2",
"h3",
"h4",
"h5",
"h6",
"bold",
"italic",
"ol",
"ul",
"link",
"document-link",
"code",
"strikethrough",
"snippet-link",
"snippet-embed",
]
),
),
(
"lorem",
wagtail.blocks.StructBlock(
[("paragraphs", wagtail.blocks.IntegerBlock(min_value=1))]
),
),
("html", wagtail.blocks.RawHTMLBlock()),
(
"image",
wagtail.blocks.StructBlock(
[
("image", wagtail.images.blocks.ImageChooserBlock()),
(
"caption",
wagtail.blocks.RichTextBlock(
features=[
"bold",
"italic",
"link",
"document-link",
"code",
"strikethrough",
"snippet-link",
],
required=False,
),
),
]
),
),
(
"code",
wagtail.blocks.StructBlock(
[
(
"filename",
wagtail.blocks.CharBlock(
max_length=128, required=False
),
),
(
"language",
wagtail.blocks.ChoiceBlock(
choices=website.contrib.code_block.blocks.get_language_choices
),
),
("source", wagtail.blocks.TextBlock()),
(
"always_show_header",
wagtail.blocks.BooleanBlock(default=False),
),
]
),
),
(
"tangent",
wagtail.blocks.StructBlock(
[
("name", wagtail.blocks.CharBlock(max_length=64)),
(
"content",
wagtail.blocks.RichTextBlock(
features=[
"bold",
"italic",
"ol",
"ul",
"link",
"document-link",
"code",
"strikethrough",
"snippet-link",
]
),
),
]
),
),
(
"mermaid",
wagtail.blocks.StructBlock(
[
("source", wagtail.blocks.TextBlock()),
(
"caption",
wagtail.blocks.RichTextBlock(
features=[
"bold",
"italic",
"link",
"document-link",
"code",
"strikethrough",
"snippet-link",
],
required=False,
),
),
]
),
),
(
"table",
wagtail.contrib.typed_table_block.blocks.TypedTableBlock(
[
(
"rich_text",
wagtail.blocks.RichTextBlock(
features=[
"bold",
"italic",
"link",
"document-link",
"code",
"strikethrough",
"snippet-link",
]
),
),
("numeric", wagtail.blocks.FloatBlock()),
("text", wagtail.blocks.CharBlock()),
]
),
),
],
blank=True,
use_json_field=True,
),
),
]