Wagtail Code Block provides PrismJS syntax highlighting in Wagtail.
Project description
Wagtail Code Block
Wagtail Code Block is a syntax highlighted block for source code for the Wagtail CMS. It features real-time highlighting in the Wagtail editor, the front end, line numbering, and support for PrismJS themes.
It uses the PrismJS library both in Wagtail Admin and the website and requires jQuery.
Example Usage
from wagtailcodeblock.blocks import CodeBlock
class ContentStreamBlock(StreamBlock):
heading = TextBlock()
paragraph = TextBlock()
code = CodeBlock(label='Code')
You can also force it to use a single language by providing a language code which must be included in your WAGTAIL_CODE_BLOCK_LANGUAGES
setting:
code = CodeBlock(label='Bash Code', language='bash')
Screenshot of the CMS Editor Interface
Installation & Setup
To install Wagtail Code Block simply run:
pip install wagtailcodeblock
And add wagtailcodeblock
to your INSTALLED_APPS
setting:
INSTALLED_APPS = [
...
'wagtailcodeblock',
...
]
Django Settings
Themes
Wagtail Code Block defaults to the PrismJS "Coy" theme, which looks good with Wagtail's CMS editor design. You can choose a different theme by configuring WAGTAIL_CODE_BLOCK_THEME
in your Django settings. PrismJS provides several themes:
- None: Default
- 'coy': Coy
- 'dark': Dark
- 'funky': Funky
- 'okaidia': Okaidia
- 'solarizedlight': Solarized Light
- 'twilight': Twilight
For example, in you want to use the Solarized Light theme: WAGTAIL_CODE_BLOCK_THEME = 'solarizedlight'
If you want to use the Default theme: WAGTAIL_CODE_BLOCK_THEME = None
Languages Available
You can customize the languages available by configuring WAGTAIL_CODE_BLOCK_LANGUAGES
in your Django settings.
By default, it will be set with these languages, since most users are in the Python web development community:
WAGTAIL_CODE_BLOCK_LANGUAGES = (
('bash', 'Bash/Shell'),
('css', 'CSS'),
('diff', 'diff'),
('html', 'HTML'),
('javascript', 'Javascript'),
('json', 'JSON'),
('python', 'Python'),
('scss', 'SCSS'),
('yaml', 'YAML'),
)
Each language in this setting is a tuple of the PrismJS code and a descriptive label. If you want use all available languages, here is a list:
WAGTAIL_CODE_BLOCK_LANGUAGES = (
('abap', 'ABAP'),
('abnf', 'Augmented Backus–Naur form'),
('actionscript', 'ActionScript'),
('ada', 'Ada'),
('apacheconf', 'Apache Configuration'),
('apl', 'APL'),
('applescript', 'AppleScript'),
('arduino', 'Arduino'),
('arff', 'ARFF'),
('asciidoc', 'AsciiDoc'),
('asm6502', '6502 Assembly'),
('aspnet', 'ASP.NET (C#)'),
('autohotkey', 'AutoHotkey'),
('autoit', 'AutoIt'),
('bash', 'Bash + Shell'),
('basic', 'BASIC'),
('batch', 'Batch'),
('bison', 'Bison'),
('bnf', 'Backus–Naur form + Routing Backus–Naur form'),
('brainfuck', 'Brainfuck'),
('bro', 'Bro'),
('c', 'C'),
('clike', 'C-like'),
('csharp', 'C#'),
('cpp', 'C++'),
('cil', 'CIL'),
('coffeescript', 'CoffeeScript'),
('clojure', 'Clojure'),
('crystal', 'Crystal'),
('csp', 'Content-Security-Policy'),
('css', 'CSS'),
('css-extras', 'CSS Extras'),
('d', 'D'),
('dart', 'Dart'),
('diff', 'Diff'),
('django', 'Django/Jinja2'),
('docker', 'Docker'),
('ebnf', 'Extended Backus–Naur form'),
('eiffel', 'Eiffel'),
('ejs', 'EJS'),
('elixir', 'Elixir'),
('elm', 'Elm'),
('erb', 'ERB'),
('erlang', 'Erlang'),
('fsharp', 'F#'),
('flow', 'Flow'),
('fortran', 'Fortran'),
('gcode', 'G-code'),
('gedcom', 'GEDCOM'),
('gherkin', 'Gherkin'),
('git', 'Git'),
('glsl', 'GLSL'),
('gml', 'GameMaker Language'),
('go', 'Go'),
('graphql', 'GraphQL'),
('groovy', 'Groovy'),
('haml', 'Haml'),
('handlebars', 'Handlebars'),
('haskell', 'Haskell'),
('haxe', 'Haxe'),
('hcl', 'HCL'),
('http', 'HTTP'),
('hpkp', 'HTTP Public-Key-Pins'),
('hsts', 'HTTP Strict-Transport-Security'),
('ichigojam', 'IchigoJam'),
('icon', 'Icon'),
('inform7', 'Inform 7'),
('ini', 'Ini'),
('io', 'Io'),
('j', 'J'),
('java', 'Java'),
('javadoc', 'JavaDoc'),
('javadoclike', 'JavaDoc-like'),
('javascript', 'JavaScript'),
('javastacktrace', 'Java stack trace'),
('jolie', 'Jolie'),
('jsdoc', 'JSDoc'),
('js-extras', 'JS Extras'),
('json', 'JSON'),
('jsonp', 'JSONP'),
('json5', 'JSON5'),
('julia', 'Julia'),
('keyman', 'Keyman'),
('kotlin', 'Kotlin'),
('latex', 'LaTeX'),
('less', 'Less'),
('liquid', 'Liquid'),
('lisp', 'Lisp'),
('livescript', 'LiveScript'),
('lolcode', 'LOLCODE'),
('lua', 'Lua'),
('makefile', 'Makefile'),
('markdown', 'Markdown'),
('markup', 'Markup + HTML + XML + SVG + MathML'),
('markup-templating', 'Markup templating'),
('matlab', 'MATLAB'),
('mel', 'MEL'),
('mizar', 'Mizar'),
('monkey', 'Monkey'),
('n1ql', 'N1QL'),
('n4js', 'N4JS'),
('nand2tetris-hdl', 'Nand To Tetris HDL'),
('nasm', 'NASM'),
('nginx', 'nginx'),
('nim', 'Nim'),
('nix', 'Nix'),
('nsis', 'NSIS'),
('objectivec', 'Objective-C'),
('ocaml', 'OCaml'),
('opencl', 'OpenCL'),
('oz', 'Oz'),
('parigp', 'PARI/GP'),
('parser', 'Parser'),
('pascal', 'Pascal + Object Pascal'),
('perl', 'Perl'),
('php', 'PHP'),
('phpdoc', 'PHPDoc'),
('php-extras', 'PHP Extras'),
('plsql', 'PL/SQL'),
('powershell', 'PowerShell'),
('processing', 'Processing'),
('prolog', 'Prolog'),
('properties', '.properties'),
('protobuf', 'Protocol Buffers'),
('pug', 'Pug'),
('puppet', 'Puppet'),
('pure', 'Pure'),
('python', 'Python'),
('q', 'Q (kdb+ database)'),
('qore', 'Qore'),
('r', 'R'),
('jsx', 'React JSX'),
('tsx', 'React TSX'),
('renpy', 'Ren\'py'),
('reason', 'Reason'),
('regex', 'Regex'),
('rest', 'reST (reStructuredText)'),
('rip', 'Rip'),
('roboconf', 'Roboconf'),
('ruby', 'Ruby'),
('rust', 'Rust'),
('sas', 'SAS'),
('sass', 'Sass (Sass)'),
('scss', 'Sass (Scss)'),
('scala', 'Scala'),
('scheme', 'Scheme'),
('smalltalk', 'Smalltalk'),
('smarty', 'Smarty'),
('sql', 'SQL'),
('soy', 'Soy (Closure Template)'),
('stylus', 'Stylus'),
('swift', 'Swift'),
('tap', 'TAP'),
('tcl', 'Tcl'),
('textile', 'Textile'),
('toml', 'TOML'),
('tt2', 'Template Toolkit 2'),
('twig', 'Twig'),
('typescript', 'TypeScript'),
('t4-cs', 'T4 Text Templates (C#)'),
('t4-vb', 'T4 Text Templates (VB)'),
('t4-templating', 'T4 templating'),
('vala', 'Vala'),
('vbnet', 'VB.Net'),
('velocity', 'Velocity'),
('verilog', 'Verilog'),
('vhdl', 'VHDL'),
('vim', 'vim'),
('visual-basic', 'Visual Basic'),
('wasm', 'WebAssembly'),
('wiki', 'Wiki markup'),
('xeora', 'Xeora + XeoraCube'),
('xojo', 'Xojo (REALbasic)'),
('xquery', 'XQuery'),
('yaml', 'YAML'),
)
Change Log
1.15.0.0
- Update to PrismJS 1.15.0
- Bug fix: do not key off of
Language
label, as it is translatable.
1.14.0.0
- Upgrade to PrismJS 1.14.0
- Allow passing a language code as an attribute, only allowing the single language to be used.
- Fix conflict in CSS between
tag
class for Wagtail and markup syntax types.
1.11.0.0
- Upgrade to PrismJS 1.11.0
- Changed version numbers to match the included PrismJS release
- Patch to add support for natively included PrismJS languages ['html', 'mathml', 'svg', 'xml']
0.4
- Support for Wagtail 2.0
0.4.1
- Upgrade to PrismJS 1.9.0, which includes a patch we made to the 'coy' theme we use as a default.
0.3
- Support for PrismJS themes
0.3.1
- Bug fixes for some front-end issues. Update documentation.
Project Maintainers
- Timothy Allen (https://github.com/FlipperPA)
- Milton Lenis (https://github.com/MiltonLn)
Contributors
- José Luis (https://github.com/SalahAdDin)
- Lucas Moeskops (https://github.com/lucasmoeskops)
- Nick Sarbicki (https://github.com/NDevox)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file wagtailcodeblock-1.15.0.0.tar.gz
.
File metadata
- Download URL: wagtailcodeblock-1.15.0.0.tar.gz
- Upload date:
- Size: 145.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ca7827402d8ad9b75d82e06c5bf6694be98ffd9cdfd96e9d8de0209c5c40d8ea |
|
MD5 | 9d18895ccf94cd499da41e06883ac637 |
|
BLAKE2b-256 | 84387f02563fcb5e3758e0b57496e7aa671b81336cb7bcb5c131cafa7391fda2 |
File details
Details for the file wagtailcodeblock-1.15.0.0-py3-none-any.whl
.
File metadata
- Download URL: wagtailcodeblock-1.15.0.0-py3-none-any.whl
- Upload date:
- Size: 160.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 42fe1f77d3f898e193a7b71d590527ed920de8d6c9416db49d96ef0fbd0fd0ec |
|
MD5 | 5057dc1d89a5ecde32aaf32d57e0b3ba |
|
BLAKE2b-256 | 75bb920d1f67e1a8be1588c005fe8380d923e96cc0a0168a132390533e81d7ce |