protected function prepare() { // convert the data to a full document and we'll remove this part later $this->data = '<?xml version="' . $this->version . '" encoding="' . $this->encoding . '"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "' . $this->dtd . '"><html><body>' . $this->data . '</body></html>'; parent::prepare(); }
$highlighter->addKeywords(array($keyword)); $highlighter->highlight(); $t->is($highlighter->export(), $expected, '->highlight() does nothing if the document is invalid XHTML'); // ******************************************** // ******************************************** $xml = ' <html> <head> <title>foobar</title> </head> <body> <p>foobar - baz, I am prety</p> </body> </html> '; $expected = '<?xml version="1.0"?> <html> <head> <title>foobar</title> </head> <body> <p><h>foobar</h> - <s>baz</s>, I am prety</p> </body> </html> '; $keyword = new sfLuceneHighlighterKeywordNamed(new sfLuceneHighlighterMarkerSprint('<h>%s</h>'), 'foobar'); $keyword2 = new sfLuceneHighlighterKeywordNamed(new sfLuceneHighlighterMarkerSprint('<s>%s</s>'), 'baz'); $highlighter = new sfLuceneHighlighterXHTML($xml); $highlighter->addKeywords(array($keyword, $keyword2)); $highlighter->highlight(); $t->is($highlighter->export(), $expected, '->highlight() handles multiple keywords');
/** * Highlights the content for $terms */ protected function doHighlight(array $terms) { $content = $this->getContext()->getResponse()->getContent(); // configure highlighter $lighter = new sfLuceneHighlighterXHTML($content); $lighter->addKeywords($terms); $this->getContext()->getResponse()->setContent($lighter->highlight()->export()); }