2

Can anyone recommend a module or other Drupal add-on that can be used to format code nicely like I see on a lot of blogs and websites? Ideally something that would integrate with CKeditor, but that's not critical, I can make do with HTML tags if need be. Thanks.

1

5 Answers 5

4

The two most popular Drupal modules seem to be Code Filter and GeSHi Filter for syntax highlighting. For getting GeSHi to work with CKeditor, check out the WYSIWYG - GeSHi bridge module.

Sign up to request clarification or add additional context in comments.

1 Comment

I'm going to try GeSHi with the WYSIWYG bridge. This looks promising, and it does MATLAB code too, which I was hoping to find but didn't see in any of the other options. Thanks.
1

Well, there's http://alexgorbatchev.com/SyntaxHighlighter/ which is javascript. It gets applied at view time.

To see your code highlighted in the actual editor, you're probably going to have to work a bit harder. If it were me, I'd start with http://ace.ajax.org/ , which is an editor that grew out of Mozilla's constantly-renamed in-browser IDE project.

2 Comments

I tried Syntax Highlighter before I posted here, and it didn't seem to be working for me. Not sure if I configured something wrong, but I followed the instructions closely and all my code still came out as plain text. I'm going to try GeSHi as suggested by Matt next.
SyntaxHighlighter is still the best option in my opinion and works nicely in WYSIWYG (CKEditor) using drupal.org/project/syntaxhighlighter_insert.
0

Maybe it's to much but check this http://drupal.org/project/grammar_parser_ui

Comments

0

Quick follow up: as per this post, the WYSIWYG-GeSHi bridge development has been put on hold because of some problems integrating GeSHi buttons into CKeditor's toolbar (they make all the other buttons disappear). I can confirm that this is the case.

However, if I use GeSHi tags in HTML source, they do format things correctly. The really key thing left out of the GeSHi module documentation is that you need to enable it as an input format in Drupal.

Next I'm going to try this method for integrating GeSHi formatting directly into CKeditor without using the WISYWIG module or any bridges. Thanks again for everyone's help.

Comments

0

There's the Prettify module that implements Google Code Prettify as JS library. It works out of the box but it appears to duplicate the pre tags, that is, one pre tag appears as container for the other one:

    <pre class="prettyprint prettyprinted">
        <pre class="prettyprint">
            <code>
            .myClass {
                <br>
                float: left;
            <br>
            }
            </code>
        </pre>
    </pre>

That's only annoying because you can't really style the pre tag if there's two of them because all your styles are duplicated leading to double margins, padding, borders. etc.

Still, it works out of the box if you can deal with using the default styles provided with the module, and there are a number of them, i.e. Google Code, Stackoverflow etc.enter link description here

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.