public static function DisplayAsHtml($strContent) { // Let's get started $strResult = null; // Normalize all linebreaks and tabs $strContent = str_replace("\r\n", "\n", $strContent); $strContent = str_replace("\t", " ", $strContent); while ($strContent) { // See if we are declaring a special block $strMatches = array(); // Any Blank Lines get processed as such if (QString::FirstCharacter($strContent) == "\n") { $strContent = substr($strContent, 1); $strResult .= "<br/>\n"; // Any Blocks matched by the PatternBlock regexp should be processed as a block } else { if (preg_match(self::PatternBlock, $strContent, $strMatches) && count($strMatches) >= 3 && ($strProcessorResult = QTextStyleBlock::Process($strMatches, $strContent)) !== false) { $strResult .= $strProcessorResult; // Any ListBlocks matched by the PatternListBlock regexp should be processed as a listblock (uses the same QTSBP::Process method) } else { if (preg_match(self::PatternListBlock, $strContent, $strMatches) && count($strMatches) >= 3 && ($strProcessorResult = QTextStyleBlock::Process($strMatches, $strContent)) !== false) { $strResult .= $strProcessorResult; // Finally, anything that doesn't match any of the above will be processed as "Default" } else { $strContent = QTextStyle::KeyDefault . '. ' . $strContent; } } } } // Return the resulting HTML return $strResult; }
protected static function ListBlockItem($strListItemContent, $strBlockIdentifier) { // Build pattern to identify sublist $intBlockIdentifierLength = strlen($strBlockIdentifier); $strPattern = sprintf('/\\n(%s|%s) /', str_repeat('\\#', $intBlockIdentifierLength + 1), str_repeat('\\*', $intBlockIdentifierLength + 1)); $strToReturn = null; preg_match($strPattern, $strListItemContent, $strMatches); if (count($strMatches) >= 1) { $intPosition = strpos($strListItemContent, $strMatches[0]); $strToReturn .= QTextStyleInline::Process(substr($strListItemContent, 0, $intPosition)); $strListItemContent = substr($strListItemContent, $intPosition + strlen($strMatches[0])); $strToReturn .= QTextStyleBlock::ListBlockRecursion($strListItemContent, $strMatches[1]); } else { $strToReturn .= QTextStyleInline::Process($strListItemContent); } return $strToReturn; }