Skip to content

Commit

Permalink
* fixed TexyFigureModule classes & modifiers
Browse files Browse the repository at this point in the history
* <html>, <head>, <body> added into TexyHtmlOutputModule baseDTD & optional tags
  • Loading branch information
dg committed Aug 20, 2007
1 parent 89b125b commit 1a52353
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 32 deletions.
22 changes: 15 additions & 7 deletions texy-for-php4/modules/TexyFigureModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,33 +102,41 @@ function solve($invocation, /*TexyImage*/ $image, $link, $content, $mod)
$tx = $this->texy;

$hAlign = $image->modifier->hAlign;
$mod->hAlign = $image->modifier->hAlign = NULL;
$image->modifier->hAlign = NULL;

$elImg = $tx->imageModule->solve(NULL, $image, $link); // returns TexyHtml or false!
if (!$elImg) return FALSE;

$el = TexyHtml::el('div');
if (!empty($image->width)) $el->attrs['style']['width'] = ($image->width + $this->widthDelta) . 'px';
if (!empty($image->width) && $this->widthDelta !== FALSE) {
$el->attrs['style']['width'] = ($image->width + $this->widthDelta) . 'px';
}
$mod->decorate($tx, $el);

$el->children['img'] = $elImg;
$el->children['caption'] = TexyHtml::el('p');
$el->children['caption']->parseLine($tx, ltrim($content));

if ($hAlign === 'left') {
if ($this->leftClass != '')
if ($this->leftClass != '') {
$el->attrs['class'][] = $this->leftClass;
else
} else {
$el->attrs['style']['float'] = 'left';
$el->attrs['class'][] = $this->class;
}

} elseif ($hAlign === 'right') {

if ($this->rightClass != '')
if ($this->rightClass != '') {
$el->attrs['class'][] = $this->rightClass;
else
} else {
$el->attrs['style']['float'] = 'right';
} elseif ($this->class)
$el->attrs['class'][] = $this->class;
}

} else {
$el->attrs['class'][] = $this->class;
}

return $el;
}
Expand Down
7 changes: 4 additions & 3 deletions texy-for-php4/modules/TexyHtmlOutputModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@


/** @var array elements with optional end tag in HTML */
$GLOBALS['TexyHtmlOutputModule::$optional'] = array('colgroup'=>1,'dd'=>1,'dt'=>1,'li'=>1,'option'=>1,
'p'=>1,'tbody'=>1,'td'=>1,'tfoot'=>1,'th'=>1,'thead'=>1,'tr'=>1); /* class private static property */
$GLOBALS['TexyHtmlOutputModule::$optional'] = array('body'=>1,'head'=>1,'html'=>1,'colgroup'=>1,'dd'=>1,
'dt'=>1,'li'=>1,'option'=>1,'p'=>1,'tbody'=>1,'td'=>1,'tfoot'=>1,'th'=>1,'thead'=>1,'tr'=>1);

/** @see http://www.w3.org/TR/xhtml1/prohibitions.html */
$GLOBALS['TexyHtmlOutputModule::$prohibits'] = array(
Expand Down Expand Up @@ -105,8 +105,9 @@ function postProcess($texy, & $s)
$this->space = $this->baseIndent;
$this->tagStack = array();
$this->tagUsed = array();

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

// wellform and reformat
$s = preg_replace_callback(
Expand Down
2 changes: 1 addition & 1 deletion texy-for-php4/modules/TexyListModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ function patternDefList($parser, $matches)
$tx = $this->texy;

$bullet = NULL;
foreach ($this->bullets as $type => $desc)
foreach ($this->bullets as $desc)
if (preg_match('#'.$desc[0].'#Au', $mBullet)) {
$bullet = isset($desc[3]) ? $desc[3] : $desc[0];
break;
Expand Down
10 changes: 5 additions & 5 deletions texy-for-php4/texy.php
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,7 @@ function invokeAroundHandlers($event, $parser, $args)
*/
function invokeHandlers($event, $args)
{
if (!isset($this->handlers[$event])) return FALSE;
if (!isset($this->handlers[$event])) return;

foreach ($this->handlers[$event] as $handler) {
call_user_func_array($handler, $args);
Expand Down Expand Up @@ -615,15 +615,15 @@ function unfreezeSpaces($s) /* static */
*/
function normalize($s) /* static */
{
// remove special chars
$s = preg_replace('#[\x01-\x04\x14-\x1F]+#', '', $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 = preg_replace('#[\x00-\x08\x0B-\x1F]+#', '', $s);

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

// trailing spaces
$s = trim($s, "\n");
Expand Down
22 changes: 15 additions & 7 deletions texy/modules/TexyFigureModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,33 +102,41 @@ public function solve($invocation, TexyImage $image, $link, $content, $mod)
$tx = $this->texy;

$hAlign = $image->modifier->hAlign;
$mod->hAlign = $image->modifier->hAlign = NULL;
$image->modifier->hAlign = NULL;

$elImg = $tx->imageModule->solve(NULL, $image, $link); // returns TexyHtml or false!
if (!$elImg) return FALSE;

$el = TexyHtml::el('div');
if (!empty($image->width)) $el->attrs['style']['width'] = ($image->width + $this->widthDelta) . 'px';
if (!empty($image->width) && $this->widthDelta !== FALSE) {
$el->attrs['style']['width'] = ($image->width + $this->widthDelta) . 'px';
}
$mod->decorate($tx, $el);

$el->children['img'] = $elImg;
$el->children['caption'] = TexyHtml::el('p');
$el->children['caption']->parseLine($tx, ltrim($content));

if ($hAlign === 'left') {
if ($this->leftClass != '')
if ($this->leftClass != '') {
$el->attrs['class'][] = $this->leftClass;
else
} else {
$el->attrs['style']['float'] = 'left';
$el->attrs['class'][] = $this->class;
}

} elseif ($hAlign === 'right') {

if ($this->rightClass != '')
if ($this->rightClass != '') {
$el->attrs['class'][] = $this->rightClass;
else
} else {
$el->attrs['style']['float'] = 'right';
} elseif ($this->class)
$el->attrs['class'][] = $this->class;
}

} else {
$el->attrs['class'][] = $this->class;
}

return $el;
}
Expand Down
7 changes: 4 additions & 3 deletions texy/modules/TexyHtmlOutputModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ final class TexyHtmlOutputModule extends TexyModule
private static $dtdCache;

/** @var array elements with optional end tag in HTML */
private static $optional = array('colgroup'=>1,'dd'=>1,'dt'=>1,'li'=>1,'option'=>1,
'p'=>1,'tbody'=>1,'td'=>1,'tfoot'=>1,'th'=>1,'thead'=>1,'tr'=>1);
private static $optional = array('body'=>1,'head'=>1,'html'=>1,'colgroup'=>1,'dd'=>1,
'dt'=>1,'li'=>1,'option'=>1,'p'=>1,'tbody'=>1,'td'=>1,'tfoot'=>1,'th'=>1,'thead'=>1,'tr'=>1);

/** @see http://www.w3.org/TR/xhtml1/prohibitions.html */
private static $prohibits = array(
Expand Down Expand Up @@ -103,8 +103,9 @@ public function postProcess($texy, & $s)
$this->space = $this->baseIndent;
$this->tagStack = array();
$this->tagUsed = array();

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

// wellform and reformat
$s = preg_replace_callback(
Expand Down
2 changes: 1 addition & 1 deletion texy/modules/TexyListModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ public function patternDefList($parser, $matches)
$tx = $this->texy;

$bullet = NULL;
foreach ($this->bullets as $type => $desc)
foreach ($this->bullets as $desc)
if (preg_match('#'.$desc[0].'#Au', $mBullet)) {
$bullet = isset($desc[3]) ? $desc[3] : $desc[0];
break;
Expand Down
10 changes: 5 additions & 5 deletions texy/texy.php
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,7 @@ final public function invokeAroundHandlers($event, $parser, $args)
*/
final public function invokeHandlers($event, $args)
{
if (!isset($this->handlers[$event])) return FALSE;
if (!isset($this->handlers[$event])) return;

foreach ($this->handlers[$event] as $handler) {
call_user_func_array($handler, $args);
Expand Down Expand Up @@ -614,15 +614,15 @@ final public static function unfreezeSpaces($s)
*/
final public static function normalize($s)
{
// remove special chars
$s = preg_replace('#[\x01-\x04\x14-\x1F]+#', '', $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 = preg_replace('#[\x00-\x08\x0B-\x1F]+#', '', $s);

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

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

0 comments on commit 1a52353

Please sign in to comment.