Joomla! To highlight the source code (2)

Description:
Previous (Joomla! To highlight the source code (1)), describe how the extension was a simple way of describing the basic source code in the article.
This time, to change the default color for each language, I would like to explain how easily.
As also previously described, Joomla! "Content - Code Hightlighter (GeSHi)" is, GeSHi is based.
GeSHi is, php is a class library.
GeSHi this will do to change the color definition.
So, you can change where and how the definitions can GeSHi colors, I would like to explain easily.
http://qbnz.com/highlighter/geshi-doc.html
1:
Joomla! To highlight the source code (1)
2 :
GeSHi colors are defined, php files are written.
And temporary changes in color, php can be dynamically re-allocated, if you want to change the basic color, that will change the php file.
Php file that this file language (Language File) GeSHi and we call.
So, immediately, try to change the language file.
Cases)
php you want to change the color of the language.
Then, copy the following files in the same directory.
- /libraries/geshi/geshi/php.php
Copy the name here and we'll phplocal.php.
Now, phplocal that you have found the language.
Try it.
Described as follows: If you look like?
<pre xml:lang="phplocal">
$language_data = array(
'LANG_NAME' => 'PHP',
'COMMENT_SINGLE' => array(1 => '//', 2 => '#'),
'COMMENT_MULTI' => array('/*' => '*/'),
'HARDQUOTE' => array("'", "'"),
'HARDESCAPE' => array("'", "\\"),
'HARDCHAR' => "\\",
'COMMENT_REGEXP' => array(
//Heredoc and Nowdoc syntax
3 => '/<<<\s*?(\'?)([a-zA-Z0-9]+?)\1[^\n]*?\\n.*\\n\\2(?![a-zA-Z0-9])/siU',
// phpdoc comments
4 => '#/\*\*(?![\*\/]).*\*/#sU',
// Advanced # handling
2 => "/#.*?(?:(?=\?\>)|^)/smi"
),
'CASE_KEYWORDS' => GESHI_CAPS_NO_CHANGE,
</pre>
In fact, it looks like the following.
Indeed, php you will notice that the highlighted language the same way.
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 | $language_data = array( 'LANG_NAME' => 'PHP', 'COMMENT_SINGLE' => array(1 => '//', 2 => '#'), 'COMMENT_MULTI' => array('/*' => '*/'), 'HARDQUOTE' => array("'", "'"), 'HARDESCAPE' => array("'", "\\"), 'HARDCHAR' => "\\", 'COMMENT_REGEXP' => array( //Heredoc and Nowdoc syntax 3 => '/<<<\s*?(\'?)([a-zA-Z0-9]+?)\1[^\n]*?\\n.*\\n\\2(?![a-zA-Z0-9])/siU', // phpdoc comments 4 => '#/\*\*(?![\*\/]).*\*/#sU', // Advanced # handling 2 => "/#.*?(?:(?=\?\>)|^)/smi" ), 'CASE_KEYWORDS' => GESHI_CAPS_NO_CHANGE, |
This way, you can create a personal language file easily.
Later in order to facilitate maintenance, and a copy, I had better get into the file and copy it.
Just copy files (phplocal.php) to make the changes, let's change the color.
Here, let's change the color of the comment as an example.
First, let's check the definition of the color of the comment.
Below, phplocal.php.
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 | $language_data = array( 'LANG_NAME' => 'PHP', 'COMMENT_SINGLE' => array(1 => '//', 2 => '#'), 'COMMENT_MULTI' => array('/*' => '*/'), 'HARDQUOTE' => array("'", "'"), 'HARDESCAPE' => array("'", "\\"), 'HARDCHAR' => "\\", 'COMMENT_REGEXP' => array( //Heredoc and Nowdoc syntax 3 => "/<<<\s*?(\'?)([a-zA-Z0-9]+?)\1[^\n]*?\\n.*\\n\\2(?![a-zA-Z0-9])/siU", // phpdoc comments 4 => "#/\*\*(?![\*\/]).*\*/#sU", // Advanced # handling 2 => "/#.*?(?:(?=\?\>)|^)/smi" ), 'CASE_KEYWORDS' => GESHI_CAPS_NO_CHANGE, |
Line 55: Definition of line comment line 56: The definition of multi-line comments.
This is what the character (string) which will define how the comments.
The color is not defined.
Define the color at the bottom.
994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 | 'STYLES' => array( 'KEYWORDS' => array( 1 => 'color: #b1b100;', 2 => 'color: #000000; font-weight: bold;', 3 => 'color: #990000;', 4 => 'color: #009900; font-weight: bold;' ), 'COMMENTS' => array( 1 => 'color: #666666; font-style: italic;', 2 => 'color: #666666; font-style: italic;', 3 => 'color: #0000cc; font-style: italic;', 4 => 'color: #009933; font-style: italic;', 'MULTI' => 'color: #666666; font-style: italic;' ), 'ESCAPE_CHAR' => array( 0 => 'color: #000099; font-weight: bold;', 1 => 'color: #000099; font-weight: bold;', 2 => 'color: #660099; font-weight: bold;', 3 => 'color: #660099; font-weight: bold;', 4 => 'color: #006699; font-weight: bold;', 5 => 'color: #006699; font-weight: bold; font-style: italic;', 6 => 'color: #009933; font-weight: bold;', 'HARD' => 'color: #000099; font-weight: bold;' ), |
1001-1006 is a line comment defined color.
1 =>: A definition of the color-line comment.
2 =>: Advanced # handling is defined colors Comments.
3 =>: Heredoc and Nowdoc syntax is defined colors Comments.
4 =>: phpdoc comments in the comment color definition.
MULTI =>: multi-line comments are defined color.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | <?php // --- php コメントのテストです --- // 1 : line comment. ... what Color? # 2 : handling .... what Color? /** 4 : phpdoc .... what Color? */ /* 5: multi line color ... what Color? */ ?> <?php $str = <<<'EOD' Example of string spanning multiple lines using nowdoc syntax. EOD; /* example class */ class foo { public $foo; public $bar; function foo() { $this-->foo = 'Foo'; $this-->bar = array('Bar1', 'Bar2', 'Bar3'); } } $foo = new foo(); $name = 'MyName'; echo <<<'EOT' My name is "$name". I am printing some $foo-->foo. Now, I am printing some {$foo-->bar[1]}. This should not print a capital 'A': \x41 EOT; ?> |
Let's change the color defined as follows.
1 =>: # 666666 -> # ff0000
2 =>: # 666666 -> # 00ff00
3 =>: # 0000cc -> # ffff00
4 =>: # 009933 -> # 0000ff
MULTI =>: # 666666 -> # 00ffff
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | <?php
// --- php comment test ---
// 1 : line comment. ... what Color?
# 2 : handling .... what Color?
/** 4 : phpdoc .... what Color?
*/
/* 5: multi line color ... what Color?
*/
?>
<?php
$str = <<<'EOD'
Example of string
spanning multiple lines
using nowdoc syntax.
EOD;
/* example class */
class foo
{
public $foo;
public $bar;
function foo()
{
$this-->foo = 'Foo';
$this-->bar = array('Bar1', 'Bar2', 'Bar3');
}
}
$foo = new foo();
$name = 'MyName';
echo <<<'EOT'
My name is "$name". I am printing some $foo-->foo.
Now, I am printing some {$foo-->bar[1]}.
This should not print a capital 'A': \x41
EOT;
?> |
This could change the color.
How do you think of the contents of the article here?
The direct way to handle the php file, some may feel the resistance.
However, in order to change the color, not to write complex programs.
1 and done, I know that you can simply change the color.
GeSHi can be a lot of things.
Joomla!, It does not use only a fraction GeSHi.
That is, start doing things the "easy" it may depart from the basic concept.
However, the human being involved in the development of more customized from the screen, I think it's good also.
Next time, I want to write a story around it.
Or a line number as above, it can change the color, GeSHi easy.
However, php is then controlled using the GeSHi class description I would like to be without the programming or if I say this in general.
http://qbnz.com/highlighter/geshi-doc.html
1:
Joomla! To highlight the source code (1)
2 :
You might also like:
Trackback URL
After Admin approves this comment, it will be shown.
Comments
Leave a Reply
