本文整理汇总了PHP中TexyHtml类的典型用法代码示例。如果您正苦于以下问题:PHP TexyHtml类的具体用法?PHP TexyHtml怎么用?PHP TexyHtml使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了TexyHtml类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: blockHandler
/**
* User handler for code block
*
* @param TexyHandlerInvocation handler invocation
* @param string block type
* @param string text to highlight
* @param string language
* @param TexyModifier modifier
* @return TexyHtml
*/
function blockHandler($invocation, $blocktype, $content, $lang, $modifier)
{
if ($blocktype !== 'block/code') {
return $invocation->proceed();
}
$lang = strtoupper($lang);
if ($lang == 'JAVASCRIPT') {
$lang = 'JS';
}
$fshl = new fshlParser('HTML_UTF8', P_TAB_INDENT);
if (!$fshl->isLanguage($lang)) {
return $invocation->proceed();
}
$texy = $invocation->getTexy();
$content = Texy::outdent($content);
$content = $fshl->highlightString($lang, $content);
$content = $texy->protect($content, Texy::CONTENT_BLOCK);
$elPre = TexyHtml::el('pre');
if ($modifier) {
$modifier->decorate($texy, $elPre);
}
$elPre->attrs['class'] = strtolower($lang);
$elCode = $elPre->create('code', $content);
return $elPre;
}
示例2: solve
/**
* Finish invocation.
*
* @param TexyHandlerInvocation handler invocation
* @param string
* @param TexyModifier
*
* @return TexyHtml
*/
public function solve($invocation, $type, $modifier)
{
$el = TexyHtml::el('hr');
$modifier->decorate($invocation->texy, $el);
$class = $this->classes[$type[0]];
if ($class && !isset($modifier->classes[$class])) {
$el->attrs['class'][] = $class;
}
return $el;
}
示例3: pattern
/**
* Callback for:.
*
* > They went in single file, running like hounds on a strong scent,
* and an eager light was in their eyes. Nearly due west the broad
* swath of the marching Orcs tramped its ugly slot; the sweet grass
* of Rohan had been bruised and blackened as they passed.
* >:http://www.mycom.com/tolkien/twotowers.html
*
* @param TexyBlockParser
* @param array regexp matches
* @param string pattern name
* @return TexyHtml|string|FALSE
*/
public function pattern($parser, $matches)
{
list(, $mMod, $mPrefix, $mContent) = $matches;
// [1] => .(title)[class]{style}<>
// [2] => spaces |
// [3] => ... / LINK
$tx = $this->texy;
$el = TexyHtml::el('blockquote');
$mod = new TexyModifier($mMod);
$mod->decorate($tx, $el);
$content = '';
$spaces = '';
do {
if ($mPrefix === ':') {
$mod->cite = $tx->blockQuoteModule->citeLink($mContent);
$content .= "\n";
} else {
if ($spaces === '') $spaces = max(1, strlen($mPrefix));
$content .= $mContent . "\n";
}
if (!$parser->next("#^>(?:|(\\ {1,$spaces}|:)(.*))()$#mA", $matches)) break;
/*
if ($mPrefix === '>') {
$content .= $mPrefix . $mContent . "\n";
} elseif ($mPrefix === ':') {
$mod->cite = $tx->blockQuoteModule->citeLink($mContent);
$content .= "\n";
} else {
if ($spaces === '') $spaces = max(1, strlen($mPrefix));
$content .= $mContent . "\n";
}
if (!$parser->next("#^\\>(?:(\\>|\\ {1,$spaces}|:)(.*))?()$#mA", $matches)) break;
*/
list(, $mPrefix, $mContent) = $matches;
} while (TRUE);
$el->attrs['cite'] = $mod->cite;
$el->parseBlock($tx, $content, $parser->isIndented());
// no content?
if (!$el->count()) return FALSE;
// event listener
$tx->invokeHandlers('afterBlockquote', array($parser, $el, $mod));
return $el;
}
示例4: codeBlockHandler
/**
* Pattern handler for PHP & JavaScript block syntaxes
*
* @param TexyBlockParser
* @param array regexp matches
* @param string pattern name
* @return TexyHtml|string|FALSE
*/
function codeBlockHandler($parser, $matches, $name)
{
list($content) = $matches;
$lang = $name === 'phpBlockSyntax' ? 'PHP' : 'HTML';
$fshl = new fshlParser('HTML_UTF8', P_TAB_INDENT);
$texy = $parser->getTexy();
$content = $fshl->highlightString($lang, $content);
$content = $texy->protect($content, Texy::CONTENT_BLOCK);
$elPre = TexyHtml::el('pre');
$elPre->attrs['class'] = strtolower($lang);
$elCode = $elPre->create('code', $content);
return $elPre;
}
示例5: solve
/**
* Finish invocation.
*
* @param TexyHandlerInvocation handler invocation
* @param string
* @param TexyModifier|NULL
* @return TexyHtml|FALSE
*/
public function solve($invocation, $content, $mod)
{
$tx = $this->texy;
// find hard linebreaks
if ($tx->mergeLines) {
// ....
// ... => \r means break line
$content = TexyRegexp::replace($content, '#\\n +(?=\\S)#', "\r");
} else {
$content = TexyRegexp::replace($content, '#\\n#', "\r");
}
$el = TexyHtml::el('p');
$el->parseLine($tx, $content);
$content = $el->getText();
// string
// check content type
// block contains block tag
if (strpos($content, Texy::CONTENT_BLOCK) !== FALSE) {
$el->setName(NULL);
// ignores modifier!
// block contains text (protected)
} elseif (strpos($content, Texy::CONTENT_TEXTUAL) !== FALSE) {
// leave element p
// block contains text
} elseif (preg_match('#[^\\s' . TexyPatterns::MARK . ']#u', $content)) {
// leave element p
// block contains only replaced element
} elseif (strpos($content, Texy::CONTENT_REPLACED) !== FALSE) {
$el->setName($tx->nontextParagraph);
// block contains only markup tags or spaces or nothing
} else {
// if {ignoreEmptyStuff} return FALSE;
if (!$mod) {
$el->setName(NULL);
}
}
if ($el->getName()) {
// apply modifier
if ($mod) {
$mod->decorate($tx, $el);
}
// add <br />
if (strpos($content, "\r") !== FALSE) {
$key = $tx->protect('<br />', Texy::CONTENT_REPLACED);
$content = str_replace("\r", $key, $content);
}
}
$content = strtr($content, "\r\n", ' ');
$el->setText($content);
return $el;
}
示例6: userBlockHandler
/**
* Pattern handler for block syntaxes
*
* @param TexyBlockParser
* @param array regexp matches
* @param string pattern name (myBlockSyntax1)
* @return TexyHtml|string|FALSE
*/
function userBlockHandler($parser, $matches, $name)
{
list(, $mTag, $mText) = $matches;
$texy = $parser->getTexy();
// create element
if ($mTag === 'perex') {
$el = TexyHtml::el('div');
$el->attrs['class'][] = 'perex';
} else {
$el = TexyHtml::el($mTag);
}
// create content
$el->parseLine($texy, $mText);
return $el;
}
示例7: figureHandler
/**
* @param TexyHandlerInvocation handler invocation
* @param TexyImage
* @param TexyLink
* @param string
* @param TexyModifier
* @return TexyHtml|string|FALSE
*/
function figureHandler($invocation, $image, $link, $content, $modifier)
{
// finish invocation by default way
$el = $invocation->proceed();
// change div -> dl
$el->setName('dl');
// change p -> dd
$el[1]->setName('dd');
// wrap img into dt
$img = $el[0];
unset($el[0]);
$dt = TexyHtml::el('dt');
$dt->add($img);
$el->insert(0, $dt);
return $el;
}
示例8: wiki_texy_InlineHandler
function wiki_texy_InlineHandler($parser, $matches, $name)
{
list(, $mContent, $mMod) = $matches;
$texy = $parser->getTexy();
$tag = 'a';
$el = TexyHtml::el($tag);
$mod = new TexyModifier($mMod);
$mod->decorate($texy, $el);
if ($name == 'wikilink') {
$el->attrs['href'] = '?page=' . urlencode($mContent);
} else {
$el->attrs['href'] = $mContent;
}
$el->attrs['class'] = $name;
$el->setText($mContent);
$parser->again = TRUE;
return $el;
}
示例9: newReferenceHandler
/**
* User handler for unknown reference
*
* @param TexyHandlerInvocation handler invocation
* @param string [refName]
* @return TexyHtml|string
*/
function newReferenceHandler($parser, $refName)
{
$names = array('Me', 'Punkrats', 'Servats', 'Bonifats');
if (!isset($names[$refName])) {
return FALSE;
}
// it's not my job
$name = $names[$refName];
$el = TexyHtml::el('a');
$el->attrs['href'] = '#comm-' . $refName;
// set link destination
$el->attrs['class'][] = 'comment';
// set class name
$el->attrs['rel'] = 'nofollow';
// enable rel="nofollow"
$el->setText("[{$refName}] {$name}:");
// set link label (with Texy formatting)
return $el;
}
示例10: solve
/**
* Finish invocation.
*
* @param TexyHandlerInvocation handler invocation
* @param string
* @param string
* @return TexyHtml|FALSE
*/
public function solve($invocation, $emoticon, $raw)
{
$tx = $this->texy;
$file = $this->icons[$emoticon];
$el = TexyHtml::el('img');
$el->attrs['src'] = Texy::prependRoot($file, $this->root === NULL ? $tx->imageModule->root : $this->root);
$el->attrs['alt'] = $raw;
$el->attrs['class'][] = $this->class;
// file path
$file = rtrim($this->fileRoot === NULL ? $tx->imageModule->fileRoot : $this->fileRoot, '/\\') . '/' . $file;
if (@is_file($file)) {
// intentionally @
$size = @getImageSize($file);
// intentionally @
if (is_array($size)) {
$el->attrs['width'] = $size[0];
$el->attrs['height'] = $size[1];
}
}
$tx->summary['images'][] = $el->attrs['src'];
return $el;
}
示例11: blockHandler
/**
* User handler for code block.
*
* @param TexyHandlerInvocation handler invocation
* @param string block type
* @param string text to highlight
* @param string language
* @param TexyModifier modifier
* @return TexyHtml
*/
public static function blockHandler($invocation, $blocktype, $content, $lang, $modifier)
{
if (preg_match('#^block/(php|neon|javascript|js|css|html|htmlcb|latte)$#', $blocktype)) {
list(, $lang) = explode('/', $blocktype);
} elseif ($blocktype !== 'block/code') {
return $invocation->proceed();
}
$lang = strtolower($lang);
if ($lang === 'htmlcb' || $lang === 'latte') {
$lang = 'html';
} elseif ($lang === 'javascript') {
$lang = 'js';
}
if ($lang === 'html') {
$langClass = 'FSHL\\Lexer\\LatteHtml';
} elseif ($lang === 'js') {
$langClass = 'FSHL\\Lexer\\LatteJavascript';
} else {
$langClass = 'FSHL\\Lexer\\' . ucfirst($lang);
}
$texy = $invocation->getTexy();
$content = Texy::outdent($content);
if (class_exists($langClass)) {
$fshl = new FSHL\Highlighter(new FSHL\Output\Html(), FSHL\Highlighter::OPTION_TAB_INDENT);
$content = $fshl->highlight($content, new $langClass());
} else {
$content = htmlSpecialChars($content);
}
$content = $texy->protect($content, Texy::CONTENT_BLOCK);
$elPre = TexyHtml::el('pre');
if ($modifier) {
$modifier->decorate($texy, $elPre);
}
$elPre->attrs['class'] = 'src-' . strtolower($lang);
$elCode = $elPre->create('code', $content);
return $elPre;
}
示例12: blockHandler
/**
* User handler for code block
*
* @param TexyHandlerInvocation handler invocation
* @param string block type
* @param string text to highlight
* @param string language
* @param TexyModifier modifier
* @return TexyHtml
*/
function blockHandler($invocation, $blocktype, $content, $lang, $modifier)
{
if ($blocktype !== 'block/code') {
return $invocation->proceed();
}
$texy = $invocation->getTexy();
global $geshiPath;
if ($lang == 'html') {
$lang = 'html4strict';
}
$content = Texy::outdent($content);
$geshi = new GeSHi($content, $lang, $geshiPath . 'geshi/');
// GeSHi could not find the language
if ($geshi->error) {
return $invocation->proceed();
}
// do syntax-highlighting
$geshi->set_encoding('UTF-8');
$geshi->set_header_type(GESHI_HEADER_PRE);
$geshi->enable_classes();
$geshi->set_overall_style('color: #000066; border: 1px solid #d0d0d0; background-color: #f0f0f0;', true);
$geshi->set_line_style('font: normal normal 95% \'Courier New\', Courier, monospace; color: #003030;', 'font-weight: bold; color: #006060;', true);
$geshi->set_code_style('color: #000020;', 'color: #000020;');
$geshi->set_link_styles(GESHI_LINK, 'color: #000060;');
$geshi->set_link_styles(GESHI_HOVER, 'background-color: #f0f000;');
// save generated stylesheet
$texy->styleSheet .= $geshi->get_stylesheet();
$content = $geshi->parse_code();
// check buggy GESHI, it sometimes produce not UTF-8 valid code :-((
$content = iconv('UTF-8', 'UTF-8//IGNORE', $content);
// protect output is in HTML
$content = $texy->protect($content, Texy::CONTENT_BLOCK);
$el = TexyHtml::el();
$el->setText($content);
return $el;
}
示例13: solve
/**
* Finish invocation.
*
* @param TexyHandlerInvocation handler invocation
* @param TexyLink
* @param TexyHtml|string
* @return TexyHtml|string
*/
public function solve($invocation, $link, $content = NULL)
{
if ($link->URL == NULL) {
return $content;
}
$tx = $this->texy;
$el = TexyHtml::el('a');
if (empty($link->modifier)) {
$nofollow = $popup = FALSE;
} else {
$nofollow = isset($link->modifier->classes['nofollow']);
$popup = isset($link->modifier->classes['popup']);
unset($link->modifier->classes['nofollow'], $link->modifier->classes['popup']);
$el->attrs['href'] = NULL;
// trick - move to front
$link->modifier->decorate($tx, $el);
}
if ($link->type === TexyLink::IMAGE) {
// image
$el->attrs['href'] = Texy::prependRoot($link->URL, $tx->imageModule->linkedRoot);
if ($this->imageClass) {
$el->attrs['class'][] = $this->imageClass;
} else {
$el->attrs['onclick'] = $this->imageOnClick;
}
} else {
$el->attrs['href'] = Texy::prependRoot($link->URL, $this->root);
// rel="nofollow"
if ($nofollow || $this->forceNoFollow && strpos($el->attrs['href'], '//') !== FALSE) {
$el->attrs['rel'] = 'nofollow';
}
}
// popup on click
if ($popup) {
$el->attrs['onclick'] = $this->popupOnClick;
}
if ($content !== NULL) {
$el->add($content);
}
$tx->summary['links'][] = $el->attrs['href'];
return $el;
}
示例14: patternItem
/**
* Callback for single list item.
*
* @param TexyBlockParser
* @param string bullet type
* @param string left space
* @param string html tag
* @return TexyHtml|FALSE
*/
public function patternItem($parser, $bullet, $indented, $tag)
{
$tx = $this->texy;
$spacesBase = $indented ? '\\ {1,}' : '';
$patternItem = "#^\n?({$spacesBase}){$bullet}\\ *(\\S.*)?" . TEXY_MODIFIER_H . "?()\$#mAUu";
// first line with bullet
$matches = NULL;
if (!$parser->next($patternItem, $matches)) {
return FALSE;
}
list(, $mIndent, $mContent, $mMod) = $matches;
// [1] => indent
// [2] => ...
// [3] => .(title)[class]{style}<>
$elItem = TexyHtml::el($tag);
$mod = new TexyModifier($mMod);
$mod->decorate($tx, $elItem);
// next lines
$spaces = '';
$content = ' ' . $mContent;
// trick
while ($parser->next('#^(\\n*)' . $mIndent . '(\\ {1,' . $spaces . '})(.*)()$#Am', $matches)) {
list(, $mBlank, $mSpaces, $mContent) = $matches;
// [1] => blank line?
// [2] => spaces
// [3] => ...
if ($spaces === '') {
$spaces = strlen($mSpaces);
}
$content .= "\n" . $mBlank . $mContent;
}
// parse content
$elItem->parseBlock($tx, $content, TRUE);
if (isset($elItem[0]) && $elItem[0] instanceof TexyHtml) {
$elItem[0]->setName(NULL);
}
return $elItem;
}
示例15: texyBlockHandler
static function texyBlockHandler($invocation, $blocktype, $content, $lang, $modifier)
{
if ($blocktype !== 'block/code') {
return $invocation->proceed();
}
$texy = $invocation->getTexy();
if ($lang == 'html') {
$lang = 'html4strict';
} elseif ($lang == 'yaml') {
$lang = 'python';
}
$content = Texy::outdent($content);
$geshi = new GeSHi($content, $lang);
// GeSHi could not find the language
if ($geshi->error) {
return $invocation->proceed();
}
// do syntax-highlighting
$geshi->set_encoding('UTF-8');
$geshi->set_header_type(GESHI_HEADER_PRE);
$geshi->enable_classes();
$geshi->enable_keyword_links(false);
$geshi->set_overall_style('');
$geshi->set_overall_class('code');
// save generated stylesheet
$content = $geshi->parse_code();
// check buggy GESHI, it sometimes produce not UTF-8 valid code :-((
$content = iconv('UTF-8', 'UTF-8//IGNORE', $content);
// protect output is in HTML
$content = $texy->protect($content, Texy::CONTENT_BLOCK);
$el = TexyHtml::el();
$el->setText($content);
return $el;
}