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!
This would be useful for us-- looking forward to trying it out. Cheers-
Good to know
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
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:
Thanks
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,
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.
-- http://drupal.org/node/1187664
Guess your right
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
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
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
Why don't you use http://drupal.org/project/libraries ?
Seems to be the right way
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
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
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.