📄 textile2.php
字号:
}
// -------------------------------------------------------------
function getRefs($text)
{
return preg_replace_callback("/(?<=^|\s)\[(.+)\]((?:http:\/\/|\/)\S+)(?=\s|$)/U",
"refs",$text);
}
// -------------------------------------------------------------
function refs($m)
{
list(,$flag,$url) = $m;
$GLOBALS['urlrefs'][$flag] = $url;
return '';
}
// -------------------------------------------------------------
function checkRefs($text)
{
global $urlrefs;
return (isset($urlrefs[$text])) ? $urlrefs[$text] : $text;
}
// -------------------------------------------------------------
function image($text)
{
global $textile_c;
return preg_replace_callback("/
\! # opening
(\<|\=|\>)? # optional alignment atts
($textile_c) # optional style,class atts
(?:\. )? # optional dot-space
([^\s(!]+) # presume this is the src
\s? # optional space
(?:\(([^\)]+)\))? # optional title
\! # closing
(?::(\S+))? # optional href
(?=\s|$) # lookahead: space or end of string
/Ux","fImage",$text);
}
// -------------------------------------------------------------
function fImage($m)
{
list(,$algn,$atts,$url) = $m;
$atts = pba($atts);
$atts.= ($algn!='') ? ' align="'.iAlign($algn).'"' : '';
$atts.= (isset($m[4])) ? ' title="'.$m[4].'"' : '';
$size = @getimagesize($url);
if($size) $atts.= " $size[3]";
$href = (isset($m[5])) ? checkRefs($m[5]) : '';
$url = checkRefs($url);
$out = '';
$out.= ($href!='') ? '<a href="'.$href.'">' : '';
$out.= '<img src="'.$url.'"'.$atts.' />';
$out.= ($href!='') ? '</a>' : '';
return $out;
}
// -------------------------------------------------------------
function code($text)
{
global $pnct;
return preg_replace_callback("/
(?:^|(?<=[\s\(])|([[{])) # 1 open bracket?
@ # opening
(?:\|(\w+)\|)? # 2 language
(.+) # 3 code
@ # closing
(?:$|([\]}])|
(?=[[:punct:]]{1,2}|
\s)) # 4 closing bracket?
/Ux","fCode",$text);
}
// -------------------------------------------------------------
function fCode($m)
{
list(,$before,$lang,$code,$after) = $m;
$lang = ($lang!='') ? ' language="'.$lang.'"' : '';
return $before.'<code'.$lang.'>'.detextile($code).'</code>'.$after;
}
// -------------------------------------------------------------
function shelve($val)
{
$GLOBALS['shelf'][] = $val;
return ' <'.count($GLOBALS['shelf']).'>';
}
// -------------------------------------------------------------
function retrieve($text)
{
global $shelf;
$i = 0;
if(is_array($shelf)) {
foreach($shelf as $r){
$i++;
$text = str_replace("<$i>",$r,$text);
}
}
return $text;
}
// -------------------------------------------------------------
function incomingEntities($text)
{
/* turn any incoming ampersands into a dummy character for now.
This uses a negative lookahead for alphanumerics followed by a semicolon,
implying an incoming html entity, to be skipped */
return preg_replace("/&(?![a-z]+;|#[0-9]+;)/i","x%x%",$text);
}
// -------------------------------------------------------------
function encodeEntities($text)
{
/* Convert high and low ascii to entities. If multibyte string functions are
available (on by default in php 4.3+), we convert using unicode mapping as
defined in the function encode_high(). If not, we use php's nasty
built-in htmlentities() */
return (function_exists('mb_encode_numericentity'))
? encode_high($text)
: htmlentities($text,ENT_NOQUOTES,"utf-8");
}
// -------------------------------------------------------------
function fixEntities($text)
{
/* de-entify any remaining angle brackets or ampersands */
return str_replace(array(">", "<", "&"),
array(">", "<", "&"), $text);
}
// -------------------------------------------------------------
function cleanWhiteSpace($text)
{
$out = str_replace(array("\r\n","\t"), array("\n",''), $text);
$out = preg_replace("/\n{3,}/","\n\n",$out);
$out = preg_replace("/\n *\n/","\n\n",$out);
$out = preg_replace('/"$/',"\" ", $out);
return $out;
}
// -------------------------------------------------------------
function noTextile($text)
{
return preg_replace('/(^|\s)==(.*)==(\s|$)?/msU',
'$1<notextile>$2</notextile>$3',$text);
}
// -------------------------------------------------------------
function superscript($text)
{
return preg_replace('/\^(.*)\^/mU','<sup>$1</sup>',$text);
}
// -------------------------------------------------------------
function footnoteRef($text)
{
return preg_replace('/\b\[([0-9]+)\](\s)?/U',
'<sup><a href="#fn$1">$1</a></sup>$2',$text);
}
// -------------------------------------------------------------
function glyphs($text)
{
// fix: hackish
$text = preg_replace('/"\z/',"\" ", $text);
$glyph_search = array(
'/([^\s[{(>])?\'(?(1)|(?=\s|s\b|[[:punct:]]))/', // single closing
'/\'/', // single opening
'/([^\s[{(>])?"(?(1)|(?=\s|[[:punct:]]))/', // double closing
'/"/', // double opening
'/\b( )?\.{3}/', // ellipsis
'/\b([A-Z][A-Z0-9]{2,})\b(?:[(]([^)]*)[)])/', // 3+ uppercase acronym
'/(^|[^"][>\s])([A-Z][A-Z0-9 ]{2,})([^<a-z0-9]|$)/', // 3+ uppercase caps
'/\s?--\s?/', // em dash
'/\s-\s/', // en dash
'/(\d+) ?x ?(\d+)/', // dimension sign
'/\b ?[([]TM[])]/i', // trademark
'/\b ?[([]R[])]/i', // registered
'/\b ?[([]C[])]/i'); // copyright
$glyph_replace = array(
'$1’$2', // single closing
'‘', // single opening
'$1”', // double closing
'“', // double opening
'$1…', // ellipsis
'<acronym title="$2">$1</acronym>', // 3+ uppercase acronym
'$1<span class="caps">$2</span>$3', // 3+ uppercase caps
'—', // em dash
' – ', // en dash
'$1×$2', // dimension sign
'™', // trademark
'®', // registered
'©'); // copyright
$codepre = false;
/* if no html, do a simple search and replace... */
if (!preg_match("/<.*>/",$text)) {
$text = preg_replace($glyph_search,$glyph_replace,$text);
return $text;
} else {
$text = preg_split("/(<.*>)/U",$text,-1,PREG_SPLIT_DELIM_CAPTURE);
foreach($text as $line) {
$offtags = ('code|pre|kbd|notextile');
/* matches are off if we're between <code>, <pre> etc. */
if (preg_match('/<('.$offtags.')>/i',$line)) $codepre = true;
if (preg_match('/<\/('.$offtags.')>/i',$line)) $codepre = false;
if (!preg_match("/<.*>/",$line) && $codepre == false) {
$line = preg_replace($glyph_search,$glyph_replace,$line);
}
/* do htmlspecial if between <code> */
if ($codepre == true) {
$line = htmlspecialchars($line,ENT_NOQUOTES,"UTF-8");
$line = preg_replace('/<(\/?'.$offtags.')>/',"<$1>",$line);
}
$glyph_out[] = $line;
}
return join('',$glyph_out);
}
}
// -------------------------------------------------------------
function iAlign($in)
{
$vals = array(
'<'=>'left',
'='=>'center',
'>'=>'right');
return (isset($vals[$in])) ? $vals[$in] : '';
}
// -------------------------------------------------------------
function hAlign($in)
{
$vals = array(
'<'=>'left',
'='=>'center',
'>'=>'right',
'<>'=>'justify');
return (isset($vals[$in])) ? $vals[$in] : '';
}
// -------------------------------------------------------------
function vAlign($in)
{
$vals = array(
'^'=>'top',
'-'=>'middle',
'~'=>'bottom');
return (isset($vals[$in])) ? $vals[$in] : '';
}
// -------------------------------------------------------------
function encode_high($text,$charset="UTF-8")
{
$cmap = cmap();
return mb_encode_numericentity($text, $cmap, $charset);
}
// -------------------------------------------------------------
function decode_high($text,$charset="UTF-8")
{
$cmap = cmap();
return mb_decode_numericentity($text, $cmap, $charset);
}
// -------------------------------------------------------------
function cmap()
{
$f = 0xffff;
$cmap = array(
160, 255, 0, $f,
402, 402, 0, $f,
913, 929, 0, $f,
931, 937, 0, $f,
945, 969, 0, $f,
977, 978, 0, $f,
982, 982, 0, $f,
8226, 8226, 0, $f,
8230, 8230, 0, $f,
8242, 8243, 0, $f,
8254, 8254, 0, $f,
8260, 8260, 0, $f,
8465, 8465, 0, $f,
8472, 8472, 0, $f,
8476, 8476, 0, $f,
8482, 8482, 0, $f,
8501, 8501, 0, $f,
8592, 8596, 0, $f,
8629, 8629, 0, $f,
8656, 8660, 0, $f,
8704, 8704, 0, $f,
8706, 8707, 0, $f,
8709, 8709, 0, $f,
8711, 8713, 0, $f,
8715, 8715, 0, $f,
8719, 8719, 0, $f,
8721, 8722, 0, $f,
8727, 8727, 0, $f,
8730, 8730, 0, $f,
8733, 8734, 0, $f,
8736, 8736, 0, $f,
8743, 8747, 0, $f,
8756, 8756, 0, $f,
8764, 8764, 0, $f,
8773, 8773, 0, $f,
8776, 8776, 0, $f,
8800, 8801, 0, $f,
8804, 8805, 0, $f,
8834, 8836, 0, $f,
8838, 8839, 0, $f,
8853, 8853, 0, $f,
8855, 8855, 0, $f,
8869, 8869, 0, $f,
8901, 8901, 0, $f,
8968, 8971, 0, $f,
9001, 9002, 0, $f,
9674, 9674, 0, $f,
9824, 9824, 0, $f,
9827, 9827, 0, $f,
9829, 9830, 0, $f,
338, 339, 0, $f,
352, 353, 0, $f,
376, 376, 0, $f,
710, 710, 0, $f,
732, 732, 0, $f,
8194, 8195, 0, $f,
8201, 8201, 0, $f,
8204, 8207, 0, $f,
8211, 8212, 0, $f,
8216, 8218, 0, $f,
8218, 8218, 0, $f,
8220, 8222, 0, $f,
8224, 8225, 0, $f,
8240, 8240, 0, $f,
8249, 8250, 0, $f,
8364, 8364, 0, $f);
return $cmap;
}
// -------------------------------------------------------------
function textile_popup_help($name,$helpvar,$windowW,$windowH) {
return ' <a target="_blank" href="http://www.textpattern.com/help/?item='.$helpvar.'" onclick="window.open(this.href, \'popupwindow\', \'width='.$windowW.',height='.$windowH.',scrollbars,resizable\'); return false;">'.$name.'</a><br />';
return $out;
}
function txtgps($thing)
{
if (isset($_POST[$thing])){
if (get_magic_quotes_gpc()==1){
return stripslashes($_POST[$thing]);
} else {
return $_POST[$thing];
}
} else {
return '';
}
}
// WordPress users. If you want to change what is textiled, do so here!
// Default filters we don't want because of Textile 2
remove_filter('the_content', 'wpautop');
remove_filter('the_excerpt', 'wpautop');
remove_filter('comment_text', 'wpautop');
remove_filter('the_content', 'wptexturize');
remove_filter('the_excerpt', 'wptexturize');
remove_filter('comment_text', 'wptexturize');
add_filter('the_content', 'textile', 6);
add_filter('the_excerpt', 'textile', 6);
add_filter('comment_text', 'textile', 6);
?>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -