"Arial, 'Helvetica Neue', Helvetica, sans-serif", 'Comic Sans MS' => "'Comic Sans MS', 'Marker Felt-Thin', Arial, sans-serif", 'Courier New' => "'Courier New', Courier, 'Lucida Sans Typewriter', 'Lucida Typewriter', monospace", 'Georgia' => "Georgia, Times, 'Times New Roman', serif", 'Lucida' => "'Lucida Sans Unicode', 'Lucida Grande', sans-serif", 'Tahoma' => "Tahoma, Verdana, Segoe, sans-serif", 'Times New Roman' => "'Times New Roman', Times, Baskerville, Georgia, serif", 'Trebuchet MS' => "'Trebuchet MS', 'Lucida Grande', 'Lucida Sans Unicode', 'Lucida Sans', Tahoma, sans-serif", 'Verdana' => "Verdana, Geneva, sans-serif" ); static function render($element) { $html = $element['text']; $html = self::convertBlockquotesToTables($html); $html = self::addLineBreakAfterTags($html); $html = self::removeEmptyTags($html); $html = self::convertEmptyParagraphsToLineBreaks($html); $html = self::convertParagraphsToTables($html); $html = self::removeLastBreakLine($html); $template = '
(.*?)<\/p>/', '
$1 |
(.*?)<\/p>/', '
$2 |
<\/p>/', '
', $html);
}
static function addLineBreakAfterTags($html) {
return preg_replace('/(<\/(ul|ol|h\d)>)/', '$1
', $html);
}
static function convertBlockquotesToTables($html) {
$template = '
$1 |
(.*?)<\/blockquote>/s', $template, $html); } static function removeEmptyTags($html) { $pattern = <<<'EOD' ~ < (?: !--[^-]*(?:-(?!->)[^-]*)*-->[^<]*(*SKIP)(*F) # skip comments | ( # group 1 (span|em|strong) # tag name in group 2 [^"'>]* #'"# all that is not a quote or a closing angle bracket (?: # quoted attributes "[^\\"]*(?:\\.[^\\"]*)*+" [^"'>]* #'"# double quote | '[^\\']*(?:\\.[^\\']*)*+' [^"'>]* #'"# single quote )*+ > \s* (?: \s* # html comments | <(?1) \s* # recursion with the group 1 )*+ \2> # closing tag ) # end of the group 1 ) ~sxi EOD; return preg_replace($pattern, '', $html); } }