Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit bd2f995

Browse files
committed
new example syntax highlighting/demo-fshl-alt.php
1 parent eadc6ce commit bd2f995

File tree

9 files changed

+178
-15
lines changed

9 files changed

+178
-15
lines changed

changelog.cs.texy

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ rev. 185
2626
- implementován Nette_Object z Nette Frameworku. Nahradil TexyBase
2727

2828
rev. 181
29-
- TexyHtml::$children je nyní private. K potomkům se přistupuje přes ArrayAcces interface ("viz":http://www.latrine.cz/nhtml-pomocnik-php-programatora#comment-12140)
29+
- TexyHtml::$children je nyní private. K potomkům se přistupuje přes ArrayAcces interface ("viz":http://phpfashion.com/nette-web-html-pomocnik-php-programatora#comment-12140)
3030

3131
rev. 180
3232
- nevkládá `­` do URL
3333

3434
rev. 179
35-
- POZOR: přejmenováno TexyHtml::add() -> create(), TexyHtml::addChild() -> add() ("důvody":http://www.latrine.cz/nhtml-pomocnik-php-programatora#comment-12100)
35+
- POZOR: přejmenováno TexyHtml::add() -> create(), TexyHtml::addChild() -> add() ("důvody":http://phpfashion.com/nette-web-html-pomocnik-php-programatora#comment-12100)
3636
- verze pro PHP4: emulace třídy Exception a throw
3737
- chytřejší detekce emailů a URL v textu
3838

@@ -261,7 +261,7 @@ htmlOutputModule
261261

262262
TexyDOM a zděděné třídy
263263
-----------------------
264-
- odstraněno, náhradou je TexyHtml (obdoba NHtml, viz http://www.latrine.cz/nhtml-pomocnik-php-programatora)
264+
- odstraněno, náhradou je TexyHtml (obdoba NHtml, viz http://phpfashion.com/nette-web-html-pomocnik-php-programatora)
265265
- vlastnost TexyHtml::$xhtml - přepínač mezi XHTML a HTML výstupem
266266
- ve všech handlerech se nyní operuje s elementy reprezentovanými tímto objektem, manipulace je tedy extrémně snadná
267267

examples/Flash movie/demo.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ function imageHandler($invocation, $image, $link)
3838
$movie = htmlSpecialChars($movie);
3939
$altContent = htmlSpecialChars($image->modifier->title);
4040

41-
// @see http://www.latrine.cz/how-to-correctly-insert-a-flash-into-xhtml
41+
// @see http://phpfashion.com/how-to-correctly-insert-a-flash-into-xhtml
4242
$code = '
4343
<!--[if !IE]> -->
4444
<object type="application/x-shockwave-flash" data="'.$movie.'" '.$dimensions.'>

examples/HTML filtering/demo.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ function doIt($texy)
6767

6868
echo '<h2>Enable custom tags</h2>';
6969
$texy->allowedTags =
70-
array( // enable only tags <myExtraTag> with attribute & <strong>
71-
'myExtraTag' => array('attr1'),
72-
'strong' => array(),
73-
);
70+
array( // enable only tags <myExtraTag> with attribute & <strong>
71+
'myExtraTag' => array('attr1'),
72+
'strong' => array(),
73+
);
7474
doIt($texy);
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
<?php
2+
3+
/**
4+
* TEXY! THIRD PARTY SYNTAX HIGHLIGHTING
5+
* --------------------------------------
6+
*
7+
* This demo shows how combine Texy! with syntax highlighter FSHL
8+
* - define user callback (for /--code elements)
9+
*
10+
* @author David Grudl (http://davidgrudl.com)
11+
* @version $Revision$ $Date$
12+
*/
13+
14+
15+
// include libs
16+
require_once dirname(__FILE__).'/../../texy/texy.php';
17+
18+
$fshlPath = dirname(__FILE__).'/fshl/';
19+
@include_once $fshlPath . 'fshl.php';
20+
21+
22+
if (!class_exists('fshlParser')) {
23+
die('DOWNLOAD <a href="http://hvge.sk/scripts/fshl/">FSHL</a> AND UNPACK TO FSHL FOLDER FIRST!');
24+
}
25+
26+
27+
28+
/**
29+
* User handler for code block
30+
*
31+
* @param TexyHandlerInvocation handler invocation
32+
* @param string block type
33+
* @param string text to highlight
34+
* @param string language
35+
* @param TexyModifier modifier
36+
* @return TexyHtml
37+
*/
38+
function blockHandler($invocation, $blocktype, $content, $lang, $modifier)
39+
{
40+
if ($blocktype !== 'block/code') {
41+
return $invocation->proceed();
42+
}
43+
44+
$lang = strtoupper($lang);
45+
if ($lang == 'JAVASCRIPT') $lang = 'JS';
46+
47+
$fshl = new fshlParser('HTML_UTF8', P_TAB_INDENT);
48+
if (!$fshl->isLanguage($lang)) {
49+
return $invocation->proceed();
50+
}
51+
52+
$texy = $invocation->getTexy();
53+
$content = Texy::outdent($content);
54+
$content = $fshl->highlightString($lang, $content);
55+
$content = $texy->protect($content, Texy::CONTENT_BLOCK);
56+
57+
$elPre = TexyHtml::el('pre');
58+
if ($modifier) $modifier->decorate($texy, $elPre);
59+
$elPre->attrs['class'] = strtolower($lang);
60+
61+
$elCode = $elPre->create('code', $content);
62+
63+
return $elPre;
64+
}
65+
66+
67+
68+
/**
69+
* Pattern handler for PHP & JavaScript block syntaxes
70+
*
71+
* @param TexyBlockParser
72+
* @param array regexp matches
73+
* @param string pattern name
74+
* @return TexyHtml|string|FALSE
75+
*/
76+
function codeBlockHandler($parser, $matches, $name)
77+
{
78+
list($content) = $matches;
79+
$lang = $name === 'phpBlockSyntax' ? 'PHP' : 'HTML';
80+
81+
$fshl = new fshlParser('HTML_UTF8', P_TAB_INDENT);
82+
$texy = $parser->getTexy();
83+
$content = $fshl->highlightString($lang, $content);
84+
$content = $texy->protect($content, Texy::CONTENT_BLOCK);
85+
86+
$elPre = TexyHtml::el('pre');
87+
$elPre->attrs['class'] = strtolower($lang);
88+
89+
$elCode = $elPre->create('code', $content);
90+
91+
return $elPre;
92+
}
93+
94+
95+
96+
$texy = new Texy();
97+
$texy->addHandler('block', 'blockHandler');
98+
99+
// add new syntax: <?php ... ? >
100+
$texy->registerBlockPattern(
101+
'codeBlockHandler',
102+
'#^<\\?php\n.+\n\\?>$#ms', // block patterns must be multiline and line-anchored
103+
'phpBlockSyntax'
104+
);
105+
106+
// add new syntax: <script ...> ... </script>
107+
$texy->registerBlockPattern(
108+
'codeBlockHandler',
109+
'#^<script(?: type=.?text/javascript.?)?>\n.+\n</script>$#ms', // block patterns must be multiline and line-anchored
110+
'scriptBlockSyntax'
111+
);
112+
113+
// processing
114+
$text = file_get_contents('sample2.texy');
115+
$html = $texy->process($text); // that's all folks!
116+
117+
// echo Geshi Stylesheet
118+
header('Content-type: text/html; charset=utf-8');
119+
echo '<style type="text/css">'. file_get_contents($fshlPath.'styles/COHEN_style.css') . '</style>';
120+
echo '<title>' . $texy->headingModule->title . '</title>';
121+
// echo formated output
122+
echo $html;
123+
124+
// and echo generated HTML code
125+
echo '<hr />';
126+
echo '<pre>';
127+
echo htmlSpecialChars($html);
128+
echo '</pre>';

examples/syntax highlighting/demo-fshl.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@
1919
@include_once $fshlPath . 'fshl.php';
2020

2121

22-
if (!class_exists('fshlParser'))
22+
if (!class_exists('fshlParser')) {
2323
die('DOWNLOAD <a href="http://hvge.sk/scripts/fshl/">FSHL</a> AND UNPACK TO FSHL FOLDER FIRST!');
24+
}
2425

2526

2627

@@ -43,14 +44,14 @@ function blockHandler($invocation, $blocktype, $content, $lang, $modifier)
4344
$lang = strtoupper($lang);
4445
if ($lang == 'JAVASCRIPT') $lang = 'JS';
4546

46-
$parser = new fshlParser('HTML_UTF8', P_TAB_INDENT);
47-
if (!$parser->isLanguage($lang)) {
47+
$fshl = new fshlParser('HTML_UTF8', P_TAB_INDENT);
48+
if (!$fshl->isLanguage($lang)) {
4849
return $invocation->proceed();
4950
}
5051

5152
$texy = $invocation->getTexy();
5253
$content = Texy::outdent($content);
53-
$content = $parser->highlightString($lang, $content);
54+
$content = $fshl->highlightString($lang, $content);
5455
$content = $texy->protect($content, Texy::CONTENT_BLOCK);
5556

5657
$elPre = TexyHtml::el('pre');

examples/syntax highlighting/demo-geshi.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@
2222
@include_once $geshiPath . 'geshi.php';
2323

2424

25-
if (!class_exists('Geshi'))
25+
if (!class_exists('Geshi')) {
2626
die('DOWNLOAD <a href="http://qbnz.com/highlighter/">GESHI</a> AND UNPACK TO GESHI FOLDER FIRST!');
27+
}
2728

2829

2930

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
Syntax highlighting in Texy!
2+
****************************
3+
4+
5+
6+
How use clone in PHP4
7+
---------------------
8+
9+
This example show how to implement PHP5 `clone` construction in older PHP4
10+
11+
<?php
12+
if (((int) phpversion() < 5) && (!function_exists('clone')))
13+
eval('function &clone($obj) { return $obj; }');
14+
15+
$obj = new Object();
16+
$dolly = clone ($obj);
17+
?>
18+
19+
20+
21+
22+
And Now for Something Completely Different:
23+
-------------------------------------------
24+
25+
<script type="text/javascript">
26+
// function trim() in JavaScript
27+
28+
function trim(s) {
29+
while (s.substr(0, 1) == ' ') s = s.substr(1);
30+
while (s.substr(s.length-1, 1) == ' ') s = s.substr(0, s.length-2);
31+
return s;
32+
}
33+
</script>

readme.cs.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,4 @@ HTML kód najdete v adresáři /icons/
6767

6868
-----
6969
Chcete-li další informace, navštivte autorův weblog:
70-
http://www.latrine.cz/
70+
http://phpfashion.com

readme.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,4 +72,4 @@ Choose buttons and look at exemplary HTML code in directory /icons/
7272

7373
-----
7474
For more information, visit the author's weblog (in czech language):
75-
http://www.latrine.cz/
75+
http://phpfashion.com

0 commit comments

Comments
 (0)