国外设计欣赏网站 - DOOOOR.com

 找回密码
 注册

QQ登录

只需一步,快速开始

扫一扫,微信登陆

帖子

[Drupal模块] Drupal 7.X/6.X模块介绍:GeSHi Filter语法高亮模块

[复制链接]
发表于 4-14-2012 00:25 | 显示全部楼层 |阅读模式

Drupal语法高亮模块有很多,主要分为两类:服务器端和客户端(基于JavaScript)。这里结束的Drupal语法高亮模块GeSHi是基于服务器端的,通过Drupal Filter来实现的。下面就来介绍一下GeSHi模块的使用。

GeSHi语法高亮介绍:

一开始以为GeSHi是中文“格式”的拼音,其实GeSHi全名为Generic Syntax Highlighter,是一个通用的语法高亮程序。

目前支持130多重编程语言的语法高亮,几乎包括了全部常见编程语言,这些语言包括:ActionScript, Ada, Apache Log, AppleScript, ASM, ASP, Bash, C, ColdFusion, C++, QT, C#, CSS, D, Delphi, Diff, DOS, dot, Eiffel, Fortran, Groovy, Haskell, HTML, INI, Inno, Java, Javascript, LaTeX, Lisp, Lua, Motorola 68000 Assembler, Matlab, mIRC Scripting, MySQL, Objective C, OCaml, OpenOffice.org Basic, Oracle 8 SQL, Pascal, Perl, PHP, PL/SQL, Python, QBasic/QuickBASIC, Rails, Microsoft Registry, robots.txt, Ruby, SAS, Scheme, Smalltalk, Smarty, SQL, TCL, Text, Visual Basic, vb.net, VHDL, XML, X++.

GeSHi Filter的安装与配置:

1、去Drupal项目页面下载GeSHi Filter: http://drupal.org/project/geshifilter

2、Drupal的GeSHi包里面没有包含GeSHi的核心程序,我们需要去GeSHi官网http://qbnz.com/highlighter/ 下载,然后解压缩到Drupal GeSHi模块下,路径为 sites/all/modules/geshifilter/geshi

3、在Drupal中启用GeSHi模块

4、配置GeSHi,GeSHi配置路径 admin/settings/geshifilter/general。如果没有特殊的要求,可以使用默认的配置。

5、在文章中使用 <code php> ... </code> 对你的脚本进行高亮设置。

Drupal GeSHi语法高亮演示:

function do_command($commandName, $args)4 ?: k1 T; Y. a4 \9 N2 @* {9 R
{
% U: X9 i, W9 C0 t! J" h. ~  |. z7 F& s    $buffer = "";
# `& [9 }2 c& [: Z$ X) s3 V5 r    if (false === ($command = find_command($commandName))) return false;
/ r0 ~# I# n) R1 V$ p4 r    if ($fp = @popen("$command $args", 'r'))
' L0 d8 A; F# H        {/ n# j! B0 @3 s3 c  ~; {8 K
    while (!@feof($fp))
, }2 k1 u1 S; ^; p' I8 x- j' }    {
8 C; k* L$ c6 z" A0 o      $buffer .= @fgets($fp, 4096);- q4 \4 V6 b' X3 K  w: [
    }7 v7 s/ f, B: @2 H$ J3 A/ S
    return trim($buffer);
7 j9 D, A6 b1 s# ?  }% u7 e2 z6 L( S5 v8 O7 t3 J
    return false;, R/ C5 J/ |( g' q: m* o" d+ y
}


本文选自:东华博客,谢谢!


---------------------------------------------------------------------------------------------------------

GeSHi Filter for syntax highlighting

GeSHi filter

The GeShi Filter module provides a filter for source code syntax highlighting for a wide range of languages.

Source code can be entered with for example <code type="java">...</code> or <blockcode language="python">...</blockcode>. Starting from version 5.x-2.0 it is also possible to define your own generic and language specific tags (e.g. <java>) or to work with square bracket style tags (e.g. [python]). Automatically adding line numbers is possible too with for example [ruby linenumbers="normal"].

Language Support

At the time of this writing the GeSHi library supports highlighting for more than 200 programming languages and configuration syntaxes, including: ActionScript, Ada, Apache Log, AppleScript, ASM, ASP, Bash, C, ColdFusion, C++, QT, C#, CSS, D, Delphi, Diff, DOS, dot, Eiffel, Fortran, Groovy, Haskell, HTML, INI, Inno, Java, Javascript, LaTeX, Lisp, Lua, Motorola 68000 Assembler, Matlab, mIRC Scripting, MySQL, Objective C, OCaml, OpenOffice.org Basic, Oracle 8 SQL, Pascal, Perl, PHP, PL/SQL, Python, QBasic/QuickBASIC, Rails, Microsoft Registry, robots.txt, Ruby, SAS, Scheme, Smalltalk, Smarty, SQL, TCL, Text, Visual Basic, vb.net, VHDL, XML, X++.

Additional support for highlighting Drupal source code is provided too.

Third party library dependency: GeSHi (version 1.0.x)

This module requires the third-party PHP library GeSHi (Generic Syntax Highlighter), which has to be downloaded separately.
Important note: only the 1.0.x branch of the GeSHi library is supported, so do not use the development branch GeSHi 1.1.x. Direct link to GeSHi 1.0.x releases:http://sourceforge.net/projects/geshi/files/geshi/

7.x-1.x

The 7.x branch requires the Libraries API (2.x-dev). A drush make file is also included that will download both the libraries API and the geshi dependency.

History

The 4.7.x-1.x branch is based on the original GeSHi filter module by Vincent Filby. The 5.x-1.x branch is a basic port of this version for Drupal 5.

In the 5.x-2.x branch the GeSHi filter got a major overhaul. Main features/changes: configurable code block tags, per language tags (e.g. <java>), a submodule for a GeSHi source code node type, easier administration UI, guided filter conflict solving, and many bug fixes.

Related modules/alternatives

Project Information

Downloads




|2011-2026-版权声明|平台(网站)公约|DOOOOR 设计网 ( 吉ICP备2022003869号 )

GMT+8, 3-14-2025 22:21 , Processed in 0.447581 second(s), 231 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表