diff --git a/static/src/scss/_blocks.scss b/static/src/scss/_blocks.scss index b81ea10..443145e 100644 --- a/static/src/scss/_blocks.scss +++ b/static/src/scss/_blocks.scss @@ -78,21 +78,37 @@ div.block-tangent { } div.block-code { + position: relative; + .code-header { + position: absolute; font-family: $family-code; - background-color: $grey-lighter; - font-size: 80%; - padding: 0.25rem 1rem; + width: 100%; display: flex; - justify-content: space-between; + padding-right: 0.5rem; - @include dark-mode { - background-color: $grey-darker; + .tag { + border-radius: 0 !important; + cursor: default; } - } - &:not(:hover) .code-header:not(.always-show) { - visibility: hidden; + .code-copy-tag { + background-color: transparent; + color: $dark; + + @include dark-mode { + color: $dark-mode-text; + } + } + + .language-tag { + background-color: $primary-light; + + @include dark-mode { + background-color: $primary-dark; + color: $white; + } + } } .highlight { diff --git a/static/src/scss/_bulma_overrides.scss b/static/src/scss/_bulma_overrides.scss index 39099a0..febbb1c 100644 --- a/static/src/scss/_bulma_overrides.scss +++ b/static/src/scss/_bulma_overrides.scss @@ -22,3 +22,4 @@ $code-padding: 0; $code: inherit; $pre: unset; $content-heading-weight: $weight-medium; +$content-pre-padding: 1.5em 1.25em 1.25em; diff --git a/website/blog/migrations/0004_alter_blogpostcollectionlistpage_body_and_more.py b/website/blog/migrations/0004_alter_blogpostcollectionlistpage_body_and_more.py new file mode 100644 index 0000000..ade2e72 --- /dev/null +++ b/website/blog/migrations/0004_alter_blogpostcollectionlistpage_body_and_more.py @@ -0,0 +1,656 @@ +# Generated by Django 4.1.8 on 2023-04-19 20:19 + +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", "0003_alter_blogpostcollectionlistpage_body_and_more"), + ] + + operations = [ + migrations.AlterField( + model_name="blogpostcollectionlistpage", + name="body", + field=wagtail.fields.StreamField( + [ + ("embed", wagtail.embeds.blocks.EmbedBlock()), + ("rich_text", wagtail.blocks.RichTextBlock()), + ( + "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( + editor="plain", 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()), + ] + ), + ), + ( + "tangent", + wagtail.blocks.StructBlock( + [ + ("name", wagtail.blocks.CharBlock(max_length=64)), + ( + "content", + wagtail.blocks.RichTextBlock(editor="simple"), + ), + ] + ), + ), + ( + "mermaid", + wagtail.blocks.StructBlock( + [ + ("source", wagtail.blocks.TextBlock()), + ( + "caption", + wagtail.blocks.RichTextBlock( + editor="plain", required=False + ), + ), + ] + ), + ), + ( + "table", + wagtail.contrib.typed_table_block.blocks.TypedTableBlock( + [ + ( + "rich_text", + wagtail.blocks.RichTextBlock(editor="plain"), + ), + ("numeric", wagtail.blocks.FloatBlock()), + ("text", wagtail.blocks.CharBlock()), + ] + ), + ), + ( + "iframe", + wagtail.blocks.StructBlock( + [ + ("url", wagtail.blocks.URLBlock()), + ( + "caption", + wagtail.blocks.RichTextBlock( + editor="plain", required=False + ), + ), + ] + ), + ), + ], + 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()), + ( + "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( + editor="plain", 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()), + ] + ), + ), + ( + "tangent", + wagtail.blocks.StructBlock( + [ + ("name", wagtail.blocks.CharBlock(max_length=64)), + ( + "content", + wagtail.blocks.RichTextBlock(editor="simple"), + ), + ] + ), + ), + ( + "mermaid", + wagtail.blocks.StructBlock( + [ + ("source", wagtail.blocks.TextBlock()), + ( + "caption", + wagtail.blocks.RichTextBlock( + editor="plain", required=False + ), + ), + ] + ), + ), + ( + "table", + wagtail.contrib.typed_table_block.blocks.TypedTableBlock( + [ + ( + "rich_text", + wagtail.blocks.RichTextBlock(editor="plain"), + ), + ("numeric", wagtail.blocks.FloatBlock()), + ("text", wagtail.blocks.CharBlock()), + ] + ), + ), + ( + "iframe", + wagtail.blocks.StructBlock( + [ + ("url", wagtail.blocks.URLBlock()), + ( + "caption", + wagtail.blocks.RichTextBlock( + editor="plain", required=False + ), + ), + ] + ), + ), + ], + 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()), + ( + "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( + editor="plain", 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()), + ] + ), + ), + ( + "tangent", + wagtail.blocks.StructBlock( + [ + ("name", wagtail.blocks.CharBlock(max_length=64)), + ( + "content", + wagtail.blocks.RichTextBlock(editor="simple"), + ), + ] + ), + ), + ( + "mermaid", + wagtail.blocks.StructBlock( + [ + ("source", wagtail.blocks.TextBlock()), + ( + "caption", + wagtail.blocks.RichTextBlock( + editor="plain", required=False + ), + ), + ] + ), + ), + ( + "table", + wagtail.contrib.typed_table_block.blocks.TypedTableBlock( + [ + ( + "rich_text", + wagtail.blocks.RichTextBlock(editor="plain"), + ), + ("numeric", wagtail.blocks.FloatBlock()), + ("text", wagtail.blocks.CharBlock()), + ] + ), + ), + ( + "iframe", + wagtail.blocks.StructBlock( + [ + ("url", wagtail.blocks.URLBlock()), + ( + "caption", + wagtail.blocks.RichTextBlock( + editor="plain", required=False + ), + ), + ] + ), + ), + ], + 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()), + ( + "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( + editor="plain", 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()), + ] + ), + ), + ( + "tangent", + wagtail.blocks.StructBlock( + [ + ("name", wagtail.blocks.CharBlock(max_length=64)), + ( + "content", + wagtail.blocks.RichTextBlock(editor="simple"), + ), + ] + ), + ), + ( + "mermaid", + wagtail.blocks.StructBlock( + [ + ("source", wagtail.blocks.TextBlock()), + ( + "caption", + wagtail.blocks.RichTextBlock( + editor="plain", required=False + ), + ), + ] + ), + ), + ( + "table", + wagtail.contrib.typed_table_block.blocks.TypedTableBlock( + [ + ( + "rich_text", + wagtail.blocks.RichTextBlock(editor="plain"), + ), + ("numeric", wagtail.blocks.FloatBlock()), + ("text", wagtail.blocks.CharBlock()), + ] + ), + ), + ( + "iframe", + wagtail.blocks.StructBlock( + [ + ("url", wagtail.blocks.URLBlock()), + ( + "caption", + wagtail.blocks.RichTextBlock( + editor="plain", required=False + ), + ), + ] + ), + ), + ], + 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()), + ( + "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( + editor="plain", 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()), + ] + ), + ), + ( + "tangent", + wagtail.blocks.StructBlock( + [ + ("name", wagtail.blocks.CharBlock(max_length=64)), + ( + "content", + wagtail.blocks.RichTextBlock(editor="simple"), + ), + ] + ), + ), + ( + "mermaid", + wagtail.blocks.StructBlock( + [ + ("source", wagtail.blocks.TextBlock()), + ( + "caption", + wagtail.blocks.RichTextBlock( + editor="plain", required=False + ), + ), + ] + ), + ), + ( + "table", + wagtail.contrib.typed_table_block.blocks.TypedTableBlock( + [ + ( + "rich_text", + wagtail.blocks.RichTextBlock(editor="plain"), + ), + ("numeric", wagtail.blocks.FloatBlock()), + ("text", wagtail.blocks.CharBlock()), + ] + ), + ), + ( + "iframe", + wagtail.blocks.StructBlock( + [ + ("url", wagtail.blocks.URLBlock()), + ( + "caption", + wagtail.blocks.RichTextBlock( + editor="plain", required=False + ), + ), + ] + ), + ), + ], + 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()), + ( + "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( + editor="plain", 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()), + ] + ), + ), + ( + "tangent", + wagtail.blocks.StructBlock( + [ + ("name", wagtail.blocks.CharBlock(max_length=64)), + ( + "content", + wagtail.blocks.RichTextBlock(editor="simple"), + ), + ] + ), + ), + ( + "mermaid", + wagtail.blocks.StructBlock( + [ + ("source", wagtail.blocks.TextBlock()), + ( + "caption", + wagtail.blocks.RichTextBlock( + editor="plain", required=False + ), + ), + ] + ), + ), + ( + "table", + wagtail.contrib.typed_table_block.blocks.TypedTableBlock( + [ + ( + "rich_text", + wagtail.blocks.RichTextBlock(editor="plain"), + ), + ("numeric", wagtail.blocks.FloatBlock()), + ("text", wagtail.blocks.CharBlock()), + ] + ), + ), + ( + "iframe", + wagtail.blocks.StructBlock( + [ + ("url", wagtail.blocks.URLBlock()), + ( + "caption", + wagtail.blocks.RichTextBlock( + editor="plain", required=False + ), + ), + ] + ), + ), + ], + blank=True, + use_json_field=True, + ), + ), + ] diff --git a/website/common/migrations/0006_alter_contentpage_body_alter_listingpage_body.py b/website/common/migrations/0006_alter_contentpage_body_alter_listingpage_body.py new file mode 100644 index 0000000..f3156f8 --- /dev/null +++ b/website/common/migrations/0006_alter_contentpage_body_alter_listingpage_body.py @@ -0,0 +1,232 @@ +# Generated by Django 4.1.8 on 2023-04-19 20:19 + +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", "0005_remove_footersetting_site"), + ] + + operations = [ + migrations.AlterField( + model_name="contentpage", + name="body", + field=wagtail.fields.StreamField( + [ + ("embed", wagtail.embeds.blocks.EmbedBlock()), + ("rich_text", wagtail.blocks.RichTextBlock()), + ( + "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( + editor="plain", 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()), + ] + ), + ), + ( + "tangent", + wagtail.blocks.StructBlock( + [ + ("name", wagtail.blocks.CharBlock(max_length=64)), + ( + "content", + wagtail.blocks.RichTextBlock(editor="simple"), + ), + ] + ), + ), + ( + "mermaid", + wagtail.blocks.StructBlock( + [ + ("source", wagtail.blocks.TextBlock()), + ( + "caption", + wagtail.blocks.RichTextBlock( + editor="plain", required=False + ), + ), + ] + ), + ), + ( + "table", + wagtail.contrib.typed_table_block.blocks.TypedTableBlock( + [ + ( + "rich_text", + wagtail.blocks.RichTextBlock(editor="plain"), + ), + ("numeric", wagtail.blocks.FloatBlock()), + ("text", wagtail.blocks.CharBlock()), + ] + ), + ), + ( + "iframe", + wagtail.blocks.StructBlock( + [ + ("url", wagtail.blocks.URLBlock()), + ( + "caption", + wagtail.blocks.RichTextBlock( + editor="plain", required=False + ), + ), + ] + ), + ), + ], + 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()), + ( + "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( + editor="plain", 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()), + ] + ), + ), + ( + "tangent", + wagtail.blocks.StructBlock( + [ + ("name", wagtail.blocks.CharBlock(max_length=64)), + ( + "content", + wagtail.blocks.RichTextBlock(editor="simple"), + ), + ] + ), + ), + ( + "mermaid", + wagtail.blocks.StructBlock( + [ + ("source", wagtail.blocks.TextBlock()), + ( + "caption", + wagtail.blocks.RichTextBlock( + editor="plain", required=False + ), + ), + ] + ), + ), + ( + "table", + wagtail.contrib.typed_table_block.blocks.TypedTableBlock( + [ + ( + "rich_text", + wagtail.blocks.RichTextBlock(editor="plain"), + ), + ("numeric", wagtail.blocks.FloatBlock()), + ("text", wagtail.blocks.CharBlock()), + ] + ), + ), + ( + "iframe", + wagtail.blocks.StructBlock( + [ + ("url", wagtail.blocks.URLBlock()), + ( + "caption", + wagtail.blocks.RichTextBlock( + editor="plain", required=False + ), + ), + ] + ), + ), + ], + blank=True, + use_json_field=True, + ), + ), + ] diff --git a/website/contact/migrations/0004_alter_contactpage_body.py b/website/contact/migrations/0004_alter_contactpage_body.py new file mode 100644 index 0000000..2518b6e --- /dev/null +++ b/website/contact/migrations/0004_alter_contactpage_body.py @@ -0,0 +1,126 @@ +# Generated by Django 4.1.8 on 2023-04-19 20:19 + +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", "0003_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()), + ( + "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( + editor="plain", 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()), + ] + ), + ), + ( + "tangent", + wagtail.blocks.StructBlock( + [ + ("name", wagtail.blocks.CharBlock(max_length=64)), + ( + "content", + wagtail.blocks.RichTextBlock(editor="simple"), + ), + ] + ), + ), + ( + "mermaid", + wagtail.blocks.StructBlock( + [ + ("source", wagtail.blocks.TextBlock()), + ( + "caption", + wagtail.blocks.RichTextBlock( + editor="plain", required=False + ), + ), + ] + ), + ), + ( + "table", + wagtail.contrib.typed_table_block.blocks.TypedTableBlock( + [ + ( + "rich_text", + wagtail.blocks.RichTextBlock(editor="plain"), + ), + ("numeric", wagtail.blocks.FloatBlock()), + ("text", wagtail.blocks.CharBlock()), + ] + ), + ), + ( + "iframe", + wagtail.blocks.StructBlock( + [ + ("url", wagtail.blocks.URLBlock()), + ( + "caption", + wagtail.blocks.RichTextBlock( + editor="plain", required=False + ), + ), + ] + ), + ), + ], + blank=True, + use_json_field=True, + ), + ), + ] diff --git a/website/contrib/code_block/blocks.py b/website/contrib/code_block/blocks.py index 81423a7..7c3e5e0 100644 --- a/website/contrib/code_block/blocks.py +++ b/website/contrib/code_block/blocks.py @@ -4,15 +4,9 @@ from django.utils.safestring import mark_safe from pygments import highlight from pygments.formatters.html import HtmlFormatter from pygments.lexers import find_lexer_class, get_all_lexers +from pygments.lexers.python import PythonConsoleLexer, PythonLexer from pygments.lexers.special import TextLexer -from wagtail.blocks import ( - BooleanBlock, - CharBlock, - ChoiceBlock, - StructBlock, - StructValue, - TextBlock, -) +from wagtail.blocks import CharBlock, ChoiceBlock, StructBlock, StructValue, TextBlock def get_language_choices() -> Iterator[tuple[str, str]]: @@ -21,6 +15,8 @@ def get_language_choices() -> Iterator[tuple[str, str]]: class CodeStructValue(StructValue): + LANGUAGE_DISPLAY_MAPPING = {PythonConsoleLexer.name: PythonLexer.name} + def code(self) -> str: lexer = find_lexer_class(self["language"])() formatter = HtmlFormatter( @@ -32,11 +28,17 @@ class CodeStructValue(StructValue): if filename := self["filename"]: return filename - if (language := self["language"]) != TextLexer.name: - return language + if self["language"] != TextLexer.name: + return self.language_display() return "" + def language_display(self) -> str: + """ + Map ugly language names to something more useful + """ + return self.LANGUAGE_DISPLAY_MAPPING.get(self["language"], self["language"]) + class CodeBlock(StructBlock): filename = CharBlock(max_length=128, required=False) @@ -44,7 +46,6 @@ class CodeBlock(StructBlock): choices=get_language_choices, ) source = TextBlock() - always_show_header = BooleanBlock(default=False, required=False) class Meta: icon = "code" diff --git a/website/contrib/code_block/templates/contrib/blocks/code.html b/website/contrib/code_block/templates/contrib/blocks/code.html index 05ecce7..95e7e29 100644 --- a/website/contrib/code_block/templates/contrib/blocks/code.html +++ b/website/contrib/code_block/templates/contrib/blocks/code.html @@ -1,7 +1,7 @@ {% if value.header_text %} -