tohtml.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796
  1. #include <u.h>
  2. #include <libc.h>
  3. #include <bio.h>
  4. #include <String.h>
  5. #include <thread.h>
  6. #include "wiki.h"
  7. /*
  8. * Get HTML and text templates from underlying file system.
  9. * Caches them, which means changes don't take effect for
  10. * up to Tcache seconds after they are made.
  11. *
  12. * If the files are deleted, we keep returning the last
  13. * known copy.
  14. */
  15. enum {
  16. WAIT = 60
  17. };
  18. static char *name[2*Ntemplate] = {
  19. [Tpage] "page.html",
  20. [Tedit] "edit.html",
  21. [Tdiff] "diff.html",
  22. [Thistory] "history.html",
  23. [Tnew] "new.html",
  24. [Toldpage] "oldpage.html",
  25. [Twerror] "werror.html",
  26. [Ntemplate+Tpage] "page.txt",
  27. [Ntemplate+Tdiff] "diff.txt",
  28. [Ntemplate+Thistory] "history.txt",
  29. [Ntemplate+Toldpage] "oldpage.txt",
  30. [Ntemplate+Twerror] "werror.txt",
  31. };
  32. static struct {
  33. RWLock;
  34. String *s;
  35. ulong t;
  36. Qid qid;
  37. } cache[2*Ntemplate];
  38. static void
  39. cacheinit(void)
  40. {
  41. int i;
  42. static int x;
  43. static Lock l;
  44. if(x)
  45. return;
  46. lock(&l);
  47. if(x){
  48. unlock(&l);
  49. return;
  50. }
  51. for(i=0; i<2*Ntemplate; i++)
  52. if(name[i])
  53. cache[i].s = s_copy("");
  54. x = 1;
  55. unlock(&l);
  56. }
  57. static String*
  58. gettemplate(int type)
  59. {
  60. int n;
  61. Biobuf *b;
  62. Dir *d;
  63. String *s, *ns;
  64. if(name[type]==nil)
  65. return nil;
  66. cacheinit();
  67. rlock(&cache[type]);
  68. if(0 && cache[type].t+Tcache >= time(0)){
  69. s = s_incref(cache[type].s);
  70. runlock(&cache[type]);
  71. return s;
  72. }
  73. runlock(&cache[type]);
  74. // d = nil;
  75. wlock(&cache[type]);
  76. if(0 && cache[type].t+Tcache >= time(0) || (d = wdirstat(name[type])) == nil)
  77. goto Return;
  78. if(0 && d->qid.vers == cache[type].qid.vers && d->qid.path == cache[type].qid.path){
  79. cache[type].t = time(0);
  80. goto Return;
  81. }
  82. if((b = wBopen(name[type], OREAD)) == nil)
  83. goto Return;
  84. ns = s_reset(nil);
  85. n = s_read(b, ns, 10000);
  86. Bterm(b);
  87. if(n <= 0)
  88. goto Return;
  89. s_free(cache[type].s);
  90. cache[type].s = ns;
  91. cache[type].qid = d->qid;
  92. cache[type].t = time(0);
  93. Return:
  94. free(d);
  95. s = s_incref(cache[type].s);
  96. wunlock(&cache[type]);
  97. return s;
  98. }
  99. /*
  100. * Write wiki document in HTML.
  101. */
  102. static String*
  103. s_escappend(String *s, char *p, int pre)
  104. {
  105. char *q;
  106. while(q = strpbrk(p, pre ? "<>&" : " <>&")){
  107. s = s_nappend(s, p, q-p);
  108. switch(*q){
  109. case '<':
  110. s = s_append(s, "&lt;");
  111. break;
  112. case '>':
  113. s = s_append(s, "&gt;");
  114. break;
  115. case '&':
  116. s = s_append(s, "&amp;");
  117. break;
  118. case ' ':
  119. s = s_append(s, "\n");
  120. }
  121. p = q+1;
  122. }
  123. s = s_append(s, p);
  124. return s;
  125. }
  126. static char*
  127. mkurl(char *s, int ty)
  128. {
  129. char *p, *q;
  130. if(strncmp(s, "http:", 5)==0
  131. || strncmp(s, "ftp:", 4)==0
  132. || strncmp(s, "mailto:", 7)==0
  133. || strncmp(s, "telnet:", 7)==0
  134. || strncmp(s, "file:", 5)==0)
  135. return estrdup(s);
  136. if(strchr(s, ' ')==nil && strchr(s, '@')!=nil){
  137. p = emalloc(strlen(s)+8);
  138. strcpy(p, "mailto:");
  139. strcat(p, s);
  140. return p;
  141. }
  142. if(ty == Toldpage)
  143. p = smprint("../../%s", s);
  144. else
  145. p = smprint("../%s", s);
  146. for(q=p; *q; q++)
  147. if(*q==' ')
  148. *q = '_';
  149. return p;
  150. }
  151. String*
  152. pagehtml(String *s, Wpage *wtxt, int ty)
  153. {
  154. int inlist, inpre, inpara;
  155. char *p, tmp[40];
  156. Wpage *w;
  157. inlist = 0;
  158. inpre = 0;
  159. inpara = 0;
  160. for(w=wtxt; w; w=w->next){
  161. switch(w->type){
  162. case Wheading:
  163. if(!inpara){
  164. inpara = 1;
  165. s = s_append(s, "\n<p>\n");
  166. }
  167. s = s_appendlist(s, "<b>", w->text, "</b>\n<p>\n", nil);
  168. break;
  169. case Wpara:
  170. if(inlist){
  171. inlist = 0;
  172. s = s_append(s, "\n</ul>\n");
  173. }
  174. if(inpre){
  175. inpre = 0;
  176. s = s_append(s, "</pre>\n");
  177. }
  178. if(!inpara){
  179. inpara = 1;
  180. s = s_append(s, "\n<p>\n");
  181. }
  182. break;
  183. case Wbullet:
  184. if(inpre){
  185. inpre = 0;
  186. s = s_append(s, "</pre>\n");
  187. }
  188. if(!inlist){
  189. inlist = 1;
  190. s = s_append(s, "\n<ul>\n");
  191. }
  192. if(inpara)
  193. inpara = 0;
  194. s = s_append(s, "\n<li>\n");
  195. break;
  196. case Wlink:
  197. if(inpara)
  198. inpara = 0;
  199. if(w->url == nil)
  200. p = mkurl(w->text, ty);
  201. else
  202. p = w->url;
  203. s = s_appendlist(s, "<a href=\"", p, "\">", nil);
  204. s = s_escappend(s, w->text, 0);
  205. s = s_append(s, "</a>");
  206. if(w->url == nil)
  207. free(p);
  208. break;
  209. case Wman:
  210. if(inpara)
  211. inpara = 0;
  212. sprint(tmp, "%d", w->section);
  213. s = s_appendlist(s,
  214. "<a href=\"http://plan9.bell-labs.com/magic/man2html/",
  215. tmp, "/", w->text, "\"><i>", w->text, "</i>(",
  216. tmp, ")</a>", nil);
  217. break;
  218. case Wpre:
  219. if(inpara)
  220. inpara = 0;
  221. if(inlist){
  222. inlist = 0;
  223. s = s_append(s, "\n</ul>\n");
  224. }
  225. if(!inpre){
  226. inpre = 1;
  227. s = s_append(s, "\n<pre>\n");
  228. }
  229. s = s_escappend(s, w->text, 1);
  230. s = s_append(s, "\n");
  231. break;
  232. case Wplain:
  233. if(inpre){
  234. inpre = 0;
  235. s = s_append(s, "</pre>\n");
  236. }
  237. if(inpara)
  238. inpara = 0;
  239. s = s_escappend(s, w->text, 0);
  240. break;
  241. }
  242. }
  243. if(inlist)
  244. s = s_append(s, "\n</ul>\n");
  245. if(inpre)
  246. s = s_append(s, "</pre>\n");
  247. if(!inpara)
  248. s = s_append(s, "\n<p>\n");
  249. return s;
  250. }
  251. static String*
  252. grey(String *s)
  253. {
  254. return s_append(s, "<font color=#777777>");
  255. }
  256. static String*
  257. ungrey(String *s)
  258. {
  259. return s_append(s, "</font>");
  260. }
  261. static String*
  262. copythru(String *s, char **newp, int *nlinep, int l)
  263. {
  264. char *oq, *q, *r;
  265. int ol;
  266. q = *newp;
  267. oq = q;
  268. ol = *nlinep;
  269. while(ol < l){
  270. if(r = strchr(q, '\n'))
  271. q = r+1;
  272. else{
  273. q += strlen(q);
  274. break;
  275. }
  276. ol++;
  277. }
  278. if(*nlinep < l)
  279. *nlinep = l;
  280. *newp = q;
  281. return s_nappend(s, oq, q-oq);
  282. }
  283. static int
  284. dodiff(char *f1, char *f2)
  285. {
  286. int p[2];
  287. if(pipe(p) < 0){
  288. return -1;
  289. }
  290. switch(fork()){
  291. case -1:
  292. return -1;
  293. case 0:
  294. close(p[0]);
  295. dup(p[1], 1);
  296. execl("/bin/diff", "diff", f1, f2, nil);
  297. _exits(nil);
  298. }
  299. close(p[1]);
  300. return p[0];
  301. }
  302. /* print document i grayed out, with only diffs relative to j in black */
  303. static String*
  304. s_diff(String *s, Whist *h, int i, int j)
  305. {
  306. char *p, *q, *pnew;
  307. int fdiff, fd1, fd2, n1, n2;
  308. Biobuf b;
  309. char fn1[40], fn2[40];
  310. String *new, *old;
  311. int nline;
  312. if(j < 0)
  313. return pagehtml(s, h->doc[i].wtxt, Tpage);
  314. strcpy(fn1, "/tmp/wiki.XXXXXX");
  315. strcpy(fn2, "/tmp/wiki.XXXXXX");
  316. if((fd1 = opentemp(fn1)) < 0 || (fd2 = opentemp(fn2)) < 0){
  317. close(fd1);
  318. s = s_append(s, "\nopentemp failed; sorry\n");
  319. return s;
  320. }
  321. new = pagehtml(s_reset(nil), h->doc[i].wtxt, Tpage);
  322. old = pagehtml(s_reset(nil), h->doc[j].wtxt, Tpage);
  323. write(fd1, s_to_c(new), s_len(new));
  324. write(fd2, s_to_c(old), s_len(old));
  325. fdiff = dodiff(fn2, fn1);
  326. if(fdiff < 0)
  327. s = s_append(s, "\ndiff failed; sorry\n");
  328. else{
  329. nline = 0;
  330. pnew = s_to_c(new);
  331. Binit(&b, fdiff, OREAD);
  332. while(p = Brdline(&b, '\n')){
  333. if(p[0]=='<' || p[0]=='>' || p[0]=='-')
  334. continue;
  335. p[Blinelen(&b)-1] = '\0';
  336. if((q = strpbrk(p, "acd")) == nil)
  337. continue;
  338. switch(*q){
  339. case 'a':
  340. case 'c':
  341. n1 = atoi(q+1);
  342. if(q = strchr(q, ','))
  343. n2 = atoi(q+1);
  344. else
  345. n2 = n1;
  346. s = grey(s);
  347. s = copythru(s, &pnew, &nline, n1-1);
  348. s = ungrey(s);
  349. s = copythru(s, &pnew, &nline, n2);
  350. break;
  351. }
  352. }
  353. close(fdiff);
  354. s = grey(s);
  355. s = s_append(s, pnew);
  356. s = ungrey(s);
  357. }
  358. s_free(new);
  359. s_free(old);
  360. close(fd1);
  361. close(fd2);
  362. return s;
  363. }
  364. static String*
  365. diffhtml(String *s, Whist *h)
  366. {
  367. int i;
  368. char tmp[50];
  369. char *atime;
  370. for(i=h->ndoc-1; i>=0; i--){
  371. s = s_append(s, "<hr>\n");
  372. if(i==h->current)
  373. sprint(tmp, "index.html");
  374. else
  375. sprint(tmp, "%lud", h->doc[i].time);
  376. atime = ctime(h->doc[i].time);
  377. atime[strlen(atime)-1] = '\0';
  378. s = s_appendlist(s,
  379. "<a href=\"", tmp, "\">",
  380. atime, "</a>", nil);
  381. if(h->doc[i].author)
  382. s = s_appendlist(s, ", ", h->doc[i].author, nil);
  383. if(h->doc[i].conflict)
  384. s = s_append(s, ", conflicting write");
  385. s = s_append(s, "\n");
  386. if(h->doc[i].comment)
  387. s = s_appendlist(s, "<br><i>", h->doc[i].comment, "</i>\n", nil);
  388. s = s_append(s, "<br><hr>");
  389. s = s_diff(s, h, i, i-1);
  390. }
  391. s = s_append(s, "<hr>");
  392. return s;
  393. }
  394. static String*
  395. historyhtml(String *s, Whist *h)
  396. {
  397. int i;
  398. char tmp[40];
  399. char *atime;
  400. s = s_append(s, "<ul>\n");
  401. for(i=h->ndoc-1; i>=0; i--){
  402. if(i==h->current)
  403. sprint(tmp, "index.html");
  404. else
  405. sprint(tmp, "%lud", h->doc[i].time);
  406. atime = ctime(h->doc[i].time);
  407. atime[strlen(atime)-1] = '\0';
  408. s = s_appendlist(s,
  409. "<li><a href=\"", tmp, "\">",
  410. atime, "</a>", nil);
  411. if(h->doc[i].author)
  412. s = s_appendlist(s, ", ", h->doc[i].author, nil);
  413. if(h->doc[i].conflict)
  414. s = s_append(s, ", conflicting write");
  415. s = s_append(s, "\n");
  416. if(h->doc[i].comment)
  417. s = s_appendlist(s, "<br><i>", h->doc[i].comment, "</i>\n", nil);
  418. }
  419. s = s_append(s, "</ul>");
  420. return s;
  421. }
  422. String*
  423. tohtml(Whist *h, Wdoc *d, int ty)
  424. {
  425. char *atime;
  426. char *p, *q, ver[40];
  427. int nsub;
  428. Sub sub[3];
  429. String *s, *t;
  430. t = gettemplate(ty);
  431. if(p = strstr(s_to_c(t), "PAGE"))
  432. q = p+4;
  433. else{
  434. p = s_to_c(t)+s_len(t);
  435. q = nil;
  436. }
  437. nsub = 0;
  438. if(h){
  439. sub[nsub] = (Sub){ "TITLE", h->title };
  440. nsub++;
  441. }
  442. if(d){
  443. sprint(ver, "%lud", d->time);
  444. sub[nsub] = (Sub){ "VERSION", ver };
  445. nsub++;
  446. atime = ctime(d->time);
  447. atime[strlen(atime)-1] = '\0';
  448. sub[nsub] = (Sub){ "DATE", atime };
  449. nsub++;
  450. }
  451. s = s_reset(nil);
  452. s = s_appendsub(s, s_to_c(t), p-s_to_c(t), sub, nsub);
  453. switch(ty){
  454. case Tpage:
  455. case Toldpage:
  456. s = pagehtml(s, d->wtxt, ty);
  457. break;
  458. case Tedit:
  459. s = pagetext(s, d->wtxt, 0);
  460. break;
  461. case Tdiff:
  462. s = diffhtml(s, h);
  463. break;
  464. case Thistory:
  465. s = historyhtml(s, h);
  466. break;
  467. case Tnew:
  468. case Twerror:
  469. break;
  470. }
  471. if(q)
  472. s = s_appendsub(s, q, strlen(q), sub, nsub);
  473. s_free(t);
  474. return s;
  475. }
  476. enum {
  477. LINELEN = 70,
  478. };
  479. static String*
  480. s_appendbrk(String *s, char *p, char *prefix, int dosharp)
  481. {
  482. char *e, *w, *x;
  483. int first, l;
  484. first = 1;
  485. while(*p){
  486. s = s_append(s, p);
  487. e = strrchr(s_to_c(s), '\n');
  488. if(e == nil)
  489. e = s_to_c(s);
  490. else
  491. e++;
  492. l = utflen(e);
  493. if(l <= LINELEN)
  494. break;
  495. /* BUG: should be LINELEN utf chars not LINELEN bytes */
  496. x = strchr(e+LINELEN, ' ');
  497. if(x){
  498. *x = '\0';
  499. w = strrchr(e, ' ');
  500. *x = ' ';
  501. }else
  502. w = strrchr(e, ' ');
  503. if(w-s_to_c(s) < strlen(prefix))
  504. break;
  505. x = estrdup(w+1);
  506. *w = '\0';
  507. s->ptr = w;
  508. s_append(s, "\n");
  509. if(dosharp)
  510. s_append(s, "#");
  511. s_append(s, prefix);
  512. if(!first)
  513. free(p);
  514. first = 0;
  515. p = x;
  516. }
  517. if(!first)
  518. free(p);
  519. return s;
  520. }
  521. static void
  522. s_endline(String *s, int dosharp)
  523. {
  524. if(dosharp){
  525. if(s->ptr == s->base+1 && s->ptr[-1] == '#')
  526. return;
  527. if(s->ptr > s->base+1 && s->ptr[-1] == '#' && s->ptr[-2] == '\n')
  528. return;
  529. s_append(s, "\n#");
  530. }else{
  531. if(s->ptr > s->base+1 && s->ptr[-1] == '\n')
  532. return;
  533. s_append(s, "\n");
  534. }
  535. }
  536. String*
  537. pagetext(String *s, Wpage *page, int dosharp)
  538. {
  539. int inlist, inpara;
  540. char *prefix, *sharp, tmp[40];
  541. String *t;
  542. Wpage *w;
  543. inlist = 0;
  544. inpara = 0;
  545. prefix = "";
  546. sharp = dosharp ? "#" : "";
  547. s = s_append(s, sharp);
  548. for(w=page; w; w=w->next){
  549. switch(w->type){
  550. case Wheading:
  551. if(inlist){
  552. prefix = "";
  553. inlist = 0;
  554. }
  555. s_endline(s, dosharp);
  556. if(!inpara){
  557. inpara = 1;
  558. s = s_appendlist(s, "\n", sharp, nil);
  559. }
  560. s = s_appendlist(s, w->text, "\n", sharp, "\n", sharp, nil);
  561. break;
  562. case Wpara:
  563. s_endline(s, dosharp);
  564. if(inlist){
  565. prefix = "";
  566. inlist = 0;
  567. }
  568. if(!inpara){
  569. inpara = 1;
  570. s = s_appendlist(s, "\n", sharp, nil);
  571. }
  572. break;
  573. case Wbullet:
  574. s_endline(s, dosharp);
  575. if(!inlist)
  576. inlist = 1;
  577. if(inpara)
  578. inpara = 0;
  579. s = s_append(s, " *\t");
  580. prefix = "\t";
  581. break;
  582. case Wlink:
  583. if(inpara)
  584. inpara = 0;
  585. t = s_append(s_copy("["), w->text);
  586. if(w->url == nil)
  587. t = s_append(t, "]");
  588. else{
  589. t = s_append(t, " | ");
  590. t = s_append(t, w->url);
  591. t = s_append(t, "]");
  592. }
  593. s = s_appendbrk(s, s_to_c(t), prefix, dosharp);
  594. s_free(t);
  595. break;
  596. case Wman:
  597. if(inpara)
  598. inpara = 0;
  599. s = s_appendbrk(s, w->text, prefix, dosharp);
  600. sprint(tmp, "(%d)", w->section);
  601. s = s_appendbrk(s, tmp, prefix, dosharp);
  602. break;
  603. case Wpre:
  604. if(inlist){
  605. prefix = "";
  606. inlist = 0;
  607. }
  608. if(inpara)
  609. inpara = 0;
  610. s_endline(s, dosharp);
  611. s = s_appendlist(s, "! ", w->text, "\n", sharp, nil);
  612. break;
  613. case Wplain:
  614. if(inpara)
  615. inpara = 0;
  616. s = s_appendbrk(s, w->text, prefix, dosharp);
  617. break;
  618. }
  619. }
  620. s_endline(s, dosharp);
  621. s->ptr--;
  622. *s->ptr = '\0';
  623. return s;
  624. }
  625. static String*
  626. historytext(String *s, Whist *h)
  627. {
  628. int i;
  629. char tmp[40];
  630. char *atime;
  631. for(i=h->ndoc-1; i>=0; i--){
  632. if(i==h->current)
  633. sprint(tmp, "[current]");
  634. else
  635. sprint(tmp, "[%lud/]", h->doc[i].time);
  636. atime = ctime(h->doc[i].time);
  637. atime[strlen(atime)-1] = '\0';
  638. s = s_appendlist(s, " * ", tmp, " ", atime, nil);
  639. if(h->doc[i].author)
  640. s = s_appendlist(s, ", ", h->doc[i].author, nil);
  641. if(h->doc[i].conflict)
  642. s = s_append(s, ", conflicting write");
  643. s = s_append(s, "\n");
  644. if(h->doc[i].comment)
  645. s = s_appendlist(s, "<i>", h->doc[i].comment, "</i>\n", nil);
  646. }
  647. return s;
  648. }
  649. String*
  650. totext(Whist *h, Wdoc *d, int ty)
  651. {
  652. char *atime;
  653. char *p, *q, ver[40];
  654. int nsub;
  655. Sub sub[3];
  656. String *s, *t;
  657. t = gettemplate(Ntemplate+ty);
  658. if(p = strstr(s_to_c(t), "PAGE"))
  659. q = p+4;
  660. else{
  661. p = s_to_c(t)+s_len(t);
  662. q = nil;
  663. }
  664. nsub = 0;
  665. if(h){
  666. sub[nsub] = (Sub){ "TITLE", h->title };
  667. nsub++;
  668. }
  669. if(d){
  670. sprint(ver, "%lud", d->time);
  671. sub[nsub] = (Sub){ "VERSION", ver };
  672. nsub++;
  673. atime = ctime(d->time);
  674. atime[strlen(atime)-1] = '\0';
  675. sub[nsub] = (Sub){ "DATE", atime };
  676. nsub++;
  677. }
  678. s = s_reset(nil);
  679. s = s_appendsub(s, s_to_c(t), p-s_to_c(t), sub, nsub);
  680. switch(ty){
  681. case Tpage:
  682. case Toldpage:
  683. s = pagetext(s, d->wtxt, 0);
  684. break;
  685. case Thistory:
  686. s = historytext(s, h);
  687. break;
  688. case Tnew:
  689. case Twerror:
  690. break;
  691. }
  692. if(q)
  693. s = s_appendsub(s, q, strlen(q), sub, nsub);
  694. s_free(t);
  695. return s;
  696. }
  697. String*
  698. doctext(String *s, Wdoc *d)
  699. {
  700. char tmp[40];
  701. sprint(tmp, "D%lud", d->time);
  702. s = s_append(s, tmp);
  703. if(d->comment){
  704. s = s_append(s, "\nC");
  705. s = s_append(s, d->comment);
  706. }
  707. if(d->author){
  708. s = s_append(s, "\nA");
  709. s = s_append(s, d->author);
  710. }
  711. if(d->conflict)
  712. s = s_append(s, "\nX");
  713. s = s_append(s, "\n");
  714. s = pagetext(s, d->wtxt, 1);
  715. return s;
  716. }