Considering how powerful the new Geshi Filter Drupal Module is now, I thought I'd have my try at recreating a PasteBin web application using Drupal. The outcome was: DrupalBin.

To make it more helpful for Drupal developers, I started work on a Drupal language definition for Geshi syntax highlighting of Drupal code. So far there are only a small group of Drupal functions and constants in there, but it's slowly growing. I think the best example of it in use is at drupalbin.com/4, where you can click on "drupal_site_offline()", and it takes you to the documentation. The language file is attached (drupal.php), which you can just stick into the Geshi language directory. Work will continue on this, and as updates come, I'll re-upload the file here.

As a side note, soxofaan, would you like to help out with DrupalBin?

Comments

soxofaan’s picture

Good Idea,

Would you want me to put it in CVS already?
For example in a directory 'misc' or something?

robloach’s picture

Not sure where it would go... I've been trying to utilize the API module to automatically output all constants and functions in a comma-separated format, but can't get it.

robloach’s picture

Just saw this, a script to generate a list of Drupal functions from source.

soxofaan’s picture

StatusFileSize
new32.38 KB

I've written this small Python script to extract function names and "define" constants:

#!/usr/bin/env python

import os
import re
import sys

# get drupal path from command line
try:
  drupal_path = sys.argv[1]
except IndexError:
  print "usage: %s drupal_path" % sys.argv[0]
  sys.exit()

# get source code files from includes and modules directories
source_code_files = []
for subdir in ['includes', 'modules']:
  for data in os.walk(os.path.join(drupal_path, subdir)):
    for filename in data[2]:
      if os.path.splitext(filename)[1] in ['.php', '.module', '.inc']:
        source_code_files.append(os.path.join(data[0], filename))

# regular expression pattern for getting function names
function_name_rep = re.compile(r'^function\s+([a-zA-Z0-9_]+)\s*\(')
# regular expression pattern for getting constant_names
constant_rep = re.compile(r'^(define|DEFINE)\(["\']([A-Z0-9_]+)')

function_names = []
constant_names = []
for filename in source_code_files:
  for line in file(filename):
    match = function_name_rep.match(line)
    if match:
      function_names.append(match.group(1))
    match = constant_rep.match(line)
    if match:
      constant_names.append(match.group(2))

print "function names:"
print function_names

print "constant names:"
print constant_names

result for Drupal 5.2 in attachment

robloach’s picture

Status: Active » Needs review
StatusFileSize
new55.37 KB

Nice one! The attached is drupal.php, which acts as the Geshi language filter found on DrupalBin.

Mind if we put this in the CVS? I think putting it into
contributions/modules/geshifilter/drupal.php
... would be fine. It's your call. Also, can I have CVS write access so whenever I make a change to this, I can reflect the changes in the CVS?

robloach’s picture

StatusFileSize
new55.39 KB

Put in some installation instructions.

soxofaan’s picture

Title: Drupal Highlighting for Geshi » Drupal Highlighting for GeSHi

Maybe it's better to create a directory 'geshi_extra' where users can put their custom language definitions (and where drupal.php would be by default). Just like one should put contrib drupal modules in "/sites/all/modules" instead of "/modules" to keep the drupal core directories clean.
I think it is possible to make GeSHi also scan extra directories for language definitions. But I'll have to look into this.

wim leers’s picture

Subscribing. Awesome work guys :)

soxofaan’s picture

Status: Needs review » Fixed

fixed in
http://drupal.org/cvs?commit=91131 : GeSHi filter module now also looks for language definition files in geshi-extra directory, added drupal5 and drupal6 definition files

soxofaan’s picture

Version: 6.x-1.x-dev » 5.x-2.x-dev
Assigned: robloach » soxofaan
Christefano-oldaccount’s picture

After updating to 5.x-2.3 the language cache needed to be flushed but now GeSHi is better than ever. Thanks guys.

soxofaan’s picture

After updating to 5.x-2.3 the language cache needed to be flushed

Did you run update.php?
I added a hook_update_N() function for flushing that cache automatically on the update to 5.x-2.3.

Thanks

Christefano-oldaccount’s picture

Oops, it looks like I missed that. Thanks for the reminder.

robloach’s picture

I've updated to GeSHi Filter 2.3 on DrupalBin.

Anonymous’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.