Table of Contents是一个可以根据文章中的HTML的H1~H6直接生成文章目录的一个模块,但对于中文支持不是很好.
这个模块是由2 个filter组成,一个名为headinganchors是用来给文章中的H1到H6加上ID.另一个名为tableofcontents是用来生成右边的列表.
模块的安装与启用,很简单,复制到modules目录之后,启用就行了,
使用要点:
- Headings to Anchors必须要在Table of Contents之前
- 如果和HTML filter一起使用时,要加入允许的HTML标记(div,h1~h6)
想要比较好的支持中文,要对headinganchors.module文件中生成ID标记进行修改.
if (preg_match('/id="(.*?)"/i', $attributes, $existing_id)) {
$anchor = $existing_id[1];
// remove the existing id, it will be added back later
$attributes = preg_replace('/\s*id="(.*?)"\s*/i', '', $attributes);
// if no id found, create one
}
else {
// sanitize ID text & remove leading digits (invalid on IDs)
$anchor = preg_replace("/&/", "", strip_tags($matches[3][$count]));
$anchor = preg_replace("/[^A-Za-z0-9]/", "", $anchor);
$anchor = preg_replace("/^[0-9]+/", "", $anchor);
}
找到这一段之后将else的语句改成这样
if (preg_match('/id="(.*?)"/i', $attributes, $existing_id)) {
$anchor = $existing_id[1];
// remove the existing id, it will be added back later
$attributes = preg_replace('/\s*id="(.*?)"\s*/i', '', $attributes);
// if no id found, create one
}
else {
// sanitize ID text & remove leading digits (invalid on IDs)
$anchor ="tocid".$count;//直接用tocid+数字替代,因为中文会出错
}
目录是一个可以根据文章中的的HTML的H1基因〜 H6直接生成文章目录的一个模块,但对于中文支持不是很好。这个模块是由2个过滤器组成,一个名为headinganchors是用来给文章中的H1基因到H6加上编号。另一个名为tableofcontents是用来生成右边的列表。
>>
最新评论