📄 textile.php
字号:
// ------------------------------------------------------------- function textile_lT($in) { return preg_match("/^#+/",$in) ? 'o' : 'u'; }// ------------------------------------------------------------- function textile_block($text) { global $a,$c; $pre = false; $find = array('bq','h[1-6]','fn\d+','p'); $text = preg_replace("/(.+)\n(?![#*\s|])/", "$1<br />", $text); $text = explode("\n",$text); array_push($text," "); foreach($text as $line) { if (preg_match('/<pre>/i',$line)) { $pre = true; } foreach($find as $tag){ $line = ($pre==false) ? preg_replace_callback("/^($tag)($a$c)\.(?::(\S+))? (.*)$/", "textile_fBlock",$line) : $line; } $line = preg_replace('/^(?!\t|<\/?pre|<\/?code|$| )(.*)/',"\t<p>$1</p>",$line); $line=($pre==true) ? str_replace("<br />","\n",$line):$line; if (preg_match('/<\/pre>/i',$line)) { $pre = false; } $out[] = $line; } return join("\n",$out); } // ------------------------------------------------------------- function textile_fBlock($m) {# dump($m); list(,$tag,$atts,$cite,$content) = $m; $atts = textile_pba($atts); if(preg_match("/fn(\d+)/",$tag,$fns)){ $tag = 'p'; $atts.= ' id="fn'.$fns[1].'"'; $content = '<sup>'.$fns[1].'</sup> '.$content; } $start = "\t<$tag"; $end = "</$tag>"; if ($tag=="bq") { $cite = textile_checkRefs($cite); $cite = ($cite!='') ? ' cite="'.$cite.'"' : ''; $start = "\t<blockquote$cite>\n\t\t<p"; $end = "</p>\n\t</blockquote>"; } return "$start$atts>$content$end"; }// ------------------------------------------------------------- function textile_span($text) { global $c,$pnct; $qtags = array('\*\*','\*','\?\?','-','__','_','%','\+','~'); foreach($qtags as $f) { $text = preg_replace_callback( "/(?<=^|\s|\>|[[:punct:]]|[{(\[]) ($f) ($c) (?::(\S+))? (\w.+\w) ([[:punct:]]*) $f (?=[])}]|[[:punct:]]+|\s|$) /xmU","textile_fSpan",$text); } return $text; }// ------------------------------------------------------------- function textile_fSpan($m) {# dump($m); global $c; $qtags = array( '*' => 'b', '**' => 'strong', '??' => 'cite', '_' => 'em', '__' => 'i', '-' => 'del', '%' => 'span', '+' => 'ins', '~' => 'sub'); list(,$tag,$atts,$cite,$content,$end) = $m; $tag = $qtags[$tag]; $atts = textile_pba($atts); $atts.= ($cite!='') ? 'cite="'.$cite.'"' : ''; return "<$tag$atts>$content$end</$tag>"; }// ------------------------------------------------------------- function textile_links($text) { global $c; return preg_replace_callback('/ ([\s[{(]|[[:punct:]])? # $pre " # start ('.$c.') # $atts ([^"]+) # $text \s? (?:\(([^)]+)\)(?="))? # $title ": (\S+\b) # $url (\/)? # $slash ([^\w\/;]*) # $post (?=\s|$) /Ux',"textile_fLink",$text); }// ------------------------------------------------------------- function textile_fLink($m) { list(,$pre,$atts,$text,$title,$url,$slash,$post) = $m; $url = textile_checkRefs($url); $atts = textile_pba($atts); $atts.= ($title!='') ? ' title="'.$title.'"' : ''; $atts = ($atts!='') ? textile_shelve($atts) : ''; if ($text=='_') { $text = $url; } if (preg_match('/^http(s?):\/\//i', $url)) { $atts.=' class="external"'; } return $pre.'<a href="'.$url.$slash.'"'.$atts.'>'.$text.'</a>'.$post; }// ------------------------------------------------------------- function textile_getRefs($text) { return preg_replace_callback("/(?<=^|\s)\[(.+)\]((?:http:\/\/|\/)\S+)(?=\s|$)/U", "textile_refs",$text); } // ------------------------------------------------------------- function textile_refs($m) { list(,$flag,$url) = $m; $GLOBALS['urlrefs'][$flag] = $url; return ''; } // ------------------------------------------------------------- function textile_checkRefs($text) { global $urlrefs; return (isset($urlrefs[$text])) ? $urlrefs[$text] : $text; }// ------------------------------------------------------------- function textile_image($text) { global $c; return preg_replace_callback("/ \! # opening (\<|\=|\>)? # optional alignment atts ($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","textile_fImage",$text); }// ------------------------------------------------------------- function textile_fImage($m) { list(,$algn,$atts,$url) = $m; $atts = textile_pba($atts); $atts.= ($algn!='') ? ' align="'.textile_iAlign($algn).'"' : ''; $atts.= (isset($m[4])) ? ' title="'.$m[4].'"' : ''; $size = @getimagesize($url); if($size) $atts.= " $size[3]"; $href = (isset($m[5])) ? textile_checkRefs($m[5]) : ''; $url = textile_checkRefs($url); $out = ''; $out.= ($href!='') ? '<a href="'.$href.'">' : ''; $out.= '<img src="'.$url.'"'.$atts.' />'; $out.= ($href!='') ? '</a>' : ''; return $out; }// ------------------------------------------------------------- function textile_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","textile_fCode",$text); }// ------------------------------------------------------------- function textile_fCode($m) { list(,$before,$lang,$code,$after) = $m; $lang = ($lang!='') ? ' language="'.$lang.'"' : ''; return $before.'<code'.$lang.'>'.$code.'</code>'.$after; }// ------------------------------------------------------------- function textile_shelve($val) { $GLOBALS['shelf'][] = $val; return ' <'.count($GLOBALS['shelf']).'>'; } // ------------------------------------------------------------- function textile_retrieve($text) { global $shelf; $i = 0; if(is_array($shelf)) { foreach($shelf as $r){ $i++; $text = str_replace("<$i>",$r,$text); } } return $text; }// ------------------------------------------------------------- function textile_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-z0-9]+;)/i","x%x%",$text); }// ------------------------------------------------------------- function textile_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')) ? textile_encode_high($text) : htmlentities($text,ENT_NOQUOTES,"utf-8"); }// ------------------------------------------------------------- function textile_fixEntities($text) { /* de-entify any remaining angle brackets or ampersands */ return str_replace(array(">", "<", "&"), array(">", "<", "&"), $text); }// ------------------------------------------------------------- function textile_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 textile_noTextile($text) { return preg_replace('/(^|\s)==(.*)==(\s|$)?/msU', '$1<notextile>$2</notextile>$3',$text); }// ------------------------------------------------------------- function textile_superscript($text) { return preg_replace('/\^(.*)\^/mU','<sup>$1</sup>',$text); }// ------------------------------------------------------------- function textile_footnoteRef($text) { return preg_replace('/\b\[([0-9]+)\](\s)?/U', '<sup><a href="#fn$1">$1</a></sup>$2',$text); } // ------------------------------------------------------------- function textile_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);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -