diff --git a/tutorial/html.pike b/tutorial/html.pike index 7606cf13214a66af7b8244035e7ea7b2755c14a5..d972025032c282b5c4ecc0373c898a944a62a985 100644 --- a/tutorial/html.pike +++ b/tutorial/html.pike @@ -559,6 +559,10 @@ SGML convert(SGML data) } else { + if(!objectp(data)) + { + error("Tag is neither string nor object: %O\n",data); + } cpos=data->pos; switch(data->tag) { @@ -903,6 +907,88 @@ SGML wmml_to_html(SGML data) }); } +SGML split_tag(TAG t, TAG t2) +{ + array current=({}); + switch(t2->tag) + { + case "preface": + if(!sections->introduction) + sections->introduction=({t}); + else + sections->introduction+= + ({ + t, + Sgml.Tag("hr") + })+ + sections->introduction; + return current; + + case "introduction": + if(!sections->introduction) + sections->introduction=({}); + else + sections->introduction+= + ({ + Sgml.Tag("hr",(["size":"1","noshade":1]),0) + }); + + + sections->introduction+=({ + t + }); + return current; + + case "index": + sections[t2->params->name || "index"]=({ t }); + return current; + + case "chapter": + case "appendix": + t2->data=low_split(t2->data); + sections[t2->params->number]=({ t }); + return current; + + case "firstpage": + current+= + t->data+ + ({ + Sgml.Tag("hr",(["size":"1","noshade":1]),0) + }); + + sections->firstpage=({ + t, + }); + return current; + + case "table-of-contents": + sections->frame=({ + Sgml.Tag("frameset",(["cols":"30%,*"]),0, + ({ + "\n", + Sgml.Tag("frame",(["src":mklinkname("toc_frame"),"name":"toc"])), + "\n", + + Sgml.Tag("frame",(["src":mklinkname("firstpage"),"name":"display"])), + "\n", + + })), + "\n", + }); + + sections->toc_frame=Sgml.copy(({ t })); + TAG t3=get_tag(sections->toc_frame[0]); + t3->params->target="display"; + sections->toc_frame[0]->params->name="toc_frame"; + break; + + default: + if(t->data) + t->data=low_split(t->data); + } + return ({t}); +} + SGML low_split(SGML data) { @@ -911,86 +997,15 @@ SGML low_split(SGML data) { if(objectp(t)) { - TAG t2=get_tag(t); - switch(t2->tag) + SGML tmp=split_tag(t,get_tag(t)); + if(search(tmp,0) != -1) { - case "preface": - if(!sections->introduction) - sections->introduction=({t}); - else - sections->introduction+= - ({ - t, - Sgml.Tag("hr") - })+ - sections->introduction; - continue; - - case "introduction": - if(!sections->introduction) - sections->introduction=({}); - else - sections->introduction+= - ({ - Sgml.Tag("hr",(["size":"1","noshade":1]),0) - }); - - - sections->introduction+=({ - t - }); - continue; - - case "index": - sections[t2->params->name || "index"]=({ t }); - continue; - - case "chapter": - case "appendix": - sections[t2->params->number]=({ t }); - if (this_object()->split_and_remove_section) - this_object()->split_and_remove_section(t); - continue; - - case "firstpage": - current+= - t->data+ - ({ - Sgml.Tag("hr",(["size":"1","noshade":1]),0) - }); - - sections->firstpage=({ - t, - }); - continue; - - case "table-of-contents": - sections->frame=({ - Sgml.Tag("frameset",(["cols":"30%,*"]),0, - ({ - "\n", - Sgml.Tag("frame",(["src":mklinkname("toc_frame"),"name":"toc"])), - "\n", - - Sgml.Tag("frame",(["src":mklinkname("firstpage"),"name":"display"])), - "\n", - - })), - "\n", - }); - - sections->toc_frame=Sgml.copy(({ t })); - TAG t3=get_tag(sections->toc_frame[0]); - t3->params->target="display"; - sections->toc_frame[0]->params->name="toc_frame"; - break; - - default: - if(t->data) - t->data=low_split(t->data); + error("Got zero! %O\n",tmp); } + current+=tmp; + }else{ + current+=({t}); } - current+=({t}); } return current; diff --git a/tutorial/html_section_pages.pike b/tutorial/html_section_pages.pike index cdd9e60ad685744d3f7bb89f9c80db465452b427..7ce88ccc04c2acde285fadbfb4255828c0268a7a 100644 --- a/tutorial/html_section_pages.pike +++ b/tutorial/html_section_pages.pike @@ -2,28 +2,27 @@ #if __VERSION__ >= 0.6 import "."; #endif /* __VERSION__ >= 0.6 */ -inherit "html"; +inherit "html.pike"; -void split_and_remove_section(object t,object prev) + +SGML split_tag(TAG t, TAG t2) { - if (t->data) - foreach (t->data,object t2) - if (objectp(t2)) - { - split_and_remove_section(t2,t->tag=="anchor"?t:0); - if (t2->tag=="section") - { - object tq; - if (prev) - { - sections[t2->params->number]=({t}); - prev->data-=({t}); - } - else - { - sections[t2->params->number]=({t2}); - t->data-=({t2}); - } - } - } + switch(t2->tag) + { + case "section": + t2->data=low_split(t2->data); + sections[t2->params->number]=({t}); + return ({ + Sgml.Tag("h3",0,0,({ + Sgml.Tag("link",(["to":t2->params->number]),0, + ({ + sprintf("%s %s", + t2->params->number, + (string) t2->params->title), + })), + }) + }); + } + return ::split_tag(t,t2); } +