Skip to content

Commit

Permalink
Remove CodeBlock (Formatted Code Block)
Browse files Browse the repository at this point in the history
  • Loading branch information
FlipperPA authored and vsalvino committed Dec 14, 2018
1 parent 1e9564a commit 6c5eba5
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 67 deletions.
1 change: 0 additions & 1 deletion coderedcms/blocks/__init__.py
Expand Up @@ -26,7 +26,6 @@
('quote', QuoteBlock()),
('table', TableBlock()),
('google_map', EmbedGoogleMapBlock()),
('code', CodeBlock()),
]

CONTENT_STREAMBLOCKS = HTML_STREAMBLOCKS + [
Expand Down
53 changes: 0 additions & 53 deletions coderedcms/blocks/html_blocks.py
Expand Up @@ -3,12 +3,7 @@
with additional styling and attributes.
"""

from django.utils.html import format_html
from django.utils.safestring import mark_safe
from django.utils.translation import ugettext_lazy as _
from pygments import highlight
from pygments.lexers import get_all_lexers, get_lexer_by_name
from pygments.formatters import HtmlFormatter
from wagtail.contrib.table_block.blocks import TableBlock as WagtailTableBlock
from wagtail.core import blocks
from wagtail.documents.blocks import DocumentChooserBlock
Expand All @@ -29,54 +24,6 @@ class Meta:
value_class = LinkStructValue


class CodeBlock(BaseBlock):
"""
Source code with syntax highlighting in a <pre> tag.
"""
LANGUAGE_CHOICES = []

for lex in get_all_lexers():
LANGUAGE_CHOICES.append((lex[1][0], lex[0]))

language = blocks.ChoiceBlock(
required=False,
choices=LANGUAGE_CHOICES,
label=_('Syntax highlighting'),
)
title = blocks.CharBlock(
required=False,
max_length=255,
label=_('Title'),
)
code = blocks.TextBlock(
classname='monospace',
rows=8,
label=('Code'),
help_text=_('Code is rendered in a <pre> tag.'),
)

def get_context(self, value, parent_context=None):
ctx = super(CodeBlock, self).get_context(value, parent_context)

if value['language']:
src = value['code'].strip('\n')
lexer = get_lexer_by_name(value['language'])
code_html = mark_safe(highlight(src, lexer, HtmlFormatter()))
else:
code_html = format_html('<pre>{}</pre>', value['code'])

ctx.update({
'code_html': code_html,
})

return ctx

class Meta:
template = 'coderedcms/blocks/code_block.html'
icon = 'fa-file-code-o'
label = _('Formatted Code')


class DownloadBlock(ButtonMixin, BaseBlock):
"""
Link to a file that can be downloaded.
Expand Down
40 changes: 40 additions & 0 deletions coderedcms/migrations/0005_alter_content_field.py

Large diffs are not rendered by default.

12 changes: 0 additions & 12 deletions coderedcms/templates/coderedcms/blocks/code_block.html

This file was deleted.

1 change: 0 additions & 1 deletion setup.py
Expand Up @@ -45,7 +45,6 @@
'django>=1.11,<2.2',
'geocoder>=1.38.1,<2.0',
'icalendar==4.0.*',
'pygments>=2.2.0,<3.0',
'wagtail==2.3.*',
'wagtailfontawesome>=1.1.3,<2.0',
'wagtail-cache==0.2.*',
Expand Down

0 comments on commit 6c5eba5

Please sign in to comment.