• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP TexyHtml类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了PHP中TexyHtml的典型用法代码示例。如果您正苦于以下问题:PHP TexyHtml类的具体用法?PHP TexyHtml怎么用?PHP TexyHtml使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了TexyHtml类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;
}
开发者ID:jiripudil,项目名称:texy,代码行数:35,代码来源:demo-fshl.php


示例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;
 }
开发者ID:BozzaCoon,项目名称:SPHERE-Framework,代码行数:19,代码来源:TexyHorizLineModule.php


示例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;
	}
开发者ID:JanTvrdik,项目名称:StaticWeb,代码行数:67,代码来源:TexyBlockQuoteModule.php


示例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;
}
开发者ID:eduardobenito10,项目名称:jenkins-php-quickstart,代码行数:21,代码来源:demo-fshl-alt.php


示例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;
 }
开发者ID:ppwalks33,项目名称:cleansure,代码行数:59,代码来源:TexyParagraphModule.php


示例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;
}
开发者ID:jiripudil,项目名称:texy,代码行数:23,代码来源:demo.php


示例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;
}
开发者ID:ppwalks33,项目名称:cleansure,代码行数:24,代码来源:demo.php


示例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;
}
开发者ID:Harvie,项目名称:haiwiki,代码行数:18,代码来源:texy.mod.php


示例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;
}
开发者ID:ppwalks33,项目名称:cleansure,代码行数:26,代码来源:demo.php


示例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;
 }
开发者ID:anagio,项目名称:woocommerce,代码行数:30,代码来源:TexyEmoticonModule.php


示例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;
 }
开发者ID:JanTvrdik,项目名称:planette,代码行数:47,代码来源:TexyFactory.php


示例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;
}
开发者ID:eduardobenito10,项目名称:jenkins-php-quickstart,代码行数:46,代码来源:demo-geshi.php


示例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;
 }
开发者ID:eduardobenito10,项目名称:jenkins-php-quickstart,代码行数:50,代码来源:TexyLinkModule.php


示例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;
 }
开发者ID:vanessaforney,项目名称:VanessasDogSitting,代码行数:47,代码来源:TexyListModule.php


示例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;
 }
开发者ID:xtgss,项目名称:qeephp2_x,代码行数:34,代码来源:abstract.php


示例16: 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 function blockHandler($invocation, $blocktype, $content, $lang, $modifier)
 {
     /** @var \Texy $texy */
     $texy = $invocation->getTexy();
     $content = \Texy::outdent($content);
     $lexerData = $this->resolveLexer($blocktype);
     $lexer = $this->getLexerInstance($lexerData['name']);
     $highlighter = $this->getHighlighter($lexerData['countLines']);
     if ($lexer !== false) {
         $content = $highlighter->highlight($content, $lexer);
     } else {
         $content = htmlspecialchars($content);
     }
     $content = $texy->protect($content, \Texy::CONTENT_BLOCK);
     $elPre = \TexyHtml::el('pre');
     if ($modifier) {
         $modifier->decorate($texy, $elPre);
     }
     $elPre->attrs['class'] = mb_strtolower($this->getLanguage($blocktype));
     $elPre->create('code', $content);
     return $elPre;
 }
开发者ID:blitzik,项目名称:CMS,代码行数:32,代码来源:TexyFactory.php


示例17: solve

 /**
  * Finish invocation.
  *
  * @param  TexyHandlerInvocation  handler invocation
  * @param  int  0..5
  * @param  string
  * @param  TexyModifier
  * @param  bool
  * @return TexyHtml
  */
 public function solve($invocation, $level, $content, $mod, $isSurrounded)
 {
     // as fixed balancing, for block/texysource & correct decorating
     $el = TexyHtml::el('h' . min(6, max(1, $level + $this->top)));
     $mod->decorate($this->texy, $el);
     $el->parseLine($this->texy, trim($content));
     $this->TOC[] = array('el' => $el, 'level' => $level, 'type' => $isSurrounded ? 'surrounded' : 'underlined');
     return $el;
 }
开发者ID:Debenson,项目名称:openwan,代码行数:19,代码来源:TexyHeadingModule.php


示例18: solve

 /**
  * Finish invocation.
  *
  * @param  TexyHandlerInvocation  handler invocation
  * @param  TexyImage
  * @param  TexyLink
  * @param  string
  * @param  TexyModifier
  * @return TexyHtml|FALSE
  */
 public function solve($invocation, TexyImage $image, $link, $content, $mod)
 {
     $tx = $this->texy;
     $hAlign = $image->modifier->hAlign;
     $image->modifier->hAlign = NULL;
     $elImg = $tx->imageModule->solve(NULL, $image, $link);
     // returns TexyHtml or false!
     if (!$elImg) {
         return FALSE;
     }
     $el = TexyHtml::el('div');
     if (!empty($image->width) && $this->widthDelta !== FALSE) {
         $el->attrs['style']['width'] = $image->width + $this->widthDelta . 'px';
     }
     $mod->decorate($tx, $el);
     $el[0] = $elImg;
     $el[1] = TexyHtml::el('p');
     $el[1]->parseLine($tx, ltrim($content));
     $class = $this->class;
     if ($hAlign) {
         $var = $hAlign . 'Class';
         // leftClass, rightClass
         if (!empty($this->{$var})) {
             $class = $this->{$var};
         } elseif (empty($tx->alignClasses[$hAlign])) {
             $el->attrs['style']['float'] = $hAlign;
         } else {
             $class .= '-' . $tx->alignClasses[$hAlign];
         }
     }
     $el->attrs['class'][] = $class;
     return $el;
 }
开发者ID:uuking,项目名称:wildflower,代码行数:43,代码来源:TexyFigureModule.php


示例19: __construct

 /**
  * Creates template.
  *
  * @param \ApiGen\Generator $generator
  */
 public function __construct(Generator $generator)
 {
     $this->generator = $generator;
     $this->config = $generator->getConfig();
     $that = $this;
     // Output in HTML5
     Nette\Utils\Html::$xhtml = false;
     // FSHL
     $fshl = new FSHL\Highlighter(new FSHL\Output\Html());
     $fshl->setLexer(new FSHL\Lexer\Php());
     // Texy
     $this->texy = new \Texy();
     $this->texy->allowedTags = array_flip($this->config->allowedHtml);
     $this->texy->allowed['list/definition'] = false;
     $this->texy->allowed['phrase/em-alt'] = false;
     $this->texy->allowed['longwords'] = false;
     $this->texy->allowed['typography'] = false;
     $this->texy->linkModule->shorten = false;
     // Highlighting <code>, <pre>
     $this->texy->addHandler('beforeParse', function ($texy, &$text, $singleLine) {
         $text = preg_replace('~<code>(.+?)</code>~', '#code#\\1#/code#', $text);
     });
     $this->texy->registerLinePattern(function ($parser, $matches, $name) use($fshl) {
         return \TexyHtml::el('code', $fshl->highlight($matches[1]));
     }, '~#code#(.+?)#/code#~', 'codeInlineSyntax');
     $this->texy->registerBlockPattern(function ($parser, $matches, $name) use($fshl) {
         if ('code' === $matches[1]) {
             $lines = array_filter(explode("\n", $matches[2]));
             if (!empty($lines)) {
                 $firstLine = array_shift($lines);
                 $indent = '';
                 $li = 0;
                 while (isset($firstLine[$li]) && preg_match('~\\s~', $firstLine[$li])) {
                     foreach ($lines as $line) {
                         if (!isset($line[$li]) || $firstLine[$li] !== $line[$li]) {
                             break 2;
                         }
                     }
                     $indent .= $firstLine[$li++];
                 }
                 if (!empty($indent)) {
                     $matches[2] = str_replace("\n" . $indent, "\n", 0 === strpos($matches[2], $indent) ? substr($matches[2], $li) : $matches[2]);
                 }
             }
             $content = $fshl->highlight($matches[2]);
         } else {
             $content = htmlspecialchars($matches[2]);
         }
         $content = $parser->getTexy()->protect($content, \Texy::CONTENT_BLOCK);
         return \TexyHtml::el('pre', $content);
     }, '~<(code|pre)>(.+?)</\\1>~s', 'codeBlockSyntax');
     // Common operations
     $this->registerHelperLoader('Nette\\Templating\\Helpers::loader');
     // PHP source highlight
     $this->registerHelper('highlightPHP', function ($source, $context) use($that, $fshl) {
         return $that->resolveLink($that->getTypeName($source), $context) ?: $fshl->highlight((string) $source);
     });
     $this->registerHelper('highlightValue', function ($definition, $context) use($that) {
         return $that->highlightPHP(preg_replace('~^(?:[ ]{4}|\\t)~m', '', $definition), $context);
     });
     // Urls
     $this->registerHelper('packageUrl', new Nette\Callback($this, 'getPackageUrl'));
     $this->registerHelper('namespaceUrl', new Nette\Callback($this, 'getNamespaceUrl'));
     $this->registerHelper('groupUrl', new Nette\Callback($this, 'getGroupUrl'));
     $this->registerHelper('classUrl', new Nette\Callback($this, 'getClassUrl'));
     $this->registerHelper('methodUrl', new Nette\Callback($this, 'getMethodUrl'));
     $this->registerHelper('propertyUrl', new Nette\Callback($this, 'getPropertyUrl'));
     $this->registerHelper('constantUrl', new Nette\Callback($this, 'getConstantUrl'));
     $this->registerHelper('functionUrl', new Nette\Callback($this, 'getFunctionUrl'));
     $this->registerHelper('elementUrl', new Nette\Callback($this, 'getElementUrl'));
     $this->registerHelper('sourceUrl', new Nette\Callback($this, 'getSourceUrl'));
     $this->registerHelper('manualUrl', new Nette\Callback($this, 'getManualUrl'));
     // Packages & namespaces
     $this->registerHelper('packageLinks', new Nette\Callback($this, 'getPackageLinks'));
     $this->registerHelper('namespaceLinks', new Nette\Callback($this, 'getNamespaceLinks'));
     $this->registerHelper('subgroupName', function ($groupName) {
         if ($pos = strrpos($groupName, '\\')) {
             return substr($groupName, $pos + 1);
         }
         return $groupName;
     });
     // Types
     $this->registerHelper('typeLinks', new Nette\Callback($this, 'getTypeLinks'));
     // Docblock descriptions
     $this->registerHelper('description', function ($annotation, $context) use($that) {
         $description = trim(strpbrk($annotation, "\n\r\t \$"));
         if ($context instanceof ReflectionParameter) {
             $description = preg_replace('~^(\\$' . $context->getName() . '(?:,\\.{3})?)(\\s+|$)~i', '\\2', $description, 1);
             $context = $context->getDeclaringFunction();
         }
         return $that->doc($description, $context);
     });
     $this->registerHelper('shortDescription', function ($element, $block = false) use($that) {
         return $that->doc($element->getShortDescription(), $element, $block);
     });
//.........这里部分代码省略.........
开发者ID:TheTypoMaster,项目名称:SPHERE-Framework,代码行数:101,代码来源:Template.php


示例20: solve

 /**
  * Finish invocation.
  *
  * @param  TexyHandlerInvocation  handler invocation
  * @param  string
  * @param  string
  * @param  TexyModifier
  * @param  TexyLink
  * @return TexyHtml
  */
 public function solve($invocation, $phrase, $content, $mod, $link)
 {
     $tx = $this->texy;
     $tag = isset($this->tags[$phrase]) ? $this->tags[$phrase] : NULL;
     if ($tag === 'a') {
         $tag = $link && $this->linksAllowed ? NULL : 'span';
     }
     if ($phrase === 'phrase/code') {
         $content = $tx->protect(Texy::escapeHtml($content), Texy::CONTENT_TEXTUAL);
     }
     if ($phrase === 'phrase/strong+em') {
         $el = TexyHtml::el($this->tags['phrase/strong']);
         $el->create($this->tags['phrase/em'], $content);
         $mod->decorate($tx, $el);
     } elseif ($tag) {
         $el = TexyHtml::el($tag)->setText($content);
         $mod->decorate($tx, $el);
         if ($tag === 'q') {
             $el->attrs['cite'] = $mod->cite;
         }
     } else {
         $el = $content;
         // trick
     }
     if ($link && $this->linksAllowed) {
         return $tx->linkModule->solve(NULL, $link, $el);
     }
     return $el;
 }
开发者ID:redhead,项目名称:texy,代码行数:39,代码来源:TexyPhraseModule.php



注:本文中的TexyHtml类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP ThePaper类代码示例发布时间:2022-05-23
下一篇:
PHP Texy类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap