在 TextPattern 4 中使用Markdown
TextPattern 是一个十分不错的博客工具,也是我一直使用的工具,与另一个很好的博客工具WordPress比起来,TextPattern清新许多,它所有的,都是我所要的,没有任何多余的在里面,唯一的一个缺点就是它没有提供Markdown插件(或者说它只提供了Textile支持),而我一直使用的都是Markdown,所以,还得自己整一下。
首先需要下载两个必须的文件:markdown.php 以及 smartypants.php ,它们的下载地址是:
之后修改 ./textpattern/lib/classTextile.php 为 ./textpattern/lib/classTextile.php.bak 对原 classTextile.php 作一个备份,之后将下载并解压后得到的 smartypants.php 与 markdown.php 两个文件移动到 ./textpattern/lib/ 目录中,并修改 markdown.php 为 classTextile.php。
安装之后,需要让 markdown 真正以 textile 的方法运行,我们还需要修改当前的 classTextile.php 文件:
打开 classTextile.php 后搜索 “### Textile Compatibility Mode ###” ,可以看到如下代码:
if (strcasecmp(substr(__FILE__, -16), "classTextile.php") == 0) {
# Try to include PHP SmartyPants. Should be in the same directory.
@include_once 'smartypants.php';
# Fake Textile class. It calls Markdown instead.
class Textile {
function TextileThis($text, $lite='', $encode='') {
if ($lite == '' && $encode == '') $text = Markdown($text);
if (function_exists('SmartyPants')) $text = SmartyPants($text);
return $text;
}
# Fake restricted version: restrictions are not supported for now.
function TextileRestricted($text, $lite='', $noimage='') {
return $this->TextileThis($text, $lite);
}
# Workaround to ensure compatibility with TextPattern 4.0.3.
function blockLite($text) { return $text; }
}
}修改为:
if (strcasecmp(substr(__FILE__, -16), "classTextile.php") == 0) {
# Try to include PHP SmartyPants. Should be in the same directory.
@include_once 'smartypants.php';
# Fake Textile class. It calls Markdown instead.
class Textile {
function TextileThis($text, $lite='', $encode='') {
if ($lite == '' && $encode == '') $text = Markdown($text);
if (function_exists('SmartyPants')) $text = SmartyPants($text);
return $text;
}
# Fake restricted version: restrictions are not supported for now.
#function TextileRestricted($text, $lite='', $noimage='') {
# return $this->TextileThis($text, $lite);
#}
# Workaround to ensure compatibility with TextPattern 4.0.3.
function blockLite($text) { return $text; }
function TextileRestricted( $text, $lite='', $encode='') {
return $this->TextileThis($text, $lite, $encode);
}
}
}现在已经可以直接在编辑内容时使用 Markdown 语法了,当然,这样一来,不能再使用 Textile 语法,不过有一种想法,修改函数 TextileThis() ,让 $text 通过真正的 Textile 函数处理一次再返回应该是没问题的,不过如果 Textile 与 Markdown里面有相同的标记语法但有不同的解释的话,就不成了。
评论已关闭