function handle($match, $state, $pos, &$handler) { switch ($state) { case DOKU_LEXER_ENTER: return array($state, ''); case DOKU_LEXER_UNMATCHED: $x = new T2T($match); $x->go(); $html = $x->bodyhtml; return array($state, $html); case DOKU_LEXER_EXIT: return array($state, ''); } return array($state, ''); }
// This part will load the txt2tags class, and parse the txt file with it require_once 'txt2tags.class.php'; $CON = preg_replace("/=================(.*)/", "--------------------", $CON); $CON = preg_replace("/=====(.*)=====/m", "!!!\$1", $CON); $CON = preg_replace("/====(.*)====/m", "!!!\$1", $CON); $CON = preg_replace("/===(.*)===/m", "!!\$1", $CON); $CON = preg_replace("/==(.*)==/m", "!\$1", $CON); // heading 1 = heading 2 here: $CON = preg_replace("/=(.*)=/m", "!\$1", $CON); $CON = preg_replace("/%%toc/m", "{TOC}", $CON); $stack = array(); $x = new T2T($CON); // doesn't work yet, you have to enable it in the txt2tags.class.php: $x->enableheaders = 0; //$x->snippets['**'] = "<strong>%s</strong>"; # instead of <b> $x->go(); $CON = $x->bodyhtml; // end txt2tags part // subpages while (preg_match('/(?<!\\^){include:([^}]+)}/Um', $CON, $m)) { $includePage = clear_path($m[1]); if (!strcmp($includePage, $page)) { // limited recursion protection $CON = str_replace($m[0], "'''Warning: subpage recursion!'''", $CON); } elseif (file_exists("{$PG_DIR}{$includePage}.txt")) { $CON = str_replace($m[0], file_get_contents("{$PG_DIR}{$includePage}.txt"), $CON); } else { $CON = str_replace($m[0], "'''Warning: subpage {$includePage} was not found!'''", $CON); } } plugin('subPagesLoaded');
function tc_post_process($text, $do_text = '', $do_char = '') { if ('textile2' == $do_text) { require_once 'text-control/textile2.php'; $t = new Textile(); $text = $t->process($text); } else { if ('textile1' == $do_text) { require_once 'text-control/textile1.php'; $text = textile($text); } else { if ('markdown' == $do_text) { require_once 'text-control/markdown.php'; //$text = Markdown_Parser($text); $o = new Markdown_Parser(); return $o->transform($text); } else { if ('txt2tags' == $do_text) { require_once 'text-control/txt2tags.class.php'; $x = new T2T($text); $x->go(); return $text = $x->bodyhtml; } else { if ('wpautop' == $do_text) { $text = wpautop($text); } else { if ('nl2br' == $do_text) { $text = nl2br($text); } else { if ('none' == $do_text) { $text = $text; } else { $text = wpautop($text); } } } } } } } if ('smartypants' == $do_char) { require_once 'text-control/smartypants.php'; $text = SmartyPants($text); } else { if ('wptexturize' == $do_char) { $text = wptexturize($text); } else { if ('none' == $do_char) { $text = $text; } else { $text = wptexturize($text); } } } return $text; }
public static function convert($str) { $x = new T2T($str); $x->go(); return $html = $x->bodyhtml; }
``` {(CODE)} == Rendered HTML == ''' <div class='demo'> {(HTML)} ''' </div> % </div class=body> ''' </div> EOF; # create the form page $x = new T2T($page); # change the %%mtime $x->mtime = filemtime(__FILE__); $x->go(); $html = $x->fullhtml; # for including in an HTML page: $html = $x->bodyhtml; # for a complete HTML page: $html = $x->fullhtml; $search = array('{(CODE)}', '{(HTML)}', '{(TEXT)}'); $replace = array("The result will appear here.", "The result will appear here.", ''); if (@$_POST['text']) { $text = stripmagic($_POST['text']); $z = new T2T($text); $z->go(); $fullhtml = $z->fullhtml; $onlybody = $z->bodyhtml; $replace = array(htmlspecialchars($fullhtml), $onlybody, htmlspecialchars($text)); } $html = str_replace($search, $replace, $html); echo $html;