This file is indexed.

/usr/share/php/texy/src/Texy/modules/TexyHtmlOutputModule.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
<?php

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


/**
 *
 * @author     David Grudl
 */
final class TexyHtmlOutputModule extends TexyModule
{
	/** @var bool  indent HTML code? */
	public $indent = TRUE;

	/** @var array */
	public $preserveSpaces = array('textarea', 'pre', 'script', 'code', 'samp', 'kbd');

	/** @var int  base indent level */
	public $baseIndent = 0;

	/** @var int  wrap width, doesn't include indent space */
	public $lineWrap = 80;

	/** @var bool  remove optional HTML end tags? */
	public $removeOptional = FALSE;

	/** @var int  indent space counter */
	private $space;

	/** @var array */
	private $tagUsed;

	/** @var array */
	private $tagStack;

	/** @var array  content DTD used, when context is not defined */
	private $baseDTD;

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


	public function __construct($texy)
	{
		$this->texy = $texy;
		$texy->addHandler('postProcess', array($this, 'postProcess'));
	}


	/**
	 * Converts <strong><em> ... </strong> ... </em>.
	 * into <strong><em> ... </em></strong><em> ... </em>
	 */
	public function postProcess($texy, & $s)
	{
		$this->space = $this->baseIndent;
		$this->tagStack = array();
		$this->tagUsed = array();
		$this->xml = $texy->getOutputMode() & Texy::XML;

		// special "base content"
		$this->baseDTD = $texy->dtd['div'][1] + $texy->dtd['html'][1] /*+ $texy->dtd['head'][1]*/ + $texy->dtd['body'][1] + array('html'=>1);

		// wellform and reformat
		$s = TexyRegexp::replace(
			$s . '</end/>',
			'#([^<]*+)<(?:(!--.*--)|(/?)([a-z][a-z0-9._:-]*)(|[ \n].*)\s*(/?))>()#Uis',
			array($this, 'cb')
		);

		// empty out stack
		foreach ($this->tagStack as $item) {
			$s .= $item['close'];
		}

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

		// join double \r to single \n
		$s = str_replace("\r\r", "\n", $s);
		$s = strtr($s, "\r", "\n");

		// greedy chars
		$s = TexyRegexp::replace($s, "#\\x07 *#", '');
		// back-tabs
		$s = TexyRegexp::replace($s, "#\\t? *\\x08#", '');

		// line wrap
		if ($this->lineWrap > 0) {
			$s = TexyRegexp::replace(
				$s,
				'#^(\t*)(.*)$#m',
				array($this, 'wrap')
			);
		}

		// remove HTML 4.01 optional end tags
		if (!$this->xml && $this->removeOptional) {
			$s = TexyRegexp::replace($s, '#\\s*</(colgroup|dd|dt|li|option|p|td|tfoot|th|thead|tr)>#u', '');
		}
	}


	/**
	 * Callback function: <tag> | </tag> | ....
	 * @return string
	 * @internal
	 */
	public function cb($matches)
	{
		// html tag
		list(, $mText, $mComment, $mEnd, $mTag, $mAttr, $mEmpty) = $matches;
		// [1] => text
		// [1] => !-- comment --
		// [2] => /
		// [3] => TAG
		// [4] => ... (attributes)
		// [5] => / (empty)

		$s = '';

		// phase #1 - stuff between tags
		if ($mText !== '') {
			$item = reset($this->tagStack);
			if ($item && !isset($item['dtdContent']['%DATA'])) {  // text not allowed?

			} elseif (array_intersect(array_keys($this->tagUsed, TRUE), $this->preserveSpaces)) { // inside pre & textarea preserve spaces
				$s = Texy::freezeSpaces($mText);

			} else {
				$s = TexyRegexp::replace($mText, '#[ \n]+#', ' '); // otherwise shrink multiple spaces
			}
		}


		// phase #2 - HTML comment
		if ($mComment) {
			return $s . '<' . Texy::freezeSpaces($mComment) . '>';
		}


		// phase #3 - HTML tag
		$mEmpty = $mEmpty || isset(TexyHtml::$emptyElements[$mTag]);
		if ($mEmpty && $mEnd) {
			return $s; // bad tag; /end/
		}


		if ($mEnd) { // end tag

			// has start tag?
			if (empty($this->tagUsed[$mTag])) {
				return $s;
			}

			// autoclose tags
			$tmp = array();
			$back = TRUE;
			foreach ($this->tagStack as $i => $item) {
				$tag = $item['tag'];
				$s .= $item['close'];
				$this->space -= $item['indent'];
				$this->tagUsed[$tag]--;
				$back = $back && isset(TexyHtml::$inlineElements[$tag]);
				unset($this->tagStack[$i]);
				if ($tag === $mTag) {
					break;
				}
				array_unshift($tmp, $item);
			}

			if (!$back || !$tmp) {
				return $s;
			}

			// allowed-check (nejspis neni ani potreba)
			$item = reset($this->tagStack);
			$dtdContent = $item ? $item['dtdContent'] : $this->baseDTD;
			if (!isset($dtdContent[$tmp[0]['tag']])) {
				return $s;
			}

			// autoopen tags
			foreach ($tmp as $item) {
				$s .= $item['open'];
				$this->space += $item['indent'];
				$this->tagUsed[$item['tag']]++;
				array_unshift($this->tagStack, $item);
			}


		} else { // start tag

			$dtdContent = $this->baseDTD;

			if (!isset($this->texy->dtd[$mTag])) {
				// unknown (non-html) tag
				$allowed = TRUE;
				$item = reset($this->tagStack);
				if ($item) {
					$dtdContent = $item['dtdContent'];
				}


			} else {
				// optional end tag closing
				foreach ($this->tagStack as $i => $item) {
					// is tag allowed here?
					$dtdContent = $item['dtdContent'];
					if (isset($dtdContent[$mTag])) {
						break;
					}

					$tag = $item['tag'];

					// auto-close hidden, optional and inline tags
					if ($item['close'] && (!isset(TexyHtml::$optionalEnds[$tag]) && !isset(TexyHtml::$inlineElements[$tag]))) {
						break;
					}

					// close it
					$s .= $item['close'];
					$this->space -= $item['indent'];
					$this->tagUsed[$tag]--;
					unset($this->tagStack[$i]);
					$dtdContent = $this->baseDTD;
				}

				// is tag allowed in this content?
				$allowed = isset($dtdContent[$mTag]);

				// check deep element prohibitions
				if ($allowed && isset(TexyHtml::$prohibits[$mTag])) {
					foreach (TexyHtml::$prohibits[$mTag] as $pTag) {
						if (!empty($this->tagUsed[$pTag])) {
							$allowed = FALSE; break;
						}
					}
				}
			}

			// empty elements se neukladaji do zasobniku
			if ($mEmpty) {
				if (!$allowed) {
					return $s;
				}

				if ($this->xml) {
					$mAttr .= " /";
				}

				$indent = $this->indent && !array_intersect(array_keys($this->tagUsed, TRUE), $this->preserveSpaces);

				if ($indent && $mTag === 'br') { // formatting exception
					return rtrim($s) . '<' . $mTag . $mAttr . ">\n" . str_repeat("\t", max(0, $this->space - 1)) . "\x07";

				} elseif ($indent && !isset(TexyHtml::$inlineElements[$mTag])) {
					$space = "\r" . str_repeat("\t", $this->space);
					return $s . $space . '<' . $mTag . $mAttr . '>' . $space;

				} else {
					return $s . '<' . $mTag . $mAttr . '>';
				}
			}

			$open = NULL;
			$close = NULL;
			$indent = 0;

			/*
			if (!isset(TexyHtml::$inlineElements[$mTag])) {
				// block tags always decorate with \n
				$s .= "\n";
				$close = "\n";
			}
			*/

			if ($allowed) {
				$open = '<' . $mTag . $mAttr . '>';

				// receive new content (ins & del are special cases)
				if (!empty($this->texy->dtd[$mTag][1])) {
					$dtdContent = $this->texy->dtd[$mTag][1];
				}

				// format output
				if ($this->indent && !isset(TexyHtml::$inlineElements[$mTag])) {
					$close = "\x08" . '</'.$mTag.'>' . "\n" . str_repeat("\t", $this->space);
					$s .= "\n" . str_repeat("\t", $this->space++) . $open . "\x07";
					$indent = 1;
				} else {
					$close = '</'.$mTag.'>';
					$s .= $open;
				}

				// TODO: problematic formatting of select / options, object / params
			}


			// open tag, put to stack, increase counter
			$item = array(
				'tag' => $mTag,
				'open' => $open,
				'close' => $close,
				'dtdContent' => $dtdContent,
				'indent' => $indent,
			);
			array_unshift($this->tagStack, $item);
			$tmp = & $this->tagUsed[$mTag]; $tmp++;
		}

		return $s;
	}


	/**
	 * Callback function: wrap lines.
	 * @return string
	 * @internal
	 */
	public function wrap($m)
	{
		list(, $space, $s) = $m;
		return $space . wordwrap($s, $this->lineWrap, "\n" . $space);
	}

}