When using version 3.0.83 of the syntax-highlighter library there is a javascript error in /src/shCore.js "XregExp not defined".

CommentFileSizeAuthor
#1 1230482-XregExp-not-defined.patch633 bytesmrfelton
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mrfelton’s picture

Status: Active » Needs review
FileSize
633 bytes
mrfelton’s picture

Version: 6.x-1.26 » 6.x-1.x-dev
mattyoung’s picture

Status: Needs review » Closed (works as designed)

This stackoverflow post explains why you are getting the error:

http://stackoverflow.com/questions/4937915/syntaxhighlighter-v3-0-83-sou...

The reason is XRegExp *is* embedded in the minified "scripts/shCore.js" but is *not* in "src/shCore.js".

We don't use "src/shCore.js", we only use "scripts/shCore.js". The module expressly ignores the "src" directory. So I don't know how you end up with "src/shCore.js". This should not be possible.

If you really want to use "src/shCore.js" for debug purpose, I suggest:

append XRegExp to the end of "src/shCore.js"
mv src/shCore.js scripts/shCore.js

then restore scripts/shCore.js when you are done.

mrfelton’s picture

Status: Closed (works as designed) » Active

No, not working as designed!

This was installed very simply from a drush make file

projects[syntaxhighlighter][version] = 1.26
projects[syntaxhighlighter][subdir] = contrib

libraries[syntaxhighlighter][download][type] = "get"
libraries[syntaxhighlighter][download][url] = "https://bitbucket.org/alexg/syntaxhighlighter/get/3.0.83.zip"
libraries[syntaxhighlighter][directory_name] = "syntaxhighlighter"

No funny business, no messing with the code. scripts/shCore.js is being loaded. XRegExp is not defined there.

mattyoung’s picture

The problem is the code from bitbucket is the source, it's only for development/debugging and not for "regular" usage. It needs to be "built" for normal deployment usage, which minify the code and embed XRegExp. (see the build dir inside the source).

So you should not download from bitbucket, instead download from:

http://alexgorbatchev.com/SyntaxHighlighter/download/download.php?sh_current

This give you the built version. This link is at http://alexgorbatchev.com/SyntaxHighlighter/download/

And FYI, the source is now at https://github.com/alexgorbatchev/SyntaxHighlighter

If you change the drush make, it should work without change.

mrfelton’s picture

Status: Active » Closed (works as designed)

Got it. Thanks for clearing that up.

mrfelton’s picture

Status: Closed (works as designed) » Needs work

nah, sorry but it doesn't work. Latest syntaxhighlighter downloaded from http://alexgorbatchev.com/SyntaxHighlighter/download/download.php?sh_cur.... Still does not work without my patch.

jdvc’s picture

Alex recently moved the syntax highlighter project to github, and I ran into the same exact issue after cloning from there as described in the stackoverflow discussion linked to in #3.

So don't clone it, just make sure to download the project from http://alexgorbatchev.com/SyntaxHighlighter/download/, other than that thanks for the awesome module!

mattyoung’s picture

Status: Needs work » Closed (works as designed)
morbiD’s picture

Version: 6.x-1.x-dev » 7.x-2.x-dev
Priority: Normal » Major
Issue summary: View changes
Status: Closed (works as designed) » Active

The download links in previous comments seemingly went dead at some point within the last 6 months and are producing 404 errors; the download link on the SyntaxHighlighter website now goes straight to the master branch on github instead.

You can still grab the pre-built version from snapshots on archive.org (last one was Nov 2016) but if that ever goes dead then the only way to make this module work will be to build the library from source, which apparently requires node.js.

Perhaps a better solution is now desirable?

ao2’s picture

The pre-built versions are available also on github: https://github.com/syntaxhighlighter/SyntaxHighlighter-Site/tree/master/...

So I guess the fix for D7 is to use this URL in the drush make file.

BTW the issue has been fixed in the D8 port I am working on.

ao2’s picture

Title: "XregExp not defined" error from syntaxhighlighter. » The URL of the pre-built archive is invalid
numerabilis’s picture

Aleluia! I found out what´s missing!!!
Mr. Felton, your patch didn´t run in Drupal 7.64 and Syntx Highlighter 7.x-2.0 so I decided to insert manually these lines in the file syntaxhighlighter.module:

  if (file_exists($scripts_path .'XRegExp.js')) {
   drupal_add_js($scripts_path .'XRegExp.js', 'module');
 }

I noticed in the page source that XRegExp.js was there but not together all other scripts.
So I realized I should do a little change to work out:

    if (file_exists($scripts_path .'XRegExp.js')) {
    drupal_add_js($scripts_path .'XRegExp.js', $js_options);
  }

Now it works!!! After soooooo many hours driving me crazy... so happy now!!! lol

This section became this:

function syntaxhighlighter_init() {
  if (!_syntaxhighlighter_page_match()) {
    return;
  }

  $lib_location = _syntaxhighlighter_get_lib_location();
  $styles_path = $lib_location . '/styles/';
  $scripts_path = $lib_location . '/scripts/';
  $js_options = array('type' => 'file', 'group' => JS_DEFAULT, 'every_page' => TRUE);


  drupal_add_css($styles_path . 'shCore.css');
  $theme = variable_get('syntaxhighlighter_theme', 'shThemeDefault.css');
  drupal_add_css($styles_path . $theme);

    if (file_exists($scripts_path .'XRegExp.js')) {
    drupal_add_js($scripts_path .'XRegExp.js', $js_options);
  }
  
  drupal_add_js($scripts_path . 'shCore.js', $js_options);
  if (variable_get('syntaxhighlighter_legacy_mode', 0)) {
    drupal_add_js($scripts_path . 'shLegacy.js', $js_options);
  }