5

I'm attempting to use Drupal as creating a pretty versatile code snippet site for storing all of my and others goodness. Yeah I know, sounds a bit familiar, but stick with me. What I'm having a hard time grasping is the best way to handle this in terms of both functionality and security.

At its simplest form, I'm thinking I'd create a Code content type with some taxonomy attributes, language type, etc. and then the actual 'body' of the node will be the code snippet itself. What I'm struggling on is, do I allow unfiltered text through here so anything and I mean anything can be put in and then on the node display just wrap the body in a code or pre block? I think then I could just wrap that with Google Prettify and bam, code snippets.

Am I way off with this? Is there something I'm missing with how that could conceptually work? In terms of security, it seems a single code or pre block from any code actually rendering sounds a bit scary - is that how normal code snippet sites work?

I've been fumbling around with ideas in my head, so any help to either lead me in the right direction or slap some sense into me would be greatly appreciated. Thanks!

  • 2
    I might not be following, but if you just use a plain text input filter/formatter, then all text entered will be properly sanitized, and then you just have to theme it the way you want it. – rfay Nov 27 '11 at 16:36
  • Ha, I was just thinking that. Makes logical sense and guess I needed a "don't over think it stupid" kind of nudge ;) Thanks! – Zach Nov 27 '11 at 19:56
  • And of course you can do what drupal.org does and just provide Codefilter module and add it to the filtered_html format and go with that. – rfay Nov 28 '11 at 20:42
  • Ah - very cool. Looks like this is only for PHP though - but maybe could be used for commenting on code snippets. Thanks! – Zach Nov 28 '11 at 20:44
2

I would definitely encourage you to look at the http://drupal.org/project/geshifilter input filter

From the page:

At the time of this writing the GeSHi library supports highlighting for more than 200 programming languages and configuration syntaxes, including: ActionScript, Ada, Apache Log, AppleScript, ASM, ASP, Bash, C, ColdFusion, C++, QT, C#, CSS, D, Delphi, Diff, DOS, dot, Eiffel, Fortran, Groovy, Haskell, HTML, INI, Inno, Java, Javascript, LaTeX, Lisp, Lua, Motorola 68000 Assembler, Matlab, mIRC Scripting, MySQL, Objective C, OCaml, OpenOffice.org Basic, Oracle 8 SQL, Pascal, Perl, PHP, PL/SQL, Python, QBasic/QuickBASIC, Rails, Microsoft Registry, robots.txt, Ruby, SAS, Scheme, Smalltalk, Smarty, SQL, TCL, Text, Visual Basic, vb.net, VHDL, XML, X++.

There is a stable D7 and D6 version.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.