Differences between current version and previous revision of Help/PhpHighlightPlugin.
Other diffs: Previous Major Revision, Previous Author
Newer page: |
version 6 |
Last edited on 17 January 2022 3:00 |
by harold |
|
Older page: |
version 5 |
Last edited on 9 September 2007 0:16 |
by harold |
Revert |
@@ -1,86 +1,81 @@
-The PhpHighlightPlugin
pretty-prints PHP code using the
-php-function:highlight-string.
+The **~PhpHighlight** [[Help:WikiPlugin|plugin]]
pretty-prints PHP code using the
+[[
php-function:highlight-string]]
.
-See also SyntaxHighlighterPlugin for highlighting other languages.
+You specify options for the plugin on the same line as ##~<~<~PhpHighlight##,
+and put the code on the following lines, until the final ##~>~>##:
-You specify options for the plugin on the same line as the =<?plugin=,
-and put the code on the following lines, until the final =?>=:
-
-<verbatim>
-
<?plugin
PhpHighlight [wrap?] [color options]
+{{{
+<<PhpHighlight [wrap?] [color options]
-Depending on the =
wrap=
option, then the plugin will take care of
-adding =
<?php=
and =
?>=
to the code before passing it to
-php-function:highlight-string. If the PHP delimiters were added, then
-the plugin removes them again from the highlighted string, before
-
presenting it.
+Depending on the ##
wrap##
option, then the plugin will take care of
+adding ##
<?php##
and ##
?>##
to the code before passing it to
+[[
php-function:highlight-string]]
. If the PHP delimiters were added, then
+the plugin removes them again from the highlighted string, before presenting it.
+===
Automatic Wrapping ===
-
If you don't want the plugin to automatically wrap the source code
-
in =
<?php=
and =
?>=
, then set =
wrap=
to =
0=
. The default value is =
1=
-
which means that the plugin takes care of adding and removing
- =
<?php=
and =
?>=
automatically.
+If you don't want the plugin to automatically wrap the source code
+in ##
<?php##
and ##
?>##
, then set ##
wrap##
to ##
0##
. The default value is ##
1##,
+which means that the plugin takes care of adding and removing ##
<?php##
and ##
?>##
automatically.
-
If you set =
wrap=
to =
0=
, then you'll be able to mix PHP code with
-
HTML. The plugin will then translate '=
< ?php=
' into '=
<?php=
' and
-
'=
? >=
' into '=
?>=
' to allow you to start and stop PHP mode in your
-
code.
+If you set ##
wrap##
to ##
0##
, then you'll be able to mix PHP code with
+HTML. The plugin will then translate '##
< ?php##
' into '##
<?php##
' and
+'##
? >##
' into '##
?>##
' to allow you to start and stop PHP mode in your code.
-
The plugin accepts optional color arguments which correspond to the
-
highlight settings in *php.ini*. Specified colors must be a valid
-
hexadecimal color or
-
[HTML 4 color name|
http://www.w3.org/TR/REC-html40/types.html#h-6.5]
-
in lowercase, such as =
'#0f0344'=
or =
blue=
. You can set the
-
following options:
+The plugin accepts optional color arguments which correspond to the
+highlight settings in *
*php.ini*
*. Specified colors must be a valid
+hexadecimal color or
+[[
http://www.w3.org/TR/REC-html40/types.html#h-6.5|HTML 4 color name]
]
+in lowercase, such as ##
'#0f0344'##
or ##
blue##
. You can set the
+following options: ##string##, ##comment##, ##keyword##, ##bg##, ##default##, and ##html##.
- =string=, =comment=, =keyword=, =
bg=, =default=, and =html=
+**Note:** ##
bg## no longer exists in PHP >
= 5.4.
-!!
PHP with default colors from =
php.ini=
:
+===
PHP with default colors from ##
php.ini##
: ===
function hello() {
echo "Hello World<p>";
}
-!!
HTML with embedded PHP
+===
HTML with embedded PHP ===
-Here we have to use =
wrap=0=
to prevent automatic wrapping, and escape
-'=
?>=
' as '=
? >=
':
+Here we have to use ##
wrap=0##
to prevent automatic wrapping, and escape
+'##
?>##
' as '##
? >##
':
-<?plugin
PhpHighlight wrap=0 html='#000000' bg='#dddddd'
+<<
PhpHighlight wrap=0 html='#000000' bg='#dddddd'
<html>
<head>
<title>PHP Test</title>
</head>
<body>
< ?php echo "<p>Hello World</p>\n"; ? >
</body>
</html>
-Although =
highlight_string()=
was designed with PHP code in mind it is
+Although ##
highlight_string()##
was designed with PHP code in mind it is
suitable for basic syntax-highlighting of most C code because the two
syntax are similar.
-<?plugin
PhpHighlight default=black string=blue comment=gray keyword=purple
+<<
PhpHighlight default=black string=blue comment=gray keyword=purple
#include <stdio.h>
/* Get load */
int
getload(void)
@@ -91,14 +86,26 @@
exit(EX_OSFILE);
}
fclose(fp);
}
+== Known Problems ==
+{{{
+<<PhpHighlight
+ testing[somearray];
+ testing~[badworkaround~];
+>>
+}}}
+will swallow "~[somearray~]"
-Martin Geisler
mailto:gimpster@gimpster.com and Carsten Klapp
-mailto:carstenklapp@users.sourceforge.net.
+== Authors ==
+* [[
mailto:gimpster@gimpster.com|Martin Geisler]]
+* [[
mailto:carstenklapp@users.sourceforge.net|Carsten Klapp]] (added ability to override colors defined in ##php
.ini##)
+== See Also ==
+* [[Help:SyntaxHighlighterPlugin|SyntaxHighlighter]] plugin for highlighting other languages.
-PhpWikiDocumentation Help:WikiPlugin
+<noinclude>
+----
+[[
PhpWikiDocumentation]] [[CategoryWikiPlugin]]
+</noinclude>
current version
The PhpHighlight
plugin pretty-prints PHP code using the
php-function:highlight-string.
Usage
You specify options for the plugin on the same line as <<PhpHighlight,
and put the code on the following lines, until the final >>:
<<PhpHighlight [wrap?] [color options]
code to be highlighted
>>
Description
Depending on the wrap option, then the plugin will take care of
adding <?php and ?> to the code before passing it to
php-function:highlight-string. If the PHP delimiters were added, then
the plugin removes them again from the highlighted string, before presenting it.
Options
Automatic Wrapping
If you don't want the plugin to automatically wrap the source code
in <?php and ?>, then set wrap to 0. The default value is 1,
which means that the plugin takes care of adding and removing <?php and ?> automatically.
If you set wrap to 0, then you'll be able to mix PHP code with
HTML. The plugin will then translate '< ?php' into '<?php' and
'? >' into '?>' to allow you to start and stop PHP mode in your code.
Color Options
The plugin accepts optional color arguments which correspond to the
highlight settings in php.ini. Specified colors must be a valid
hexadecimal color or
HTML 4 color name
in lowercase, such as '#0f0344' or blue. You can set the
following options: string, comment, keyword, bg, default, and html.
Note: bg no longer exists in PHP >= 5.4.
Examples
PHP with default colors from php.ini:
function hello() {
echo "Hello World<p>";
}
HTML with embedded PHP
Here we have to use wrap=0 to prevent automatic wrapping, and escape
'?>' as '? >':
<html>
<head>
<title>PHP Test</title>
</head>
<body>
<?php echo "<p>Hello World</p>\n"; ?>
</body>
</html>
C Source
Although highlight_string() was designed with PHP code in mind it is
suitable for basic syntax-highlighting of most C code because the two
syntax are similar.
#include <stdio.h>
/* Get load */
int
getload(void)
{
if ((fp = fopen("/proc/loadavg", "r")) == NULL) {
syslog(LOG_ERR, _("%s %s: unable to open %s: %s"), _("FATAL ERROR:"),
"getload()", "/proc/loadavg", strerror(errno));
exit(EX_OSFILE);
}
fclose(fp);
}
Known Problems
<<PhpHighlight
testing[somearray];
testing~[badworkaround~];
>>
will swallow "[somearray]"
Authors
See Also