/usr/share/php/texy/src/Texy/modules/TexyParagraphModule.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 | <?php
/**
* This file is part of the Texy! (http://texy.info)
* Copyright (c) 2004 David Grudl (http://davidgrudl.com)
*/
/**
* Paragraph module.
*
* @author David Grudl
*/
final class TexyParagraphModule extends TexyModule
{
public function __construct($texy)
{
$this->texy = $texy;
$texy->addHandler('paragraph', array($this, 'solve'));
}
/**
* @param TexyBlockParser
* @param string text
* @param array
* @param TexyHtml
* @return vois
*/
public function process($parser, $content, $el)
{
$tx = $this->texy;
if ($parser->isIndented()) {
$parts = preg_split('#(\n(?! )|\n{2,})#', $content, -1, PREG_SPLIT_NO_EMPTY);
} else {
$parts = preg_split('#(\n{2,})#', $content, -1, PREG_SPLIT_NO_EMPTY);
}
foreach ($parts as $s) {
$s = trim($s);
if ($s === '') {
continue;
}
// try to find modifier
$mod = NULL;
if ($mx = TexyRegexp::match($s, '#'.TexyPatterns::MODIFIER_H.'(?=\n|\z)#sUm', TexyRegexp::OFFSET_CAPTURE)) {
list($mMod) = $mx[1];
$s = trim(substr_replace($s, '', $mx[0][1], strlen($mx[0][0])));
if ($s === '') {
continue;
}
$mod = new TexyModifier;
$mod->setProperties($mMod);
}
$res = $tx->invokeAroundHandlers('paragraph', $parser, array($s, $mod));
if ($res) {
$el->insert(NULL, $res);
}
}
}
/**
* Finish invocation.
*
* @param TexyHandlerInvocation handler invocation
* @param string
* @param TexyModifier|NULL
* @return TexyHtml|FALSE
*/
public function solve($invocation, $content, $mod)
{
$tx = $this->texy;
// find hard linebreaks
if ($tx->mergeLines) {
// ....
// ... => \r means break line
$content = TexyRegexp::replace($content, '#\n +(?=\S)#', "\r");
} else {
$content = TexyRegexp::replace($content, '#\n#', "\r");
}
$el = TexyHtml::el('p');
$el->parseLine($tx, $content);
$content = $el->getText(); // string
// check content type
// block contains block tag
if (strpos($content, Texy::CONTENT_BLOCK) !== FALSE) {
$el->setName(NULL); // ignores modifier!
// block contains text (protected)
} elseif (strpos($content, Texy::CONTENT_TEXTUAL) !== FALSE) {
// leave element p
// block contains text
} elseif (preg_match('#[^\s'.TexyPatterns::MARK.']#u', $content)) {
// leave element p
// block contains only replaced element
} elseif (strpos($content, Texy::CONTENT_REPLACED) !== FALSE) {
$el->setName($tx->nontextParagraph);
// block contains only markup tags or spaces or nothing
} else {
// if {ignoreEmptyStuff} return FALSE;
if (!$mod) {
$el->setName(NULL);
}
}
if ($el->getName()) {
// apply modifier
if ($mod) {
$mod->decorate($tx, $el);
}
// add <br />
if (strpos($content, "\r") !== FALSE) {
$key = $tx->protect('<br />', Texy::CONTENT_REPLACED);
$content = str_replace("\r", $key, $content);
};
}
$content = strtr($content, "\r\n", ' ');
$el->setText($content);
return $el;
}
}
|