This file is indexed.

/usr/share/php/texy/src/Texy/Texy.php is in php-texy 2.6-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
<?php

/**
 * This file is part of the Texy! (http://texy.info)
 * Copyright (c) 2004 David Grudl (http://davidgrudl.com)
 */


/**
 * Texy! - Convert plain text to XHTML format using {@link process()}.
 *
 * <code>
 * $texy = new Texy();
 * $html = $texy->process($text);
 * </code>
 *
 * @author     David Grudl
 */
class Texy extends TexyObject
{
	// configuration directives
	const ALL = TRUE;
	const NONE = FALSE;

	// Texy version
	const VERSION = '2.6';
	const REVISION = 'released on 2014-06-20';

	// types of protection marks
	const CONTENT_MARKUP = "\x17";
	const CONTENT_REPLACED = "\x16";
	const CONTENT_TEXTUAL = "\x15";
	const CONTENT_BLOCK = "\x14";

	// url filters
	const FILTER_ANCHOR = 'anchor';
	const FILTER_IMAGE = 'image';

	// HTML minor-modes
	const XML = 2;

	// HTML modes
	const HTML4_TRANSITIONAL = 0;
	const HTML4_STRICT = 1;
	const HTML5 = 4;
	const XHTML1_TRANSITIONAL = 2; // Texy::HTML4_TRANSITIONAL | Texy::XML;
	const XHTML1_STRICT = 3; // Texy::HTML4_STRICT | Texy::XML;
	const XHTML5 = 6; // Texy::HTML5 | Texy::XML;

	/** @var string  input & output text encoding */
	public $encoding = 'utf-8';

	/** @var array  Texy! syntax configuration */
	public $allowed = array();

	/** @var TRUE|FALSE|array  Allowed HTML tags */
	public $allowedTags;

	/** @var TRUE|FALSE|array  Allowed classes */
	public $allowedClasses = Texy::ALL; // all classes and id are allowed

	/** @var TRUE|FALSE|array  Allowed inline CSS style */
	public $allowedStyles = Texy::ALL;  // all inline styles are allowed

	/** @var int  TAB width (for converting tabs to spaces) */
	public $tabWidth = 8;

	/** @var boolean  Do obfuscate e-mail addresses? */
	public $obfuscateEmail = TRUE;

	/** @var array  regexps to check URL schemes */
	public $urlSchemeFilters = NULL; // disable URL scheme filter

	/** @var bool  Paragraph merging mode */
	public $mergeLines = TRUE;

	/** @var array  Parsing summary */
	public $summary = array(
		'images' => array(),
		'links' => array(),
		'preload' => array(),
	);

	/** @var string  Generated stylesheet */
	public $styleSheet = '';

	/** @var array  CSS classes for align modifiers */
	public $alignClasses = array(
		'left' => NULL,
		'right' => NULL,
		'center' => NULL,
		'justify' => NULL,
		'top' => NULL,
		'middle' => NULL,
		'bottom' => NULL,
	);

	/** @var bool  remove soft hyphens (SHY)? */
	public $removeSoftHyphens = TRUE;

	/** @deprecated */
	public static $advertisingNotice = FALSE;

	/** @var string */
	public $nontextParagraph = 'div';

	/** @var TexyScriptModule */
	public $scriptModule;

	/** @var TexyParagraphModule */
	public $paragraphModule;

	/** @var TexyHtmlModule */
	public $htmlModule;

	/** @var TexyImageModule */
	public $imageModule;

	/** @var TexyLinkModule */
	public $linkModule;

	/** @var TexyPhraseModule */
	public $phraseModule;

	/** @var TexyEmoticonModule */
	public $emoticonModule;

	/** @var TexyBlockModule */
	public $blockModule;

	/** @var TexyHeadingModule */
	public $headingModule;

	/** @var TexyHorizLineModule */
	public $horizLineModule;

	/** @var TexyBlockQuoteModule */
	public $blockQuoteModule;

	/** @var TexyListModule */
	public $listModule;

	/** @var TexyTableModule */
	public $tableModule;

	/** @var TexyFigureModule */
	public $figureModule;

	/** @var TexyTypographyModule */
	public $typographyModule;

	/** @var TexyLongWordsModule */
	public $longWordsModule;

	/** @var TexyHtmlOutputModule */
	public $htmlOutputModule;


	/**
	 * Registered regexps and associated handlers for inline parsing.
	 * @var array of ('handler' => callback, 'pattern' => regular expression)
	 */
	private $linePatterns = array();
	private $_linePatterns;

	/**
	 * Registered regexps and associated handlers for block parsing.
	 * @var array of ('handler' => callback, 'pattern' => regular expression)
	 */
	private $blockPatterns = array();
	private $_blockPatterns;

	/** @var array */
	private $postHandlers = array();

	/** @var TexyHtml  DOM structure for parsed text */
	private $DOM;

	/** @var array  Texy protect markup table */
	private $marks = array();

	/** @var array  for internal usage */
	public $_classes, $_styles;

	/** @var bool */
	private $processing;

	/** @var array of events and registered handlers */
	private $handlers = array();

	/**
	 * DTD descriptor.
	 *   $dtd[element][0] - allowed attributes (as array keys)
	 *   $dtd[element][1] - allowed content for an element (content model) (as array keys)
	 *                    - array of allowed elements (as keys)
	 *                    - FALSE - empty element
	 *                    - 0 - special case for ins & del
	 * @var array
	 */
	public $dtd;

	/** @var array */
	private static $dtdCache;

	/** @var int  HTML mode */
	private $mode;


	/** DEPRECATED */
	public static $strictDTD;
	public $cleaner;
	public $xhtml;


	public function __construct()
	{
		// load all modules
		$this->loadModules();

		// DEPRECATED
		if (self::$strictDTD !== NULL) {
			$this->setOutputMode(self::$strictDTD ? self::XHTML1_STRICT : self::XHTML1_TRANSITIONAL);
		} else {
			$this->setOutputMode(self::XHTML1_TRANSITIONAL);
		}

		// DEPRECATED
		$this->cleaner = & $this->htmlOutputModule;

		// examples of link references ;-)
		$link = new TexyLink('http://texy.info/');
		$link->modifier->title = 'The best text -> HTML converter and formatter';
		$link->label = 'Texy!';
		$this->linkModule->addReference('texy', $link);

		$link = new TexyLink('http://www.google.com/search?q=%s');
		$this->linkModule->addReference('google', $link);

		$link = new TexyLink('http://en.wikipedia.org/wiki/Special:Search?search=%s');
		$this->linkModule->addReference('wikipedia', $link);
	}


	/**
	 * Set HTML/XHTML output mode (overwrites self::$allowedTags)
	 * @param  int
	 * @return void
	 */
	public function setOutputMode($mode)
	{
		if (!in_array($mode, array(self::HTML4_TRANSITIONAL, self::HTML4_STRICT,
			self::HTML5, self::XHTML1_TRANSITIONAL, self::XHTML1_STRICT, self::XHTML5), TRUE)
		) {
			throw new InvalidArgumentException("Invalid mode.");
		}

		if (!isset(self::$dtdCache[$mode])) {
			require dirname(__FILE__) . '/DTD.php';
			self::$dtdCache[$mode] = $dtd;
		}

		$this->mode = $mode;
		$this->dtd = self::$dtdCache[$mode];
		TexyHtml::$xhtml = (bool) ($mode & self::XML); // TODO: remove?

		// accept all valid HTML tags and attributes by default
		$this->allowedTags = array();
		foreach ($this->dtd as $tag => $dtd) {
			$this->allowedTags[$tag] = self::ALL;
		}
	}


	/**
	 * Get HTML/XHTML output mode
	 * @return int
	 */
	public function getOutputMode()
	{
		return $this->mode;
	}


	/**
	 * Create array of all used modules ($this->modules).
	 * This array can be changed by overriding this method (by subclasses)
	 */
	protected function loadModules()
	{
		// line parsing
		$this->scriptModule = new TexyScriptModule($this);
		$this->htmlModule = new TexyHtmlModule($this);
		$this->imageModule = new TexyImageModule($this);
		$this->phraseModule = new TexyPhraseModule($this);
		$this->linkModule = new TexyLinkModule($this);
		$this->emoticonModule = new TexyEmoticonModule($this);

		// block parsing
		$this->paragraphModule = new TexyParagraphModule($this);
		$this->blockModule = new TexyBlockModule($this);
		$this->figureModule = new TexyFigureModule($this);
		$this->horizLineModule = new TexyHorizLineModule($this);
		$this->blockQuoteModule = new TexyBlockQuoteModule($this);
		$this->tableModule = new TexyTableModule($this);
		$this->headingModule = new TexyHeadingModule($this);
		$this->listModule = new TexyListModule($this);

		// post process
		$this->typographyModule = new TexyTypographyModule($this);
		$this->longWordsModule = new TexyLongWordsModule($this);
		$this->htmlOutputModule = new TexyHtmlOutputModule($this);
	}


	final public function registerLinePattern($handler, $pattern, $name, $againTest = NULL)
	{
		if (!is_callable($handler)) {
			$able = is_callable($handler, TRUE, $textual);
			throw new InvalidArgumentException("Handler '$textual' is not " . ($able ? 'callable.' : 'valid PHP callback.'));
		}

		if (!isset($this->allowed[$name])) {
			$this->allowed[$name] = TRUE;
		}

		$this->linePatterns[$name] = array(
			'handler' => $handler,
			'pattern' => $pattern,
			'again' => $againTest,
		);
	}


	final public function registerBlockPattern($handler, $pattern, $name)
	{
		if (!is_callable($handler)) {
			$able = is_callable($handler, TRUE, $textual);
			throw new InvalidArgumentException("Handler '$textual' is not " . ($able ? 'callable.' : 'valid PHP callback.'));
		}

		// if (!preg_match('#(.)\^.*\$\\1[a-z]*#is', $pattern)) die("Texy: Not a block pattern $name");
		if (!isset($this->allowed[$name])) {
			$this->allowed[$name] = TRUE;
		}

		$this->blockPatterns[$name] = array(
			'handler' => $handler,
			'pattern' => $pattern . 'm', // force multiline
		);
	}


	final public function registerPostLine($handler, $name)
	{
		if (!is_callable($handler)) {
			$able = is_callable($handler, TRUE, $textual);
			throw new InvalidArgumentException("Handler '$textual' is not " . ($able ? 'callable.' : 'valid PHP callback.'));
		}

		if (!isset($this->allowed[$name])) {
			$this->allowed[$name] = TRUE;
		}

		$this->postHandlers[$name] = $handler;
	}


	/**
	 * Converts document in Texy! to (X)HTML code.
	 *
	 * @param  string   input text
	 * @param  bool     is single line?
	 * @return string   output HTML code
	 */
	public function process($text, $singleLine = FALSE)
	{
		if ($this->processing) {
			throw new RuntimeException('Processing is in progress yet.');
		}

		// initialization
		$this->marks = array();
		$this->processing = TRUE;

		// speed-up
		if (is_array($this->allowedClasses)) {
			$this->_classes = array_flip($this->allowedClasses);
		} else {
			$this->_classes = $this->allowedClasses;
		}
		if (is_array($this->allowedStyles)) {
			$this->_styles = array_flip($this->allowedStyles);
		} else {
			$this->_styles = $this->allowedStyles;
		}

		// convert to UTF-8 (and check source encoding)
		$text = TexyUtf::toUtf($text, $this->encoding);

		if ($this->removeSoftHyphens) {
			$text = str_replace("\xC2\xAD", '', $text);
		}

		// standardize line endings and spaces
		$text = self::normalize($text);

		// replace tabs with spaces
		$this->tabWidth = max(1, (int) $this->tabWidth);
		while (strpos($text, "\t") !== FALSE) {
			$text = TexyRegexp::replace($text, '#^([^\t\n]*+)\t#mU', array($this, 'tabCb'));
		}

		// user before handler
		$this->invokeHandlers('beforeParse', array($this, & $text, $singleLine));

		// select patterns
		$this->_linePatterns = $this->linePatterns;
		$this->_blockPatterns = $this->blockPatterns;
		foreach ($this->_linePatterns as $name => $foo) {
			if (empty($this->allowed[$name])) {
				unset($this->_linePatterns[$name]);
			}
		}
		foreach ($this->_blockPatterns as $name => $foo) {
			if (empty($this->allowed[$name])) {
				unset($this->_blockPatterns[$name]);
			}
		}

		// parse Texy! document into internal DOM structure
		$this->DOM = TexyHtml::el();
		if ($singleLine) {
			$this->DOM->parseLine($this, $text);
		} else {
			$this->DOM->parseBlock($this, $text);
		}

		// user after handler
		$this->invokeHandlers('afterParse', array($this, $this->DOM, $singleLine));

		// converts internal DOM structure to final HTML code
		$html = $this->DOM->toHtml($this);

		// created by TexyParagraphModule and then protected
		$html = str_replace("\r", "\n", $html);

		$this->processing = FALSE;

		return TexyUtf::utf2html($html, $this->encoding);
	}


	/**
	 * Converts single line in Texy! to (X)HTML code.
	 *
	 * @param  string   input text
	 * @return string   output HTML code
	 */
	public function processLine($text)
	{
		return $this->process($text, TRUE);
	}


	/**
	 * Makes only typographic corrections.
	 * @param  string   input text (in encoding defined by Texy::$encoding)
	 * @return string   output text (in UTF-8)
	 */
	public function processTypo($text)
	{
		// convert to UTF-8 (and check source encoding)
		$text = TexyUtf::toUtf($text, $this->encoding);

		// standardize line endings and spaces
		$text = self::normalize($text);

		$this->typographyModule->beforeParse($this, $text);
		$text = $this->typographyModule->postLine($text, TRUE);

		if (!empty($this->allowed['longwords'])) {
			$text = $this->longWordsModule->postLine($text);
		}

		return TexyUtf::utf2html($text, $this->encoding);
	}


	/**
	 * Converts DOM structure to pure text.
	 * @return string
	 */
	public function toText()
	{
		if (!$this->DOM) {
			throw new RuntimeException('Call $texy->process() first.');
		}

		return TexyUtf::utfTo($this->DOM->toText($this), $this->encoding);
	}


	/**
	 * Converts internal string representation to final HTML code in UTF-8.
	 * @return string
	 */
	final public function stringToHtml($s)
	{
		// decode HTML entities to UTF-8
		$s = self::unescapeHtml($s);

		// line-postprocessing
		$blocks = explode(self::CONTENT_BLOCK, $s);
		foreach ($this->postHandlers as $name => $handler) {
			if (empty($this->allowed[$name])) {
				continue;
			}
			foreach ($blocks as $n => $s) {
				if ($n % 2 === 0 && $s !== '') {
					$blocks[$n] = call_user_func($handler, $s);
				}
			}
		}
		$s = implode(self::CONTENT_BLOCK, $blocks);

		// encode < > &
		$s = self::escapeHtml($s);

		// replace protected marks
		$s = $this->unProtect($s);

		// wellform and reformat HTML
		$this->invokeHandlers('postProcess', array($this, & $s));

		// unfreeze spaces
		$s = self::unfreezeSpaces($s);

		return $s;
	}


	/**
	 * Converts internal string representation to final HTML code in UTF-8.
	 * @return string
	 */
	final public function stringToText($s)
	{
		$save = $this->htmlOutputModule->lineWrap;
		$this->htmlOutputModule->lineWrap = FALSE;
		$s = $this->stringToHtml( $s );
		$this->htmlOutputModule->lineWrap = $save;

		// remove tags
		$s = TexyRegexp::replace($s, '#<(script|style)(.*)</\\1>#Uis', '');
		$s = strip_tags($s);
		$s = TexyRegexp::replace($s, '#\n\s*\n\s*\n[\n\s]*\n#', "\n\n");

		// entities -> chars
		$s = self::unescapeHtml($s);

		// convert nbsp to normal space and remove shy
		$s = strtr($s, array(
			"\xC2\xAD" => '', // shy
			"\xC2\xA0" => ' ', // nbsp
		));

		return $s;
	}


	/**
	 * Add new event handler.
	 *
	 * @param  string   event name
	 * @param  callback
	 * @return void
	 */
	final public function addHandler($event, $callback)
	{
		if (!is_callable($callback)) {
			$able = is_callable($callback, TRUE, $textual);
			throw new InvalidArgumentException("Handler '$textual' is not " . ($able ? 'callable.' : 'valid PHP callback.'));
		}

		$this->handlers[$event][] = $callback;
	}


	/**
	 * Invoke registered around-handlers.
	 *
	 * @param  string   event name
	 * @param  TexyParser  actual parser object
	 * @param  array    arguments passed into handler
	 * @return mixed
	 */
	final public function invokeAroundHandlers($event, $parser, $args)
	{
		if (!isset($this->handlers[$event])) {
			return FALSE;
		}

		$invocation = new TexyHandlerInvocation($this->handlers[$event], $parser, $args);
		$res = $invocation->proceed();
		$invocation->free();
		return $res;
	}


	/**
	 * Invoke registered after-handlers.
	 *
	 * @param  string   event name
	 * @param  array    arguments passed into handler
	 * @return void
	 */
	final public function invokeHandlers($event, $args)
	{
		if (!isset($this->handlers[$event])) {
			return;
		}

		foreach ($this->handlers[$event] as $handler) {
			call_user_func_array($handler, $args);
		}
	}


	/**
	 * Translate all white spaces (\t \n \r space) to meta-spaces \x01-\x04.
	 * which are ignored by TexyHtmlOutputModule routine
	 * @param  string
	 * @return string
	 */
	final public static function freezeSpaces($s)
	{
		return strtr($s, " \t\r\n", "\x01\x02\x03\x04");
	}


	/**
	 * Reverts meta-spaces back to normal spaces.
	 * @param  string
	 * @return string
	 */
	final public static function unfreezeSpaces($s)
	{
		return strtr($s, "\x01\x02\x03\x04", " \t\r\n");
	}


	/**
	 * Removes special controls characters and normalizes line endings and spaces.
	 * @param  string
	 * @return string
	 */
	final public static function normalize($s)
	{
		// standardize line endings to unix-like
		$s = str_replace("\r\n", "\n", $s); // DOS
		$s = strtr($s, "\r", "\n"); // Mac

		// remove special chars; leave \t + \n
		$s = TexyRegexp::replace($s, '#[\x00-\x08\x0B-\x1F]+#', '');

		// right trim
		$s = TexyRegexp::replace($s, "#[\t ]+$#m", '');

		// trailing spaces
		$s = trim($s, "\n");

		return $s;
	}


	/**
	 * Converts to web safe characters [a-z0-9-] text.
	 * @param  string
	 * @param  string
	 * @return string
	 */
	final public static function webalize($s, $charlist = NULL)
	{
		$s = TexyUtf::utf2ascii($s);
		$s = strtolower($s);
		$s = TexyRegexp::replace($s, '#[^a-z0-9'.preg_quote($charlist, '#').']+#', '-');
		$s = trim($s, '-');
		return $s;
	}


	/**
	 * Texy! version of htmlSpecialChars (much faster than htmlSpecialChars!).
	 * note: &quot; is not encoded!
	 * @param  string
	 * @return string
	 */
	final public static function escapeHtml($s)
	{
		return str_replace(array('&', '<', '>'), array('&amp;', '&lt;', '&gt;'), $s);
	}


	/**
	 * Texy! version of html_entity_decode (always UTF-8, much faster than original!).
	 * @param  string
	 * @return string
	 */
	final public static function unescapeHtml($s)
	{
		if (strpos($s, '&') === FALSE) {
			return $s;
		}
		return html_entity_decode($s, ENT_QUOTES, 'UTF-8');
	}


	/**
	 * Outdents text block.
	 * @param  string
	 * @return string
	 */
	final public static function outdent($s)
	{
		$s = trim($s, "\n");
		$min = strlen($s);
		foreach (TexyRegexp::match($s, '#^ *\S#m', TexyRegexp::ALL) as $m) {
			$min = min($min, strlen($m[0]) - 1);
		}
		if ($min) {
			$s = TexyRegexp::replace($s, "#^ {{$min}}#m", '');
		}
		return $s;
	}


	/**
	 * Generate unique mark - useful for freezing (folding) some substrings.
	 * @param  string   any string to froze
	 * @param  int      Texy::CONTENT_* constant
	 * @return string  internal mark
	 */
	final public function protect($child, $contentType)
	{
		if ($child === '') {
			return '';
		}

		$key = $contentType
			. strtr(base_convert(count($this->marks), 10, 8), '01234567', "\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F")
			. $contentType;

		$this->marks[$key] = $child;

		return $key;
	}


	final public function unProtect($html)
	{
		return strtr($html, $this->marks);
	}


	/**
	 * Filters bad URLs.
	 * @param  string   user URL
	 * @param  string   type: a-anchor, i-image, c-cite
	 * @return bool
	 */
	final public function checkURL($URL, $type)
	{
		// absolute URL with scheme? check scheme!
		return empty($this->urlSchemeFilters[$type])
			|| !preg_match('#[a-z][a-z0-9+.-]{0,20}:#A', $URL) // http: | mailto:
			|| preg_match($this->urlSchemeFilters[$type], $URL);
	}


	/**
	 * Is given URL relative?
	 * @param  string  URL
	 * @return bool
	 */
	final public static function isRelative($URL)
	{
		// check for scheme, or absolute path, or absolute URL
		return !preg_match('#[a-z][a-z0-9+.-]{0,20}:|[\#/?]#A', $URL);
	}


	/**
	 * Prepends root to URL, if possible.
	 * @param  string  URL
	 * @param  string  root
	 * @return string
	 */
	final public static function prependRoot($URL, $root)
	{
		if ($root == NULL || !self::isRelative($URL)) {
			return $URL;
		}
		return rtrim($root, '/\\') . '/' . $URL;
	}


	final public function getLinePatterns()
	{
		return $this->_linePatterns;
	}


	final public function getBlockPatterns()
	{
		return $this->_blockPatterns;
	}


	final public function getDOM()
	{
		return $this->DOM;
	}


	/** @internal */
	public function tabCb($m)
	{
		return $m[1] . str_repeat(' ', $this->tabWidth - strlen($m[1]) % $this->tabWidth);
	}


	/**
	 * PHP garbage collector helper.
	 */
	final public function free()
	{
		if (version_compare(PHP_VERSION , '5.3', '<')) {
			foreach (array_keys(get_object_vars($this)) as $key) {
				$this->$key = NULL;
			}
		}
	}


	final public function __clone()
	{
		throw new Exception('Clone is not supported.');
	}

}


/**
 * For Texy 1 backward compatibility.
 */
define('TEXY_ALL', Texy::ALL);
define('TEXY_NONE', Texy::NONE);
define('TEXY_CONTENT_MARKUP', Texy::CONTENT_MARKUP);
define('TEXY_CONTENT_REPLACED', Texy::CONTENT_REPLACED);
define('TEXY_CONTENT_TEXTUAL', Texy::CONTENT_TEXTUAL);
define('TEXY_CONTENT_BLOCK', Texy::CONTENT_BLOCK);
define('TEXY_VERSION', Texy::VERSION);

/**
 * For Texy 2.2 compatibility
 */
define('TEXY_CHAR',        TexyPatterns::CHAR);
define('TEXY_MARK',        TexyPatterns::MARK);
define('TEXY_MODIFIER',    TexyPatterns::MODIFIER);
define('TEXY_MODIFIER_H',  TexyPatterns::MODIFIER_H);
define('TEXY_MODIFIER_HV', TexyPatterns::MODIFIER_HV);
define('TEXY_IMAGE',       TexyPatterns::IMAGE);
define('TEXY_LINK_URL',    TexyPatterns::LINK_URL);
define('TEXY_LINK',        '(?::('.TEXY_LINK_URL.'))');
define('TEXY_LINK_N',      '(?::('.TEXY_LINK_URL.'|:))');
define('TEXY_EMAIL',       '['.TEXY_CHAR.'][0-9.+_'.TEXY_CHAR.'-]{0,63}@[0-9.+_'.TEXY_CHAR.'\x{ad}-]{1,252}\.['.TEXY_CHAR.'\x{ad}]{2,19}');
define('TEXY_URLSCHEME',   '[a-z][a-z0-9+.-]{0,20}:');