function doScript ($pagename, $scriptFormat, $code, $attrstr) {
	$attr = new Attributes($attrstr, array('print'=>'fo'));
	$attr = $attr->getAttribs('fo');
	if ($code == '')
		$so = ScriptObjectFactory::createScriptObjectFromFile($pagename, $scriptFormat, $attr['file']);
	else {
		$code = html_entity_decode($code);
		$code = str_replace("\\'", "'", $code);
		$code = str_replace("\\\"", '"', $code);
		$so = ScriptObjectFactory::createScriptObjectFromCode($pagename, $scriptFormat, $code);
	}	
	if ($so !== false) {
		$mo_png = $so->convert('png', $attr);
		$mo_eps = $so->convert('eps', $attr);
		$mo_pdf = $so->convert('pdf', $attr);
		$xml = "<imageobject>\n";
		if ($mo_png !== false)
			$xml.= $mo_png->getWikiXML('html', $attr) . "\n";
		if ($mo_eps !== false)
			$xml.= $mo_eps->getWikiXML('fo', $attr) . "\n";
		if ($mo_pdf !== false)
			$xml.= $mo_pdf->getWikiXML('fo', $attr) . "\n";
		$xml.= "</imageobject>\n";
		return Keep($xml);
	}
	return '';
}
function doScript ($pagename, $scriptFormat, $code, $attrstr) {
	$attribs = new Attributes($attrstr);
	$attr = $attribs->getAttribs('html');
	if ($scriptFormat == '')  // (:script ...:) => get script type from attributes
		$scriptFormat = $attr['type'];
	if ($code == '') 
		$so = ScriptObjectFactory::createScriptObjectFromFile($pagename, $scriptFormat, $attr['file']);
	else {
		$code = str_replace("\\'", "'", $code);
		$code = str_replace("\\\"", '"', $code);
		$so = ScriptObjectFactory::createScriptObjectFromCode($pagename, $scriptFormat, $code);
	}
	if ($so !== false) {
		$mo = $so->convert('png', $attr);
	//	M2MMarkReference($pagename, $mo->fname, $mo->type(), "generated $scriptFormat image");
		if (is_object($mo))
			return Keep($mo->getHTML($attr));
	}
	return '';
}