Using library version 3.0.83 I can't enable the autoloader function.
Autoloader is not available, update to the latest version of the Syntaxhighlighter javascript library to get this functionality.

Comments

mattyoung’s picture

This indicates the autoloader was not found for some reason. Can you look in the syntaxhighlighter js library, inside the script directory to see if there is the file "shAutoloader.js"? The directory should contain these files:

shAutoloader.js		shBrushErlang.js	shBrushRuby.js
shBrushAS3.js		shBrushGroovy.js	shBrushSass.js
shBrushAppleScript.js	shBrushJScript.js	shBrushScala.js
shBrushBash.js		shBrushJava.js		shBrushSql.js
shBrushCSharp.js	shBrushJavaFX.js	shBrushVb.js
shBrushColdFusion.js	shBrushPerl.js		shBrushXml.js
shBrushCpp.js		shBrushPhp.js		shCore.js
shBrushCss.js		shBrushPlain.js		shLegacy.js
shBrushDelphi.js	shBrushPowerShell.js
shBrushDiff.js		shBrushPython.js

Can you try downloading the syntaxhighlighter js library again and re-install?

jelle_s’s picture

The file is where it's supposed to be but I did manage to find the problem.

I'm working with wamp and printed the path where it looks for the autoloader.
The printed path was:

C:/wamp/www//sites/all/libraries/syntaxhighlighter_3.0.83/scripts/shAutoloader.js 

I placed my drupal installation in a map called 'drupal' in my www folder, as you can see, this folder isn't included in the path.
This is because $_SERVER['DOCUMENT_ROOT'] returns "C:/wamp/www/" (with trailing slash), and $path . '/scripts/shAutoloader.js' returns "/sites/all/libraries/syntaxhighlighter_3.0.83/scripts/shAutoloader.js" (with beginning slash).

So I found two suggestions for a solution.

  1. If you want to keep the absolute path change line 27 in syntashighlighter.admin.inc from
    <?php
       $autoloader_available = file_exists($_SERVER['DOCUMENT_ROOT'] . '/' . $path . '/scripts/shAutoloader.js');
    ?>
    

    to

    <?php
       $autoloader_available = file_exists(substr($_SERVER['DOCUMENT_ROOT'], 0, -1) . base_path() . $path . '/scripts/shAutoloader.js');
    ?>
    

    (The substring is needed or you will have to forward slashes right after each other)



  2. You could also work with a relative path and change line 27 in syntashighlighter.admin.inc from
    <?php
       $autoloader_available = file_exists($_SERVER['DOCUMENT_ROOT'] . '/' . $path . '/scripts/shAutoloader.js');
    ?>
    

    to

    <?php
       $autoloader_available = file_exists($path . '/scripts/shAutoloader.js');
    ?>
    

    This way the path is always relative to the drupal installation folder

Personally, I would recommend the second solution, as I don't know how the first will react on a server, I haven't tested that yet.

I hope this helps :-)

mattyoung’s picture

Version: 7.x-1.0 » 7.x-1.x-dev
Status: Active » Needs review

Thanks for figuring this out. I took your recommendation and do the search with relative path. It's check in to HEAD. Can you test the 'dev' version?

jelle_s’s picture

I can enable the autoloader now, with the def version, but it still isn't working. I'll figure out why and give you more details asap.

jelle_s’s picture

I figured out the problem. I'm guessing this problem is windows-related only.
_syntaxhighlighter_file_directory_path() returns "\sites\default\files" on my wampserver (notice the backslashes).
So on ~ line 92 of syntaxhighlighter.module you do

<?php
drupal_add_js(_syntaxhighlighter_file_directory_path() . '/syntaxhighlighter.autoloader.js', $js_options);
?>

this, in my case, comes down to

<?php
drupal_add_js('\sites\default\files/syntaxhighlighter.autoloader.js', $js_options);
?>

so backslashes and forward slashes are mixed in the file path, which my browser appearantly doesn't like.
So you could fix this, for now, by changing line 443 of syntaxhighlighter.module from

<?php
/**
 * This does the same thing as the old D6 file_directory_path() which
 * is to give the default 'files' directory path relative the the web root
 * 
 * @return a string containing the path to the site's 'files' directory
 */
function _syntaxhighlighter_file_directory_path() {
  return substr(drupal_realpath('public://'), strlen(DRUPAL_ROOT) + 1);
}
?>

to

<?php
/**
 * This does the same thing as the old D6 file_directory_path() which
 * is to give the default 'files' directory path relative the the web root
 * 
 * @return a string containing the path to the site's 'files' directory
 */
function _syntaxhighlighter_file_directory_path() {
  return str_replace('\\', '/', substr(drupal_realpath('public://'), strlen(DRUPAL_ROOT) + 1));
}
?>

(basically replacing backslashes with forward slashes)
Although this seems more like an issue for the drupal_realpath function to me.

And then, finally, my last point:
Probably because I didn't read the documentation right, but I assumed enabling the autoloader just loaded the brushes dynamically, regardless whether they were enabled or not. Appearantly they still need to be enabled to be autoloaded, my mistake.

So I think that resolves the autoloader issue.

And may I just say:
This really is a great module.

mattyoung’s picture

Thank you for figuring out the problem. I added your fix to replace "\" with "/".

Although this seems more like an issue for the drupal_realpath function to me.

I don't know what to make of this. If drupal_realpath() only returns "/", then it's different from DRUPAL_ROOT, which get its value from getcwd() which gives "\" under Windows. However, drupal_get_path() does always return "/".

I assumed enabling the autoloader just loaded the brushes dynamically, regardless whether they were enabled or not. Appearantly they still need to be enabled to be autoloaded, my mistake.

To avoid this confusion, I added a little bit of javascript to turn on all languages when the "Autoloader" is turn on.

Please test the "dev" version.

jelle_s’s picture


I don't know what to make of this. If drupal_realpath() only returns "/", then it's different from DRUPAL_ROOT, which get its value from getcwd() which gives "\" under Windows. However, drupal_get_path() does always return "/".

Yes, exactly my point.
It seems to me that there could be more consitency in those functions, just to avoid confusion,
or maybe that's more like a feature request... Anyway, it's not really an issue for this module,
or at least not anymore :P

I will test the dev version as soon as I find some time to do it.

jelle_s’s picture

Status: Needs review » Reviewed & tested by the community

Everything seems to work. As far as I can tell, the bugs seem to be fixed.

mattyoung’s picture

Version: 7.x-1.x-dev » 7.x-1.1
Status: Reviewed & tested by the community » Closed (fixed)