Content
Code snippet formatting not working
If I use the code snippet and add say Python and I change the format type by manually typing 'python', the formatting in the editor autoformats. But when I save and review it the formatting it gone and it's just all black text. No python formatting.
Questions:
- How to fix this?
- What formatting types can be entered?
- Why isn't there a selector to show which formats are available instead of assuming the end user knows exactly which languages are supported and what exactly to type?
- Am I doing it all wrong?
Hi Jason,
this is due to CKEditor not yet providing a WYSIWYG code block. We added a custom widget that is based on codemirror that allows dynamically loading syntax and highlight modes from these values here: https://github.com/codemirror/CodeMirror/tree/master/mode
Highlight will thus only work within the codemirror editor (double click the widget in CKEditor to open the editor modal again), and when you save the page. This widget is only meant as a workaround until CKEditor provides their own code block implementation: https://github.com/ckeditor/ckeditor5/issues/436
There is of course lots of room for improvements, it's not our topmost priority at the moment since hopefully, CKEditor5 will provide the correct solution.
- The syntax highlighting mode name must be guessed or known. This is the same as writing plain Markdown, where you highlighted your blocks in Markdown with a given marker
```ruby\n.... - CodeMirror has its own styles and thus the highlighting rendered from the backend differs (its using rouge syntax highlighter)
- Ideally we would always render the open WYSIWYG editor that highlights its own code blocks
Best,
Oliver