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 (76 lines) | stat: -rw-r--r-- 1,715 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
65
66
67
68
69
70
71
72
73
74
75
76
<?php

/**
 * TEXY! HEADINGS DEMO
 */


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


$texy = new Texy();
$text = file_get_contents('sample.texy');


// 1) Dynamic method

$texy->headingModule->top       = 2;   // set headings top limit
$texy->headingModule->balancing = TexyHeadingModule::DYNAMIC;

// generate ID
$texy->headingModule->generateID = TRUE;


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

// echo topmost heading (text is html safe!)
header('Content-type: text/html; charset=utf-8');
echo '<title>' . $texy->headingModule->title . '</title>';

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


// 2) Fixed method

$texy->headingModule->top       = 1;   // set headings top limit
$texy->headingModule->balancing = TexyHeadingModule::FIXED;

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

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


// 3) User-defined fixed method

$texy->headingModule->top       = 1;   // set headings top limit
$texy->headingModule->balancing = TexyHeadingModule::FIXED;

$texy->headingModule->levels['='] = 0;  // = means 0 + top (1) = 1 (h1)
$texy->headingModule->levels['-'] = 1;  // - means 1 + top (1) = 2 (h2)

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

// and echo generated HTML code
echo '<strong>User-defined fixed method:</strong>';
echo '<pre>';
echo htmlSpecialChars($html);
echo '</pre>';
echo '<hr />';


// and echo TOC
echo '<h2>Table of contents</h2>';
echo '<pre>';
print_r($texy->headingModule->TOC);
echo '</pre>';