You are here

function syntaxhighlighter_page_attachments in Syntax Highlighter 8

Implements hook_page_attachments().

File

./syntaxhighlighter.module, line 141
Syntax highlight code using the SyntaxHighlighter Javascript library.

Code

function syntaxhighlighter_page_attachments(array &$attachments) {
  if (!_syntaxhighlighter_page_match()) {
    return;
  }
  $config = \Drupal::config('syntaxhighlighter.settings');
  $attachments['#attached']['library'][] = 'syntaxhighlighter/core';
  if ($config
    ->get('legacy_mode')) {
    $attachments['#attached']['library'][] = 'syntaxhighlighter/legacy';
    $settings['legacyMode'] = TRUE;
  }
  if ($config
    ->get('use_autoloader')) {
    $attachments['#attached']['library'][] = 'syntaxhighlighter/autoloader';
    $settings['useAutoloader'] = TRUE;
  }
  else {
    $attachments['#attached']['library'][] = 'syntaxhighlighter/brushes';
  }
  $tag_name = $config
    ->get('tagname');
  if ($tag_name !== 'pre') {
    $settings['tagName'] = $tag_name;
  }
  $lib_location = libraries_get_path('syntaxhighlighter');
  $scripts_path = $lib_location . '/scripts/';
  if (file_exists($scripts_path . 'clipboard.swf')) {
    $settings['clipboard'] = base_path() . $scripts_path . 'clipboard.swf';
  }
  $default_expressions = $config
    ->get('default_expressions');
  if ($default_expressions) {
    $settings['default_expressions'] = $default_expressions;
  }
  if (isset($settings)) {
    $attachments['#attached']['drupalSettings']['syntaxhighlighter'] = $settings;
  }
  $attachments['#attached']['library'][] = 'syntaxhighlighter/syntaxhighlighter';
}