File: demo.php

package info (click to toggle)
php-texy 2.6-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 680 kB
  • ctags: 1,299
  • sloc: php: 4,754; makefile: 4
file content (64 lines) | stat: -rw-r--r-- 1,256 bytes parent folder | download | duplicates (2)
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php

/**
 * This demo shows how control links in Texy!
 */


// include Texy!
require_once dirname(__FILE__) . 'Texy.php';


/**
 * @param TexyHandlerInvocation  handler invocation
 * @param string
 * @param string
 * @param TexyModifier
 * @param TexyLink
 * @return TexyHtml|string|FALSE
 */
function phraseHandler($invocation, $phrase, $content, $modifier, $link)
{
	// is there link?
	if (!$link) return $invocation->proceed();

	if (Texy::isRelative($link->URL)) {
		// modifiy link
		$link->URL = 'index?page=' . urlencode($link->URL);

	} elseif (substr($link->URL, 0, 5) === 'wiki:') {
		// modifiy link
		$link->URL = 'http://en.wikipedia.org/wiki/Special:Search?search=' . urlencode(substr($link->URL, 5));
	}

	return $invocation->proceed();
}


$texy = new Texy();

// configuration
$texy->addHandler('phrase', 'phraseHandler');

// processing
$text = file_get_contents('sample.texy');
$html = $texy->process($text);  // that's all folks!


// echo formated output
header('Content-type: text/html; charset=utf-8');
echo $html;


// echo all embedded links
echo '<hr />';
echo '<pre>';
print_r($texy->summary['links']);
echo '</pre>';


// and echo generated HTML code
echo '<hr />';
echo '<pre>';
echo htmlSpecialChars($html);
echo '</pre>';