Skip to content

Commit

Permalink
added charset and quotes support to html translation (changed interna…
Browse files Browse the repository at this point in the history
…l algo

from mapping html translation tabloes to using htmlspecialchars and htmlentities)


git-svn-id: https://svn.php.net/repository/pear/packages/Text_Wiki/trunk@187172 c90b9560-bf6c-de11-be94-00142212c4b1
  • Loading branch information
Paul M Jones committed May 28, 2005
1 parent 7eab08d commit e42f935
Showing 1 changed file with 47 additions and 15 deletions.
62 changes: 47 additions & 15 deletions Text/Wiki/Render/Xhtml.php
Expand Up @@ -2,26 +2,58 @@

class Text_Wiki_Render_Xhtml extends Text_Wiki_Render {

var $conf = array('translate' => HTML_ENTITIES);
var $conf = array(
'translate' => HTML_ENTITIES,
'quotes' => ENT_COMPAT,
'charset' => 'ISO-8859-1'
);

function pre()
{
// attempt to translate HTML entities in the source before continuing.
$type = $this->getConf('translate', null);
// attempt to translate HTML entities in the source.
// get the config options.
$type = $this->getConf('translate', HTML_ENTITIES);
$quotes = $this->getConf('quotes', ENT_COMPAT);
$charset = $this->getConf('charset', 'ISO-8859-1');

// are we translating html?
if ($type !== false && $type !== null) {

// yes! get the translation table.
$xlate = get_html_translation_table($type);

// remove the delimiter character it doesn't get translated
unset($xlate[$this->wiki->delim]);

// translate!
$this->wiki->source = strtr($this->wiki->source, $xlate);
}
// have to check null and false because HTML_ENTITIES is a zero
if ($type !== null && $type !== false && $type == HTML_ENTITIES) {

// keep a copy of the translated version of the delimiter
// so we can convert it back.
$new_delim = htmlentities($this->wiki->delim, $quotes, $charset);

// convert the entities
$this->wiki->source = htmlentities(
$this->wiki->source,
$quotes,
$charset
);

// re-convert the delimiter
$this->wiki->source = str_replace(
$new_delim, $this->wiki->delim, $this->wiki->source
);

} elseif ($type == HTML_SPECIALCHARS) {

// keep a copy of the translated version of the delimiter
// so we can convert it back.
$new_delim = htmlspecialchars($this->wiki->delim, $quotes,
$charset);

// convert the special chars
$this->wiki->source = htmlspecialchars(
$this->wiki->source,
$quotes,
$charset
);

// re-convert the delimiter
$this->wiki->source = str_replace(
$new_delim, $this->wiki->delim, $this->wiki->source
);
}
}

function post()
Expand Down

0 comments on commit e42f935

Please sign in to comment.