📄 textile.php
字号:
<?php/*This is TextileA Humane Web Text GeneratorVersion 2.0 beta8 July, 2003Copyright (c) 2003, Dean Allen, www.textism.comAll rights reserved._______LICENSERedistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.* Neither the name Textile nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THEPOSSIBILITY OF SUCH DAMAGE._____________USING TEXTILEBlock modifier syntax: Header: h(1-6). Paragraphs beginning with 'hn. ' (where n is 1-6) are wrapped in header tags. Example: h1. Header... -> <h1>Header...</h1> Paragraph: p. (also applied by default) Example: p. Text -> <p>Text</p> Blockquote: bq. Example: bq. Block quotation... -> <blockquote>Block quotation...</blockquote> Blockquote with citation: bq.:http://citation.url Example: bq.:http://textism.com/ Text... -> <blockquote cite="http://textism.com">Text...</blockquote> Footnote: fn(1-100). Example: fn1. Footnote... -> <p id="fn1">Footnote...</p> Numeric list: #, ## Consecutive paragraphs beginning with # are wrapped in ordered list tags. Example: <ol><li>ordered list</li></ol> Bulleted list: *, ** Consecutive paragraphs beginning with * are wrapped in unordered list tags. Example: <ul><li>unordered list</li></ul>Phrase modifier syntax: _emphasis_ -> <em>emphasis</em> __italic__ -> <i>italic</i> *strong* -> <strong>strong</strong> **bold** -> <b>bold</b> ??citation?? -> <cite>citation</cite> -deleted text- -> <del>deleted</del> +inserted text+ -> <ins>inserted</ins> ^superscript^ -> <sup>superscript</sup> ~subscript~ -> <sub>subscript</sub> @code@ -> <code>computer code</code> %(bob)span% -> <span class="bob">span</span> ==notextile== -> leave text alone (do not format) "linktext":url -> <a href="url">linktext</a> "linktext(title)":url -> <a href="url" title="title">linktext</a> !imageurl! -> <img src="imageurl" /> !imageurl(alt text)! -> <img src="imageurl" alt="alt text" /> !imageurl!:linkurl -> <a href="linkurl"><img src="imageurl" /></a>ABC(Always Be Closing) -> <acronym title="Always Be Closing">ABC</acronym>Table syntax: Simple tables: |a|simple|table|row| |And|Another|table|row| |_. A|_. table|_. header|_.row| |A|simple|table|row| Tables with attributes: table{border:1px solid black}. {background:#ddd;color:red}. |{}| | | | Applying Attributes: Most anywhere Textile code is used, attributes such as arbitrary css style, css classes, and ids can be applied. The syntax is fairly consistent. The following characters quickly alter the alignment of block elements: < -> left align ex. p<. left-aligned para > -> right align h3>. right-aligned header 3 = -> centred h4=. centred header 4 <> -> justified p<>. justified paragraph These will change vertical alignment in table cells: ^ -> top ex. |^. top-aligned table cell| - -> middle |-. middle aligned| ~ -> bottom |~. bottom aligned cell| Plain (parentheses) inserted between block syntax and the closing dot-space indicate classes and ids: p(hector). paragraph -> <p class="hector">paragraph</p> p(#fluid). paragraph -> <p id="fluid">paragraph</p> (classes and ids can be combined) p(hector#fluid). paragraph -> <p class="hector" id="fluid">paragraph</p> Curly {brackets} insert arbitrary css style p{line-height:18px}. paragraph -> <p style="line-height:18px">paragraph</p> h3{color:red}. header 3 -> <h3 style="color:red">header 3</h3> Square [brackets] insert language attributes p[no]. paragraph -> <p lang="no">paragraph</p> %[fr]phrase% -> <span lang="fr">phrase</span> Usually Textile block element syntax requires a dot and space before the block begins, but since lists don't, they can be styled just using braces #{color:blue} one -> <ol style="color:blue"> # big <li>one</li> # list <li>big</li> <li>list</li> </ol> Using the span tag to style a phrase It goes like this, %{color:red}the fourth the fifth% -> It goes like this, <span style="color:red">the fourth the fifth</span> */ $hlgn = "(?:\<(?!>)|(?<!<)\>|\<\>|\=|[()]+)"; $vlgn = "[\-^~]"; $clas = "(?:\([^)]+\))"; $lnge = "(?:\[[^]]+\])"; $styl = "(?:\{[^}]+\})"; $cspn = "(?:\\\\\d+)"; $rspn = "(?:\/\d+)"; $a = "(?:$hlgn?$vlgn?|$vlgn?$hlgn?)"; $s = "(?:$cspn?$rspn?|$rspn?$cspn?)"; $c = "(?:$clas?$styl?$lnge?|$styl?$lnge?$clas?|$lnge?$styl?$clas?)"; $pnct = '[\!"#\$%&\'()\*\+,\-\./:;<=>\?@\[\\\]\^_`{\|}\~]'; function textile($text,$lite='') { if (get_magic_quotes_gpc()==1) $text = stripslashes($text); $text = textile_incomingEntities($text); $text = textile_encodeEntities($text); $text = textile_fixEntities($text); $text = textile_cleanWhiteSpace($text); $text = textile_getRefs($text); $text = textile_noTextile($text); $text = textile_image($text); $text = textile_links($text); $text = textile_code($text); $text = textile_span($text); $text = textile_superscript($text); $text = textile_footnoteRef($text); $text = textile_glyphs($text); $text = textile_retrieve($text); if ($lite=='') { $text = textile_lists($text); $text = textile_table($text); $text = textile_block($text); } /* clean up <notextile> */ $text = preg_replace('/<\/?notextile>/', "",$text); /* turn the temp char back to an ampersand entity */ $text = str_replace("x%x%","&",$text); $text = str_replace("<br />","<br />\n",$text); return trim($text); } // ------------------------------------------------------------- function textile_pba($in,$element="") // "parse block attributes" { global $hlgn,$vlgn,$clas,$styl,$cspn,$rspn,$a,$s,$c; $style=''; $class=''; $language=''; $colspan=''; $rowspan=''; $id=''; $atts=''; if (!empty($in)) { $matched = $in; if($element=='td'){ if(preg_match("/\\\\(\d+)/",$matched,$csp)) $colspan=$csp[1]; if(preg_match("/\/(\d+)/",$matched,$rsp)) $rowspan=$rsp[1]; if (preg_match("/($vlgn)/",$matched,$vert)) $style[] = "vertical-align:".vAlign($vert[1]).";"; } if(preg_match("/\{([^}]*)\}/",$matched,$sty)) { $style[]=$sty[1].';'; $matched = str_replace($sty[0],'',$matched); } if(preg_match("/\[([^)]+)\]/U",$matched,$lng)) { $language=$lng[1]; $matched = str_replace($lng[0],'',$matched); } if(preg_match("/\(([^()]+)\)/U",$matched,$cls)) { $class=$cls[1]; $matched = str_replace($cls[0],'',$matched); } if(preg_match("/([(]+)/",$matched,$pl)) { $style[] = "padding-left:".strlen($pl[1])."em;"; $matched = str_replace($pl[0],'',$matched); } if(preg_match("/([)]+)/",$matched,$pr)) { dump($pr); $style[] = "padding-right:".strlen($pr[1])."em;"; $matched = str_replace($pr[0],'',$matched); } if (preg_match("/($hlgn)/",$matched,$horiz)) $style[] = "text-align:".hAlign($horiz[1]).";"; if (preg_match("/^(.*)#(.*)$/",$class,$ids)) { $id = $ids[2]; $class = $ids[1]; } if($style) $atts.=' style="'.join("",$style).'"'; if($class) $atts.=' class="'.$class.'"'; if($language) $atts.=' lang="'.$language.'"'; if($id) $atts.=' id="'.$id.'"'; if($colspan) $atts.=' colspan="'.$colspan.'"'; if($rowspan) $atts.=' rowspan="'.$rowspan.'"'; return $atts; } else { return ''; } }// ------------------------------------------------------------- function textile_table($text) { global $a,$c,$s; $text = $text."\n\n"; return preg_replace_callback("/^(?:table(_?$s$a$c)\. ?\n)?^($a$c\.? ?\|.*\|)\n\n/smU", "textile_fTable",$text); }// ------------------------------------------------------------- function textile_fTable($matches) { global $s,$a,$c; $tatts = textile_pba($matches[1],'table'); foreach(preg_split("/\|$/m",$matches[2],-1,PREG_SPLIT_NO_EMPTY) as $row){ if (preg_match("/^($a$c\. )(.*)/m",$row,$rmtch)) { $ratts = pba($rmtch[1],'tr'); $row = $rmtch[2]; } else $ratts = ''; foreach(explode("|",$row) as $cell){ $ctyp = "d"; if (preg_match("/^_/",$cell)) $ctyp = "h"; if (preg_match("/^(_?$s$a$c\. )(.*)/",$cell,$cmtch)) { $catts = pba($cmtch[1],'td'); $cell = $cmtch[2]; } else $catts = ''; if(trim($cell)!='') $cells[] = "\t\t\t<t$ctyp$catts>$cell</t$ctyp>"; } $rows[] = "\t\t<tr$ratts>\n".join("\n",$cells)."\n\t\t</tr>"; unset($cells,$catts); } return "\t<table$tatts>\n".join("\n",$rows)."\n\t</table>\n\n"; } // ------------------------------------------------------------- function textile_lists($text) { global $a,$c; return preg_replace_callback("/^([#*]+$c .*)$(?![^#*])/smU","textile_fList",$text); }// ------------------------------------------------------------- function textile_fList($m) { global $a,$c; $text = explode("\n",$m[0]); foreach($text as $line){ $nextline = next($text); if(preg_match("/^([#*]+)($a$c) (.*)$/s",$line,$m)) { list(,$tl,$atts,$content) = $m; $nl = preg_replace("/^([#*]+)\s.*/","$1",$nextline); if(!isset($lists[$tl])){ $lists[$tl] = true; $atts = textile_pba($atts); $line = "\t<".textile_lT($tl)."l$atts>\n\t<li>".$content; } else { $line = "\t\t<li>".$content; } if ($nl===$tl){ $line .= "</li>"; } elseif($nl=="*" or $nl=="#") { $line .= "</li>\n\t</".lT($tl)."l>\n\t</li>"; unset($lists[$tl]); } if (!$nl) { foreach($lists as $k=>$v){ $line .= "</li>\n\t</".lT($k)."l>"; unset($lists[$k]); } } } $out[] = $line; } return join("\n",$out); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -