我想为标题标签生成toc。有没有免费的节目?
答案 0 :(得分:1)
答案 1 :(得分:1)
作为@ user5858提到的htmltoc
脚本的替代方法,有hypertoc
,更强大的重写相同,再次使用Perl。像这样安装它(例如在Ubuntu Linux上):
sudo cpan -f -i HTML::GenToc
像这样使用:
hypertoc --inline --make_anchors --make_toc --overwrite file.html
答案 2 :(得分:1)
我刚刚在使用hypertoc,sed和make为HTML页面生成目录时编写了blog post。 shell脚本还使用广告名称插入Google广告。我还创建了一个navigation section,可用于导航到网站上的其他页面。
我使用的网页示例模板如下所示:
<!-- INCLUDE Navigation -->
<div id="centerDoc">
<h1>Title</h1>
<!-- Insert an ad -->
<!-- INCLUDE GoogleAd1 -->
<!-- Insert the table of contents here -->
<!--toc-->
<h2>More HTML code here</h2>
我编写了一个名为 include 的脚本,该脚本读取名为* .html.in的文件并创建了一个* .html文件。脚本看起来像这样。我还使用makefile将* .html.in文件转换为* .html文件
#!/bin/sh
#This script modifies HTML pages staticly, using something similar
# to the "#INCLUDE" C preprocessor mechanism
INCLUDE=${1?'Missing include file'}
shift
IFILE=${1?'Missing input file'}
OFILE=`echo $IFILE | sed 's/\.in$//'`
# get the name without the path
OFILENAME=`echo $OFILE | sed 's:.*/::'`
if [ "$IFILE" = "$OFILE" ]
then
echo input file $IFILE same as output file $OFILE - exit
exit
fi
ARGS="--toc_entry 'H1=1' --toc_end 'H1=/H1' --toc_entry 'H2=2' --toc_end 'H2=/H2' --toc_entry 'H3=3' --toc_end 'H3=/H3' --toc_entry 'H4=4' --toc_end 'H4=/H4' --toc_entry 'H5=5' --toc_end 'H5=/H5'"
# The string !--toc-- is used as a marker to insert the new Table of Contents
TOC="--toc_tag '!--toc--' --toc_tag_replace"
eval hypertoc $ARGS $TOC --make_anchors --make_toc --inline --outfile - $IFILE| \
sed "/<!-- INCLUDE [Nn]avigation/ r $INCLUDE
# Quick and dirty way to add a way to get back to the Toc from an Entry
# 1) put a marker in the beginning of the ToC
s/<h1>Table of Contents/<h1><a name=\"TOC\">Table Of Contents/
# 2) Add a link back to the ToC from each entry
s:\(<h[1234]>\)<a name=:\1<a href=\"$OFILENAME#TOC\" name=:g
# Include ad named 'GoogleAd1'
/INCLUDE GoogleAd1/ {
r Ads/GoogleAd1
}
" >$OFILE