Подсветка кода программ

Подсветка синтаксиса исходных текстов программ делается с помощью пары тегов <code>..</code>, в которые он должен обрамляться. При этом сохранятся отступы и прочее форматирование исходного текста. В данном случае не указан язык программирования, поэтому текст будет подсвечиваться одинаково для всех символов.

Если указать язык программирования
<code %lang%>..</code>
, то текст программы будет подсвечен в соответствие с предопределённой схемой подсветки синтаксиса данного языка.

Параметр %lang% может быть одним из следующего списка предопределённых языков программирования:

actionscript
actionscript-french
ada
apache
applescript
asm
asp
bash
c
c_mac
caddcl
cadlisp
cpp
csharp
css
d
delphi
diff
div
dos
eiffel
freebasic
gml
html4strict
ini
inno
java
javascript
lisp
lua
matlab
mpasm
nsis
objc
ocaml
ocaml-brief
oobas
oracle8
pascal
perl
php
php-brief
python
qbasic
ruby
scheme
sdlbasic
smarty
sql
vb
vbnet
vhdl
visualfoxpro
xml

Без подсветки

echo "Hello, world!"

Visual Basic

Private Sub Command1_Click()
xx = 330
yy = 260: X2 = 200: Y2 = 0
P = 3.1415926
RR = 120
RR1 = 10
Line (0, 0)-(800, 800), RGB(227, 231, 230), BF
For i = 0 To 360 Step 2
For j = 0 To 360 Step 0.8
    t = i * P / 180
    s = j * P / 180
    rr0 = RR1 + 50 * Cos(2# * t) ^ 14 + 50 * (Sin(1 * s + 4 * t)) ^ 24
    'rr0 = RR1 + 50 * Sin(0.5 * t) ^ 4 + 30 * (Sin(1 * s + 7 * t)) ^ 44
    X = RR * Cos(t) + rr0 * Cos(s)
    Y = RR * Sin(t) + rr0 * Sin(s)
    z = 0 'RR * Sin(1 * t) + rr0 * Cos(s)
    X1 = X / 1 - z * Cos(P / 3) * 0.5
    Y1 = Y / 1 - z * Sin(P / 3) * 0.5
    red = 0 '190 '255 * rr0 / (RR1 + 70)
    green = 0 '215 '255 * Abs(Sin(i / 15))
    blue = 0 '190 '255 * Abs(Sin((j) / 20))
    'red = 255 * rr0 / (RR1 + 70)
    'green = 255 * Abs(Sin(i / 15))
    'blue = 255 * Abs(Sin((j) / 20))
    DrawWidth = 1
    If i > 0 And j > 0 Then Line (X1 + xx + 10, Y1 + yy + 40)-(X2 + xx + 10,
    Y2 + yy + 40), RGB(red, green, blue)
    X2 = X1
    Y2 = Y1
Next j
Next i

Pascal

interface
 
 
uses
  Math;
 
const
 Capacity = 100;
 
type
 TOperation = Array [1..Capacity] of byte; { Фигня }
 
 TOperand = Array [1..2] of Word; { ®ЇҐа ­¤л }
 
 TAoTOperand = Array [1..Capacity] of TOperand;
 TAoSingle = Array [1..Capacity div 2] of Single; { Еще фигня }
 
 
 TPFRecord = Record
   rb: TAoTOperand;
   ro: TOperation;
   rc: TAoSingle;
   Blength: word;   { =fi }
   Clength: word;   { =ci }
 End; {needed for import/export}
 
 
 TParsedFunction = Object
 
  public
    procedure ParseFunction (s: String; var ErCode: integer);
    function  Compute (x,y,z: single): single;
{    function Compute(const x: single = 0;
                     const y: single = 0;
                     const z: single = 0): single;}
    procedure ExportParsed (var r: TPFRecord);
    procedure ImportParsed (const r: TPFRecord);
 
  private
    a: TAoSingle;   { elementary blocks }
    b: TAoTOperand; { numbers of el. blocks, envolved in operation}
    o: TOperation;  { code of operation }
    c: TAoSingle;
    { constants, maybe variables or numbers;
      c[1]=x, c[2]=y, c[3]=z, c[4]=PI, c[5]=e, ....}
 
    fi         : word; { free index, also length of array b }
    ConstIndex : word; { last index for const, starting from 3 }
 
  End;
 
 
implementation
 
Function  UpStr (US: string): string;
var i: word;
begin
     for i := 1 to Length (US) do
         US[i] := UpCase (US[i]);
     UpStr := US;
end;

C++

#include <string>
 
using namespace std;
 
Model *pModel = NULL; // Holds The Model Data
 
GLfloat	yrot=0.0f;													// Y Rotation
 
AUX_RGBImageRec *LoadBMP(const char *Filename)						// Loads A Bitmap Image
{
	FILE *File=NULL;												// File Handle
 
	if (!Filename)													// Make Sure A Filename Was Given
	{
		return NULL;												// If Not Return NULL
	}
 
	File=fopen(Filename,"r");										// Check To See If The File Exists
 
	if (File)														// Does The File Exist?
	{
		fclose(File);												// Close The Handle
		return auxDIBImageLoad(Filename);							// Load The Bitmap And Return A Pointer
	}
 
	return NULL;													// If Load Failed Return NULL
}
 
GLuint LoadGLTexture( const char *filename )						// Load Bitmaps And Convert To Textures
{
	AUX_RGBImageRec *pImage;										// Create Storage Space For The Texture
	GLuint texture = 0;												// Texture ID
 
	pImage = LoadBMP( filename );									// Loads The Bitmap Specified By filename
 
	// Load The Bitmap, Check For Errors, If Bitmap's Not Found Quit
	if ( pImage != NULL && pImage->data != NULL )					// If Texture Image Exists
	{
		glGenTextures(1, &texture);									// Create The Texture
 
		// Typical Texture Generation Using Data From The Bitmap
		glBindTexture(GL_TEXTURE_2D, texture);
		glTexImage2D(GL_TEXTURE_2D, 0, 3, pImage->sizeX, pImage->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, pImage->data);
		glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
		glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
 
		free(pImage->data);											// Free The Texture Image Memory
		free(pImage);												// Free The Image Structure
	}
 
	return texture;													// Return The Status
}

PHP

/**
 * The loginform
 *
 * @author Andreas Gohr <andi@splitbrain.org>
 */
function html_login(){
  global $lang;
  global $conf;
  global $ID;
 
  print p_locale_xhtml('login');
  ?>
    <div align="center">
    <form action="<?php echo script()?>" accept-charset="<?php echo $lang['encoding']?>" method="post">
      <fieldset>
        <legend><?php echo $lang['btn_login']?></legend>
        <input type="hidden" name="id" value="<?php echo $ID?>" />
        <input type="hidden" name="do" value="login" />
        <label>
          <span><?php echo $lang['user']?></span>
          <input type="text" name="u" value="<?php echo formText($_REQUEST['u'])?>" class="edit" />
        </label><br />
        <label>
          <span><?php echo $lang['pass']?></span>
          <input type="password" name="p" class="edit" />
        </label><br />
        <input type="submit" value="<?php echo $lang['btn_login']?>" class="button" />
        <label for="remember" class="simple">
          <input type="checkbox" name="r" id="remember" value="1" />
          <span><?php echo $lang['remember']?></span>
        </label>
      </fieldset>
    </form>
  <?php
    if($conf['openregister']){
      print '<p>';
      print $lang['reghere'];
      print ': <a href="'.wl($ID,'do=register').'" class="wikilink1">'.$lang['register'].'</a>';
      print '</p>';
    }
  ?>
    </div>
  <?php
/*
 FIXME provide new hook
  if(@file_exists('includes/login.txt')){
    print io_cacheParse('includes/login.txt');
  }
*/
}
 
wiki/highlighting.txt · Последние изменения: 2006/08/29 11:49 От romtek
 
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki