htmlドキュメント(本の章)を取り、それをページ(DIVの配列で、それぞれがDIVの所定の寸法内に収まるhtmlコンテンツのページを含む)に分割したいと思います。私は次のコードでDOMを歩きます(このサイトにあります!)。
function walk(node, func)
{
func(node);
node = node.firstChild;
while (node)
{
walk(node, func);
node = node.nextSibling;
}
};
func関数はtestと呼ばれ、以下にあります。
function test(node)
{
var copy=node.cloneNode(false);
currentPageInArray.appendChild(copy);
//Test if we still fit
if( $(currentPageInArray).height() <= maxPageHeight )
{
//All good
}
else
{
//We dont fit anymore
//Remove node that made us exceed the height
currentPageInArray.removeChild(copy);
createNewPage();
currentPageInArray.appendChild(copy); //into new page
}
}
ページは正しく生成されますが、斜体、太字、ヘッダーなどのすべてのスタイルが失われます。clone(true)を実行しようとすると、多くの要素が複数回複製されます。どうすればこれを修正できますか?前もって感謝します。