2011-03-22 63 views
-1

我想爲標題標籤生成toc。有沒有免費的程序?尋找HTML toc生成器

+0

你說的這個「toc」是什麼?谷歌猜測*「目錄」*,但維基百科感到困惑:http://en.wikipedia.org/wiki/TOC。這是一個編程問題嗎?你有什麼嘗試? – Kobi 2011-03-22 05:59:52

+1

@Kobi,我很肯定他的意思是目錄。 – 2011-03-22 06:10:53

+2

是toc =目錄;所有html設計師常見的維護頭痛 – user5858 2011-03-22 06:28:23

回答

1

作爲@ user5858提到的htmltoc腳本的替代方法,有hypertoc,這是對Perl的更強大的重寫。像這樣安裝它(在Ubuntu Linux爲例):

sudo cpan -f -i HTML::GenToc 

使用方法如下:

hypertoc --inline --make_anchors --make_toc --overwrite file.html 
0

我剛上生成的目錄使用hypertoc的HTML頁面,用sed寫了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> 

我寫了一個叫包括腳本讀取名爲* .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