Prettify module for syntax highlighting of code

We encourage users to post events happening in the community to the community events group on https://www.drupal.org.
egil's picture

Hi all,

I created a module (my first) that enables syntax highlighting of source code snippets in nodes. The module uses the google-code-prettify JavaScript library to do the highlighting (http://code.google.com/p/google-code-prettify/).

It works in a none-obtrusive through an input filter, that looks for all pre or code tags and modifies then as needed to enable the highlighting. That has the benefit of making it easy to replace or remove later, as the original node text is not modified.

The administrator can also control the styling and add support for additional programming languages through an configuration section.

Right now the code is just hosted on my github account. I did search through existing modules and did not find any existing ones that uses Prettify, but even if there are some, this was a good learning experience for me.

Code available at: https://github.com/egil/prettify-drupal

Any feedback is much appreciated.

Regards, Egil.

Comments

Great!

othermachines's picture

This would be useful for us-- looking forward to trying it out. Cheers-

Good to know

egil's picture

Goad to hear it. Now I just have to figure out how to create a project here on drupal.org then :)

I'd like to see this as a

Niklas Fiekas's picture

I'd like to see this as a full project. Thank you for creating it, it will be useful when writing about code.

From a superficial look:

  • You should move all files from the prettify directory to the toplevel of the directory structure.
  • Then strip out all third party code and add instructions to the README instead, on how to download it and where to put it (licensing issue).
  • Create a sandbox project on drupal.org.
  • Apply for a full project: http://drupal.org/node/1011698 - someone will review your project in more detail and guide you through the process - but that might take some time.

Thanks

egil's picture

Thanks for the help.

I would prefer to include the library in the, and as far as I can see, it is under Apache License 2.0, so it should be OK from a licensing point of view, or?

Don't take my word for it,

Niklas Fiekas's picture

Don't take my word for it, but I think code under the Apache License 2.0, though that is an open source license, must not be in the project repository. Drupal.org's licensing is pretty strict about only accepting GPL.

If your project requires the use of third party libraries, provide installation instructions directing the user to where they may find the library, and how to install it.
If you are including 3rd party libraries or images in your project, provide details within your application directing reviewers on where they can independently verify the library's GPL license.

-- http://drupal.org/node/1187664

Guess your right

egil's picture

I will have re-code the module a bit to make it easy to add the library. I assume that it is OK for me to include CSS files from the theme page (http://google-code-prettify.googlecode.com/svn/trunk/styles/index.html) since I have modified them slightly to make then unobtrusive, which would also make the module much easier to use, and they are renamed to make sure there are no conflicts in the Drupal CSS system (prefixed with "prettify-").

Even 3rd party GPL isn't generally allowed

sreynen's picture

Even if it were GPL, Drupal.org doesn't generally (there are very few exceptions) allow hosting of code you didn't write in your project. See: http://drupal.org/node/422996

Third party scripts

mac2000's picture

As i understand third party scripts must be in /sites/all/libraries folder not in module so user must manualy download library, benefit of it is that user will have latest version. Also it will be good to add drush make file - so all needed files downloads automaticaly.

Why don't you use

Seems to be the right way

egil's picture

Hey Fidelix,

I dont like taking a dependency on another module if it is not necessary, but the Libraries module seem to be stable and under active development, and it looks like the right fit for my situation, so I will most likely use that. Thanks for your input.

egil, I strongly believe that

Fidelix's picture

egil, I strongly believe that your line of thought is correct.
However, there are some times that a "supposedly" unnecessary dependence is actually for the greater good.

Besides, you are able to use libraries API and don't actually depend on it.
Just check if the library folder exists in the same folder of the module, ELSE, check if libraries API is installed with module_exists() or function_exists(), and then use it.

Doesn't look like an issue to me, and there are modules currently doing this. ^^

Anyway, my best wishes with your development process.

First publish to drupal.org is up

egil's picture

Hey all,

Thanks for all the feedback, now I need more.

I just finished the modifications to the module to make it dependent on Libraries API and other small fixes. It is now available at http://drupal.org/sandbox/egil/1232772

Please provide any comments and feedback before I request it to be full project.