見出しタグのtocを生成したい。無料のプログラムはありますか?
2642 次
3 に答える
2
hypertoc、sed、および make を使用した HTML ページの目次の生成に関するブログ記事を書きました。シェル スクリプトは、広告名を使用して Google 広告も挿入します。また、Web サイトの他のページに移動するために使用できるナビゲーション セクションも作成しました。
私が使用する Web ページのサンプル テンプレートは次のようになります。
<!-- 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>
*.html.in という名前のファイルを読み取り、*.html ファイルを作成するincludeというスクリプトを作成しました。スクリプトは次のようになります。また、メイクファイルを使用して *.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
于 2014-04-16T21:01:14.657 に答える
1
samaxesjs TOC jQuery プラグインは非常にうまく機能します。
于 2012-04-10T13:35:59.147 に答える