Hi hknight
I'm afraid this won't work. You can't pass constructor arguments to the TextParser subclasses via templates.
It works (roughly) like this:
1) Template parser finds .Parse(xy) statement
2) It checks if xy is a class and if it's a subclass of TextParser
3) It creates a new instance of xy, passing the content to the constructor
4) The xy->parse() return value is being returned.
So there's actually no straightforward way to inject your parameters in this process.
You could do the following however:
<?php
class TextToXHTML extends TextParser
{
private static $tag = 'div';
function parse(){
$str = $this->content;
$str = htmlentities($str);
$str = str_ireplace(array('"','"','"'),'"',$str);
$str = str_ireplace(array('‘','‘','‘','’','’','’',''',''','''),"'",$str);
$str = str_replace("'",'‘',preg_replace('/([A-Z0-9])\'/i','$1’',$str));
$str = str_replace('"','“',preg_replace('/([A-Z0-9])\"/i','$1”',$str));
$str = str_replace("\n\n",'</'.self::$tag.'><'.self::$tag.'>', $str);
$str = str_replace("\n","<br />\n", $str);
return '<'.self::$tag.'>' . $str . '</'.self::$tag.'>';
}
static function setTag($tag = 'div'){
self::$tag = $tag;
}
}
Then you would need a helper method to alter the Tag in your Page.php class. Something like this:
// put this in Page_Controller
public function SetTag($tag){
TextToXHTML::setTag($tag);
}
Then you would be able to do something like this in your template:
$SetTag(p)
$Text2.Parse(TextToXHTML)
All subsequent calls after the SetTag call will use <p> as tag...
It's not a very elegant solution, but maybe the one with the least work involved. Maybe somebody here has got a better idea.
On a side note: What are you actually trying to achieve? Did you have a look at the methods of the Convert class (sapphire/core/Convert.php)? There are quite a lot of helper functions to convert from RAW text to XML/XHTML and vice-versa.