]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - pgsrc/Help%2FPhpHighlightPlugin
function _PageList_Column* are not private
[SourceForge/phpwiki.git] / pgsrc / Help%2FPhpHighlightPlugin
1 Date: Tue,  5 Feb 2013 15:49:31 +0000
2 Mime-Version: 1.0 (Produced by PhpWiki 1.4.0)
3 Content-Type: application/x-phpwiki;
4   pagename=Help%2FPhpHighlightPlugin;
5   flags=PAGE_LOCKED%2CEXTERNAL_PAGE;
6   markup=2;
7   charset=UTF-8
8 Content-Transfer-Encoding: binary
9
10 The **~PhpHighlight** [[Help:WikiPlugin|plugin]] pretty-prints PHP code using the
11 php-function:highlight-string.
12
13 == Usage ==
14
15 You specify options for the plugin on the same line as ##~<~<~PhpHighlight##,
16 and put the code on the following lines, until the final ##~>~>##:
17
18 {{{
19 <<PhpHighlight [wrap?] [color options]
20 code to be highlighted
21 >>
22 }}}
23
24 == Description ==
25
26 Depending on the ##wrap## option, then the plugin will take care of
27 adding ##<?php## and ##?>## to the code before passing it to
28 php-function:highlight-string. If the PHP delimiters were added, then
29 the plugin removes them again from the highlighted string, before
30 presenting it.
31
32 == Options ==
33
34 === Automatic Wrapping ===
35
36 If you don't want the plugin to automatically wrap the source code
37 in ##<?php## and ##?>##, then set ##wrap## to ##0##. The default value is ##1##
38 which means that the plugin takes care of adding and removing ##<?php## and ##?>## automatically.
39
40 If you set ##wrap## to ##0##, then you'll be able to mix PHP code with
41 HTML. The plugin will then translate '##< ?php##' into '##<?php##' and
42 '##? >##' into '##?>##' to allow you to start and stop PHP mode in your code.
43
44 === Color Options ===
45
46 The plugin accepts optional color arguments which correspond to the
47 highlight settings in **php.ini**. Specified colors must be a valid
48 hexadecimal color or
49 [[http://www.w3.org/TR/REC-html40/types.html#h-6.5|HTML 4 color name]]
50 in lowercase, such as ##'#0f0344'## or ##blue##. You can set the
51 following options: ##string##, ##comment##, ##keyword##, ##bg##, ##default##, and ##html##.
52
53 **Note:** ##bg## no longer exists in PHP 5.4.
54
55 == Examples ==
56
57 === PHP with default colors from ##php.ini##: ===
58
59 <<PhpHighlight
60 function hello() {
61     echo "Hello World<p>";
62 }
63 >>
64
65 === HTML with embedded PHP ===
66
67 Here we have to use ##wrap=0## to prevent automatic wrapping, and escape
68 '##?>##' as '##? >##':
69
70 <<PhpHighlight wrap=0 html='#000000' bg='#dddddd'
71 <html>
72   <head>
73     <title>PHP Test</title>
74   </head>
75   <body>
76     < ?php echo "<p>Hello World</p>\n"; ? >
77   </body>
78 </html>
79 >>
80
81 === C Source ===
82
83 Although ##highlight_string()## was designed with PHP code in mind it is
84 suitable for basic syntax-highlighting of most C code because the two
85 syntax are similar.
86
87 <<PhpHighlight default=black string=blue comment=gray keyword=purple
88 #include <stdio.h>
89 /* Get load */
90 int
91 getload(void)
92 {
93     if ((fp = fopen("/proc/loadavg", "r")) == NULL) {
94         syslog(LOG_ERR, _("%s %s: unable to open %s: %s"), _("FATAL ERROR:"),
95               "getload()", "/proc/loadavg", strerror(errno));
96         exit(EX_OSFILE);
97     }
98     fclose(fp);
99 }
100 >>
101
102 == Known Problems ==
103 {{{
104 <<PhpHighlight
105     testing[somearray];
106     testing~[badworkaround~];
107 >>
108 }}}
109 will swallow "~[somearray~]"
110
111 == Authors ==
112 * [[mailto:gimpster@gimpster.com|Martin Geisler]]
113 * [[mailto:carstenklapp@users.sourceforge.net|Carsten Klapp]] (added ability to override colors defined in ##php.ini##)
114
115 == See Also ==
116 * [[Help:SyntaxHighlighterPlugin|SyntaxHighlighter]] plugin for highlighting other languages.
117
118 <noinclude>
119 ----
120 [[PhpWikiDocumentation]] [[CategoryWikiPlugin]]
121 </noinclude>