Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+3 votes
1.0k views
in Plugins by
Do you guys know which plugin or editor to use in Question2Answer for inserting code snippets in my posts?

Let's say I need to share a code on Python or on Bash. If I will just paste my code, all formatting will be gone.

Any suggestions? Thanks!
Q2A version: 1.8.2

1 Answer

+1 vote
by

Take a look at this: https://ckeditor.com/docs/ckeditor4/latest/examples/codesnippet.html.

In there, you'll find a reference to https://ckeditor.com/cke4/addon/codesnippet. That's a CKEditor plugin. Try installing it following the steps in here: https://www.question2answer.org/qa/66264

This is the most up-to-date approach to follow.

by
edited by
Thanks for your help! I left a comment in  https://www.question2answer.org/qa/66264. In brief, I followed all listed steps, but nothing changed. I still have my old editor.

UPDATE. It finally worked. In order to enable it, I used config.js from the new version of CKEditor. Despite the fact that you recommended to merge or replace this file with the old one

"Theoretically, you should merge the files ckeditor/styles.js and ckeditor/config.js from the Q2A CKEditor and the new one. If you don't know the word merge then plan B would be to replace those files in the new CKEditor with the ones from the Q2A CKEditor"

HOWEVER, I still have an issue. Somehow formatting (text highlighting) works only when I edit the answer. Once the post is saved, the font is pale

Here is the screenshot: https://ibb.co/z78LpXW

And this is how it looks when I am in the editing mode:  https://ibb.co/3MfwrVZ

Any ideas why the code is pale?
by
+1
Well, "merging" does not mean "replacing". That's why "replacing" is a plan B :D

Check here to find out how to render the appropriate formatting: https://ckeditor.com/docs/ckeditor4/latest/guide/dev_codesnippet.html
by
Thanks! It finally works after activating the following js and css in the head section of the website: https://highlightjs.org/download/
by
+1
As simple as that. BTW, no need to say thanks: upvoting/accepting answers is the way to say thanks in a Q&A site :)
by
I also needed to add this
<script>hljs.initHighlightingOnLoad();</script>
to admin->layout->custom HTML at the bottom of every page
...