不去在乎结果,热情地付出过,就好了.

添加代码高亮插件

很早就有这个需求,

像什么切换可视化和HTML的时候,代码乱成一坨,

样式特别丑什么的,

现在终于加上了,

其实网上有非代码实现方法,不过要改很多文件,

如果必须要重建博客,恢复起来很麻烦,就用插件吧.

插件下载地址:SyntaxHighlighter Evolved

下面是测试

<?php
if (!defined('MEDIAWIKI'))
  exit(1);

$wgExtensionFunctions[] = "wfSyntaxHighlighterExtension";

$wgExtensionCredits['other'][] = array(
  'name' => 'SyntaxHighlighter',
  'author' => array('Alex Gorbatchev'),
  'version' => '1.0',
  'url' => 'http://alexgorbatchev.com/projects/syntaxhighlighter',
  'description' => 'Provides tight integration with SyntaxHighlighter.'
);

// Path to the SyntaxHighlighter scripts
$wgSyntaxHighlighterScriptPath = "{$wgScriptPath}/extensions/SyntaxHighlighter/scripts";

// Path to the SyntaxHighlighter styles
$wgSyntaxHighlighterStylesPath = "{$wgScriptPath}/extensions/SyntaxHighlighter/styles";

// Theme CSS file
$wgSyntaxHighlighterTheme = "shThemeDefault.css";

// Brushes to include on the page
$wgSyntaxHighlighterBrushes = array(
  'shBrushBash.js',
  'shBrushCpp.js',
  'shBrushCSharp.js',
  'shBrushCss.js',
  'shBrushDelphi.js',
  'shBrushDiff.js',
  'shBrushGroovy.js',
  'shBrushJava.js',
  'shBrushJScript.js',
  'shBrushPhp.js',
  'shBrushPlain.js',
  'shBrushPython.js',
  'shBrushRuby.js',
  'shBrushScala.js',
  'shBrushSql.js',
  'shBrushVb.js',
  'shBrushXml.js'
);

$dir = dirname(__FILE__) . '/';

function wfSyntaxHighlighterExtension()
{
  global $wgOut, $wgScriptPath, $wgParser,
      $wgSyntaxHighlighterBrushes, $wgSyntaxHighlighterScriptPath,
      $wgSyntaxHighlighterStylesPath, $wgSyntaxHighlighterTheme;

  // Make shCore.js the very first script to be included (before all the brushes)
  array_unshift($wgSyntaxHighlighterBrushes, 'shCore.js');

  $home = $wgSyntaxHighlighterScriptPath;

  // Add all scripts to the header
  foreach ($wgSyntaxHighlighterBrushes as $script)
      $wgOut->addScript("<script type=\"text/javascript\" src=\"{$wgSyntaxHighlighterScriptPath}/$script\"></script>\n");

  // Add CSS links
  foreach (array('shCore.css', $wgSyntaxHighlighterTheme) as $css)
      $wgOut->addHeadItem($css, "<link type=\"text/css\" rel=\"stylesheet\" href=\"{$wgSyntaxHighlighterStylesPath}/$css\"/>\n");

  // Add initialization code
  $wgOut->addScript(
      "<script type=\"text/javascript\">".
          "var syntaxHighlighterConfig = { clipboardSwf: '{$wgSyntaxHighlighterScriptPath}/clipboard.swf' };".
          "SyntaxHighlighter.highlight();".
      "</script>\n"
      );

  // Finally, set up a MediaWiki hook to the <sh /> tag
  $wgParser->setHook("sh", "wfSyntaxHighlighterExtensionRender");

  return true;
}

function wfSyntaxHighlighterExtensionRender($input, $argv, $parser)
{
  $args = "";

  while (list($key, $val) = each($argv))
      $args .= "$key: $val;";

  $input = htmlspecialchars($input);
  return "<pre class=\"$args\">\n$input\n</pre>";
}

呐,以后就方便多了

打赏

Add comment

1 × 3 =

不去在乎结果,热情地付出过,就好了.
某一天,你所坚持的,和承担过的一切,会有回应。它们并非失去踪迹,只是需要时间抵达。这和星光落入眼睛里,是一样的道理。

近期文章

近期评论