2 * HTML backend for Halibut
8 * - I'm never entirely convinced that having a fragment link to
9 * come in at the start of the real text in the file is
10 * sensible. Perhaps for the topmost section in the file, no
11 * fragment should be used? (Though it should probably still be
12 * _there_ even if unused.)
14 * - new configurability:
15 * * a few new things explicitly labelled as `FIXME:
16 * configurable' or similar.
18 * * Some means of specifying the distinction between
19 * restrict-charset and output-charset. It seems to me that
20 * `html-charset' is output-charset, and that
21 * restrict-charset usually wants to be either output-charset
22 * or UTF-8 (the latter indicating that any Unicode character
23 * is fair game and it will be specified using &#foo; if it
24 * isn't in output-charset). However, since XHTML defaults to
25 * UTF-8 and it's fiddly to tell it otherwise, it's just
26 * possible that some user may need to set restrict-charset
27 * to their charset of choice while leaving _output_-charset
28 * at UTF-8. Figure out some configuration, and apply it.
30 * - test all HTML flavours and ensure they validate sensibly. Fix
31 * remaining confusion issues such as <?xml?> and obsoleteness
34 * - proper naming of all fragment IDs. The ones for sections are
35 * fine; the ones for numbered list and bibliociteds are utter
36 * crap; the ones for indexes _might_ do but it might be worth
37 * giving some thought to how to do them better.
38 * + also set up a mechanism for ensuring that fragment IDs
41 * - nonbreaking spaces?
50 #define is_heading_type(type) ( (type) == para_Title || \
51 (type) == para_Chapter || \
52 (type) == para_Appendix || \
53 (type) == para_UnnumberedChapter || \
54 (type) == para_Heading || \
55 (type) == para_Subsect)
57 #define heading_depth(p) ( (p)->type == para_Subsect ? (p)->aux + 1 : \
58 (p)->type == para_Heading ? 1 : \
59 (p)->type == para_Title ? -1 : 0 )
63 wchar_t *number_suffix
;
68 sectlevel achapter
, *asect
;
69 int *contents_depths
; /* 0=main, 1=chapter, 2=sect etc */
71 int address_section
, visible_version_id
;
72 int leaf_contains_contents
, leaf_smallest_contents
;
73 char *contents_filename
;
75 char *template_filename
;
76 char *single_filename
;
77 char *template_fragment
;
78 char *head_end
, *body_start
, *body_end
, *addr_start
, *addr_end
;
79 char *body_tag
, *nav_attr
;
80 wchar_t *author
, *description
;
81 int restrict_charset
, output_charset
;
84 XHTML_1_0_TRANSITIONAL
, XHTML_1_0_STRICT
86 wchar_t *lquote
, *rquote
;
90 #define contents_depth(conf, level) \
91 ( (conf).ncdepths > (level) ? (conf).contents_depths[level] : (level)+2 )
93 #define is_xhtml(ver) ((ver) >= XHTML_1_0_TRANSITIONAL)
95 typedef struct htmlfile htmlfile
;
96 typedef struct htmlsect htmlsect
;
101 int last_fragment_number
;
102 int min_heading_depth
;
103 htmlsect
*first
, *last
; /* first/last highest-level sections */
107 htmlsect
*next
, *parent
;
109 paragraph
*title
, *text
;
110 enum { NORMAL
, TOP
, INDEX
} type
;
116 htmlfile
*head
, *tail
;
117 htmlfile
*single
, *index
;
121 htmlsect
*head
, *tail
;
136 * This level deals with charset conversion, starting and
137 * ending tags, and writing to the file. It's the lexical
142 charset_state cstate
;
145 HO_NEUTRAL
, HO_IN_TAG
, HO_IN_EMPTY_TAG
, HO_IN_TEXT
148 * Stuff beyond here deals with the higher syntactic level: it
149 * tracks how many levels of <ul> are currently open when
150 * producing a contents list, for example.
155 static void html_file_section(htmlconfig
*cfg
, htmlfilelist
*files
,
156 htmlsect
*sect
, int depth
);
158 static htmlfile
*html_new_file(htmlfilelist
*list
, char *filename
);
159 static htmlsect
*html_new_sect(htmlsectlist
*list
, paragraph
*title
);
161 /* Flags for html_words() flags parameter */
165 #define INDEXENTS 0x04
167 static void html_words(htmloutput
*ho
, word
*words
, int flags
,
168 htmlfile
*file
, keywordlist
*keywords
, htmlconfig
*cfg
);
169 static void html_codepara(htmloutput
*ho
, word
*words
);
171 static void element_open(htmloutput
*ho
, char const *name
);
172 static void element_close(htmloutput
*ho
, char const *name
);
173 static void element_empty(htmloutput
*ho
, char const *name
);
174 static void element_attr(htmloutput
*ho
, char const *name
, char const *value
);
175 static void element_attr_w(htmloutput
*ho
, char const *name
,
176 wchar_t const *value
);
177 static void html_text(htmloutput
*ho
, wchar_t const *str
);
178 static void html_text_limit(htmloutput
*ho
, wchar_t const *str
, int maxlen
);
179 static void html_text_limit_internal(htmloutput
*ho
, wchar_t const *text
,
180 int maxlen
, int quote_quotes
);
181 static void html_nl(htmloutput
*ho
);
182 static void html_raw(htmloutput
*ho
, char *text
);
183 static void html_raw_as_attr(htmloutput
*ho
, char *text
);
184 static void cleanup(htmloutput
*ho
);
186 static void html_href(htmloutput
*ho
, htmlfile
*thisfile
,
187 htmlfile
*targetfile
, char *targetfrag
);
189 static char *html_format(paragraph
*p
, char *template_string
);
190 static void html_sanitise_fragment(char *text
);
192 static void html_contents_entry(htmloutput
*ho
, int depth
, htmlsect
*s
,
193 htmlfile
*thisfile
, keywordlist
*keywords
,
195 static void html_section_title(htmloutput
*ho
, htmlsect
*s
,
196 htmlfile
*thisfile
, keywordlist
*keywords
,
199 static htmlconfig
html_configure(paragraph
*source
) {
207 ret
.achapter
.just_numbers
= FALSE
;
208 ret
.achapter
.number_suffix
= L
": ";
210 ret
.asect
= snewn(ret
.nasect
, sectlevel
);
211 ret
.asect
[0].just_numbers
= TRUE
;
212 ret
.asect
[0].number_suffix
= L
" ";
214 ret
.contents_depths
= 0;
215 ret
.visible_version_id
= TRUE
;
216 ret
.address_section
= TRUE
;
217 ret
.leaf_contains_contents
= FALSE
;
218 ret
.leaf_smallest_contents
= 4;
219 ret
.single_filename
= dupstr("Manual.html");
220 ret
.contents_filename
= dupstr("Contents.html");
221 ret
.index_filename
= dupstr("IndexPage.html");
222 ret
.template_filename
= dupstr("%n.html");
223 ret
.template_fragment
= dupstr("%b");
224 ret
.head_end
= ret
.body_tag
= ret
.body_start
= ret
.body_end
=
225 ret
.addr_start
= ret
.addr_end
= ret
.nav_attr
= NULL
;
226 ret
.author
= ret
.description
= NULL
;
227 ret
.restrict_charset
= CS_ASCII
;
228 ret
.output_charset
= CS_ASCII
;
229 ret
.htmlver
= HTML_4
;
231 * Default quote characters are Unicode matched single quotes,
232 * falling back to ordinary ASCII ".
234 ret
.lquote
= L
"\x2018\0\x2019\0\"\0\"\0\0";
235 ret
.rquote
= uadv(ret
.lquote
);
238 * Two-pass configuration so that we can pick up global config
239 * (e.g. `quotes') before having it overridden by specific
240 * config (`html-quotes'), irrespective of the order in which
243 for (p
= source
; p
; p
= p
->next
) {
244 if (p
->type
== para_Config
) {
245 if (!ustricmp(p
->keyword
, L
"quotes")) {
246 if (*uadv(p
->keyword
) && *uadv(uadv(p
->keyword
))) {
247 ret
.lquote
= uadv(p
->keyword
);
248 ret
.rquote
= uadv(ret
.lquote
);
254 for (p
= source
; p
; p
= p
->next
) {
255 if (p
->type
== para_Config
) {
256 wchar_t *k
= p
->keyword
;
258 if (!ustrnicmp(k
, L
"xhtml-", 6))
259 k
++; /* treat `xhtml-' and `html-' the same */
261 if (!ustricmp(k
, L
"html-charset")) {
262 char *csname
= utoa_dup(uadv(k
), CS_ASCII
);
263 ret
.restrict_charset
= ret
.output_charset
=
264 charset_from_localenc(csname
);
266 } else if (!ustricmp(k
, L
"html-single-filename")) {
267 sfree(ret
.single_filename
);
268 ret
.single_filename
= dupstr(adv(p
->origkeyword
));
269 } else if (!ustricmp(k
, L
"html-contents-filename")) {
270 sfree(ret
.contents_filename
);
271 ret
.contents_filename
= dupstr(adv(p
->origkeyword
));
272 } else if (!ustricmp(k
, L
"html-index-filename")) {
273 sfree(ret
.index_filename
);
274 ret
.index_filename
= dupstr(adv(p
->origkeyword
));
275 } else if (!ustricmp(k
, L
"html-template-filename")) {
276 sfree(ret
.template_filename
);
277 ret
.template_filename
= dupstr(adv(p
->origkeyword
));
278 } else if (!ustricmp(k
, L
"html-template-fragment")) {
279 sfree(ret
.template_fragment
);
280 ret
.template_fragment
= dupstr(adv(p
->origkeyword
));
281 } else if (!ustricmp(k
, L
"html-chapter-numeric")) {
282 ret
.achapter
.just_numbers
= utob(uadv(k
));
283 } else if (!ustricmp(k
, L
"html-chapter-suffix")) {
284 ret
.achapter
.number_suffix
= uadv(k
);
285 } else if (!ustricmp(k
, L
"html-leaf-level")) {
286 ret
.leaf_level
= utoi(uadv(k
));
287 } else if (!ustricmp(k
, L
"html-section-numeric")) {
288 wchar_t *q
= uadv(k
);
294 if (n
>= ret
.nasect
) {
296 ret
.asect
= sresize(ret
.asect
, n
+1, sectlevel
);
297 for (i
= ret
.nasect
; i
<= n
; i
++)
298 ret
.asect
[i
] = ret
.asect
[ret
.nasect
-1];
301 ret
.asect
[n
].just_numbers
= utob(q
);
302 } else if (!ustricmp(k
, L
"html-section-suffix")) {
303 wchar_t *q
= uadv(k
);
309 if (n
>= ret
.nasect
) {
311 ret
.asect
= sresize(ret
.asect
, n
+1, sectlevel
);
312 for (i
= ret
.nasect
; i
<= n
; i
++) {
313 ret
.asect
[i
] = ret
.asect
[ret
.nasect
-1];
317 ret
.asect
[n
].number_suffix
= q
;
318 } else if (!ustricmp(k
, L
"html-contents-depth") ||
319 !ustrnicmp(k
, L
"html-contents-depth-", 20)) {
321 * Relic of old implementation: this directive used
322 * to be written as \cfg{html-contents-depth-3}{2}
323 * rather than the usual Halibut convention of
324 * \cfg{html-contents-depth}{3}{2}. We therefore
327 wchar_t *q
= k
[19] ? k
+20 : uadv(k
);
333 if (n
>= ret
.ncdepths
) {
335 ret
.contents_depths
=
336 sresize(ret
.contents_depths
, n
+1, int);
337 for (i
= ret
.ncdepths
; i
<= n
; i
++) {
338 ret
.contents_depths
[i
] = i
+2;
342 ret
.contents_depths
[n
] = utoi(q
);
343 } else if (!ustricmp(k
, L
"html-head-end")) {
344 ret
.head_end
= adv(p
->origkeyword
);
345 } else if (!ustricmp(k
, L
"html-body-tag")) {
346 ret
.body_tag
= adv(p
->origkeyword
);
347 } else if (!ustricmp(k
, L
"html-body-start")) {
348 ret
.body_start
= adv(p
->origkeyword
);
349 } else if (!ustricmp(k
, L
"html-body-end")) {
350 ret
.body_end
= adv(p
->origkeyword
);
351 } else if (!ustricmp(k
, L
"html-address-start")) {
352 ret
.addr_start
= adv(p
->origkeyword
);
353 } else if (!ustricmp(k
, L
"html-address-end")) {
354 ret
.addr_end
= adv(p
->origkeyword
);
355 } else if (!ustricmp(k
, L
"html-navigation-attributes")) {
356 ret
.nav_attr
= adv(p
->origkeyword
);
357 } else if (!ustricmp(k
, L
"html-author")) {
358 ret
.author
= uadv(k
);
359 } else if (!ustricmp(k
, L
"html-description")) {
360 ret
.description
= uadv(k
);
361 } else if (!ustricmp(k
, L
"html-suppress-address")) {
362 ret
.address_section
= !utob(uadv(k
));
363 } else if (!ustricmp(k
, L
"html-versionid")) {
364 ret
.visible_version_id
= utob(uadv(k
));
365 } else if (!ustricmp(k
, L
"html-quotes")) {
366 if (*uadv(k
) && *uadv(uadv(k
))) {
367 ret
.lquote
= uadv(k
);
368 ret
.rquote
= uadv(ret
.lquote
);
370 } else if (!ustricmp(k
, L
"html-leaf-contains-contents")) {
371 ret
.leaf_contains_contents
= utob(uadv(k
));
372 } else if (!ustricmp(k
, L
"html-leaf-smallest-contents")) {
373 ret
.leaf_smallest_contents
= utoi(uadv(k
));
379 * Now process fallbacks on quote characters.
381 while (*uadv(ret
.rquote
) && *uadv(uadv(ret
.rquote
)) &&
382 (!cvt_ok(ret
.restrict_charset
, ret
.lquote
) ||
383 !cvt_ok(ret
.restrict_charset
, ret
.rquote
))) {
384 ret
.lquote
= uadv(ret
.rquote
);
385 ret
.rquote
= uadv(ret
.lquote
);
391 paragraph
*html_config_filename(char *filename
)
394 * If the user passes in a single filename as a parameter to
395 * the `--html' command-line option, then we should assume it
396 * to imply _two_ config directives:
397 * \cfg{html-single-filename}{whatever} and
398 * \cfg{html-leaf-level}{0}; the rationale being that the user
399 * wants their output _in that file_.
403 p
= cmdline_cfg_simple("html-single-filename", filename
, NULL
);
404 q
= cmdline_cfg_simple("html-leaf-level", "0", NULL
);
409 void html_backend(paragraph
*sourceform
, keywordlist
*keywords
,
410 indexdata
*idx
, void *unused
) {
413 htmlfilelist files
= { NULL
, NULL
, NULL
, NULL
};
414 htmlsectlist sects
= { NULL
, NULL
}, nonsects
= { NULL
, NULL
};
418 conf
= html_configure(sourceform
);
421 * We're going to make heavy use of paragraphs' private data
422 * fields in the forthcoming code. Clear them first, so we can
423 * reliably tell whether we have auxiliary data for a
424 * particular paragraph.
426 for (p
= sourceform
; p
; p
= p
->next
)
427 p
->private_data
= NULL
;
430 * Start by figuring out into which file each piece of the
431 * document should be put. We'll do this by inventing an
432 * `htmlsect' structure and stashing it in the private_data
433 * field of each section paragraph; we also need one additional
434 * htmlsect for the document index, which won't show up in the
435 * source form but needs to be consistently mentioned in
438 * While we're here, we'll also invent the HTML fragment name
442 htmlsect
*topsect
, *sect
;
445 topsect
= html_new_sect(§s
, p
);
447 topsect
->title
= NULL
;
448 topsect
->text
= sourceform
;
449 topsect
->contents_depth
= contents_depth(conf
, 0);
450 html_file_section(&conf
, &files
, topsect
, -1);
451 topsect
->fragment
= NULL
;
453 for (p
= sourceform
; p
; p
= p
->next
)
454 if (is_heading_type(p
->type
)) {
455 d
= heading_depth(p
);
457 if (p
->type
== para_Title
) {
462 sect
= html_new_sect(§s
, p
);
463 sect
->text
= p
->next
;
465 sect
->contents_depth
= contents_depth(conf
, d
+1) - (d
+1);
468 sect
->parent
= (htmlsect
*)p
->parent
->private_data
;
469 assert(sect
->parent
!= NULL
);
471 sect
->parent
= topsect
;
472 p
->private_data
= sect
;
474 html_file_section(&conf
, &files
, sect
, d
);
476 sect
->fragment
= html_format(p
, conf
.template_fragment
);
477 html_sanitise_fragment(sect
->fragment
);
478 /* FIXME: clash checking? add to a tree of (file,frag)? */
482 sect
= html_new_sect(§s
, NULL
);
483 sect
->fragment
= dupstr("Index"); /* FIXME: this _can't_ be right */
486 sect
->parent
= topsect
;
487 html_file_section(&conf
, &files
, sect
, 0); /* peer of chapters */
488 files
.index
= sect
->file
;
492 * Go through the keyword list and sort out fragment IDs for
493 * all the potentially referenced paragraphs which _aren't_
501 for (i
= 0; (kw
= index234(keywords
->keys
, i
)) != NULL
; i
++) {
502 paragraph
*q
, *p
= kw
->para
;
504 if (!is_heading_type(p
->type
)) {
508 * Find the paragraph's parent htmlsect, to
509 * determine which file it will end up in.
514 * Preamble paragraphs have no parent. So if we
515 * have a non-heading with no parent, it must
516 * be preamble, and therefore its parent
517 * htmlsect must be the preamble one.
520 sects
.head
->type
== TOP
);
523 parent
= (htmlsect
*)q
->private_data
;
526 * Now we can construct an htmlsect for this
527 * paragraph itself, taking care to put it in the
528 * list of non-sections rather than the list of
529 * sections (so that traverses of the `sects' list
530 * won't attempt to add it to the contents or
531 * anything weird like that).
533 sect
= html_new_sect(&nonsects
, p
);
534 sect
->file
= parent
->file
;
535 sect
->parent
= parent
;
536 p
->private_data
= sect
;
539 * FIXME: We need a much better means of naming
540 * these, possibly involving an additional
541 * configuration template. For the moment I'll just
542 * invent something completely stupid.
544 sect
->fragment
= snewn(40, char);
545 sprintf(sect
->fragment
, "frag%p", sect
);
551 * Now sort out the index. This involves:
553 * - For each index term, we set up an htmlindex structure to
554 * store all the references to that term.
556 * - Then we make a pass over the actual document, finding
557 * every word_IndexRef; for each one, we actually figure out
558 * the HTML filename/fragment pair we will use to reference
559 * it, store that information in the private data field of
560 * the word_IndexRef itself (so we can recreate it when the
561 * time comes to output our HTML), and add a reference to it
562 * to the index term in question.
571 * Set up the htmlindex structures.
574 for (i
= 0; (entry
= index234(idx
->entries
, i
)) != NULL
; i
++) {
575 htmlindex
*hi
= snew(htmlindex
);
577 hi
->nrefs
= hi
->refsize
= 0;
580 entry
->backend_data
= hi
;
584 * Run over the document inventing fragments. Each fragment
585 * is of the form `i' followed by an integer.
587 * FIXME: Probably in the file-organisation pass we should
588 * work out the fragment names of every section, so that we
589 * could load them all into a tree and hence ensure these
590 * index fragments don't clash with them.
593 for (p
= sourceform
; p
; p
= p
->next
) {
594 if (is_heading_type(p
->type
))
595 lastsect
= (htmlsect
*)p
->private_data
;
597 for (w
= p
->words
; w
; w
= w
->next
)
598 if (w
->type
== word_IndexRef
) {
599 htmlindexref
*hr
= snew(htmlindexref
);
603 hr
->section
= lastsect
;
604 /* FIXME: clash checking */
608 lastsect
->file
->last_fragment_number
++);
609 hr
->fragment
= dupstr(buf
);
611 w
->private_data
= hr
;
613 tag
= index_findtag(idx
, w
->text
);
617 for (i
= 0; i
< tag
->nrefs
; i
++) {
618 indexentry
*entry
= tag
->refs
[i
];
619 htmlindex
*hi
= (htmlindex
*)entry
->backend_data
;
621 if (hi
->nrefs
>= hi
->refsize
) {
623 hi
->refs
= sresize(hi
->refs
, hi
->refsize
, word
*);
626 hi
->refs
[hi
->nrefs
++] = w
;
633 * Now we're ready to write out the actual HTML files.
637 * - we open that file and write its header
638 * - we run down the list of sections
639 * - for each section directly contained within that file, we
640 * output the section text
641 * - for each section which is not in the file but which has a
642 * parent that is, we output a contents entry for the
643 * section if appropriate
644 * - finally, we output the file trailer and close the file.
653 for (f
= files
.head
; f
; f
= f
->next
) {
656 enum LISTTYPE
{ NOLIST
, UL
, OL
, DL
};
657 enum ITEMTYPE
{ NOITEM
, LI
, DT
, DD
};
658 struct stackelement
{
659 struct stackelement
*next
;
660 enum LISTTYPE listtype
;
661 enum ITEMTYPE itemtype
;
664 #define listname(lt) ( (lt)==UL ? "ul" : (lt)==OL ? "ol" : "dl" )
665 #define itemname(lt) ( (lt)==LI ? "li" : (lt)==DT ? "dt" : "dd" )
667 ho
.fp
= fopen(f
->filename
, "w");
668 ho
.charset
= conf
.output_charset
;
669 ho
.cstate
= charset_init_state
;
670 ho
.ver
= conf
.htmlver
;
671 ho
.state
= HO_NEUTRAL
;
672 ho
.contents_level
= 0;
675 switch (conf
.htmlver
) {
677 fprintf(ho
.fp
, "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD "
678 "HTML 3.2 Final//EN\">\n");
681 fprintf(ho
.fp
, "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML"
682 " 4.01//EN\"\n\"http://www.w3.org/TR/html4/"
685 case XHTML_1_0_TRANSITIONAL
:
686 /* FIXME: <?xml?> to specify character encoding.
687 * This breaks HTML backwards compat, so perhaps avoid, or
688 * perhaps only emit when not using the default UTF-8? */
689 fprintf(ho
.fp
, "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML"
690 " 1.0 Transitional//EN\"\n\"http://www.w3.org/TR/"
691 "xhtml1/DTD/xhtml1-transitional.dtd\">\n");
693 case XHTML_1_0_STRICT
:
694 /* FIXME: <?xml?> to specify character encoding. */
695 fprintf(ho
.fp
, "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML"
696 " 1.0 Strict//EN\"\n\"http://www.w3.org/TR/xhtml1/"
697 "DTD/xhtml1-strict.dtd\">\n");
701 element_open(&ho
, "html");
702 if (is_xhtml(conf
.htmlver
)) {
703 element_attr(&ho
, "xmlns", "http://www.w3.org/1999/xhtml");
707 element_open(&ho
, "head");
710 element_empty(&ho
, "meta");
711 element_attr(&ho
, "http-equiv", "content-type");
714 sprintf(buf
, "text/html; charset=%.150s",
715 charset_to_mimeenc(conf
.output_charset
));
716 element_attr(&ho
, "content", buf
);
721 element_empty(&ho
, "meta");
722 element_attr(&ho
, "name", "author");
723 element_attr_w(&ho
, "content", conf
.author
);
727 if (conf
.description
) {
728 element_empty(&ho
, "meta");
729 element_attr(&ho
, "name", "description");
730 element_attr_w(&ho
, "content", conf
.description
);
734 element_open(&ho
, "title");
735 if (f
->first
&& f
->first
->title
) {
736 html_words(&ho
, f
->first
->title
->words
, NOTHING
,
740 if (f
->last
!= f
->first
&& f
->last
->title
) {
741 html_text(&ho
, L
" - "); /* FIXME: configurable? */
742 html_words(&ho
, f
->last
->title
->words
, NOTHING
,
746 element_close(&ho
, "title");
750 html_raw(&ho
, conf
.head_end
);
752 element_close(&ho
, "head");
755 /* FIXME: need to be able to specify replacement for this */
757 html_raw(&ho
, conf
.body_tag
);
759 element_open(&ho
, "body");
763 html_raw(&ho
, conf
.body_start
);
766 * Write out a nav bar. Special case: we don't do this
767 * if there is only one file.
769 if (files
.head
!= files
.tail
) {
770 element_open(&ho
, "p");
772 html_raw_as_attr(&ho
, conf
.nav_attr
);
775 element_open(&ho
, "a");
776 element_attr(&ho
, "href", prevf
->filename
);
778 html_text(&ho
, L
"Previous");/* FIXME: conf? */
780 element_close(&ho
, "a");
782 html_text(&ho
, L
" | "); /* FIXME: conf? */
784 if (f
!= files
.head
) {
785 element_open(&ho
, "a");
786 element_attr(&ho
, "href", files
.head
->filename
);
788 html_text(&ho
, L
"Contents");/* FIXME: conf? */
790 element_close(&ho
, "a");
792 html_text(&ho
, L
" | "); /* FIXME: conf? */
794 if (f
!= files
.index
) {
795 element_open(&ho
, "a");
796 element_attr(&ho
, "href", files
.index
->filename
);
798 html_text(&ho
, L
"Index");/* FIXME: conf? */
799 if (f
!= files
.index
)
800 element_close(&ho
, "a");
802 html_text(&ho
, L
" | "); /* FIXME: conf? */
805 element_open(&ho
, "a");
806 element_attr(&ho
, "href", f
->next
->filename
);
808 html_text(&ho
, L
"Next"); /* FIXME: conf? */
810 element_close(&ho
, "a");
812 element_close(&ho
, "p");
818 * Write out a prefix TOC for the file.
820 * We start by going through the section list and
821 * collecting the sections which need to be added to
822 * the contents. On the way, we also test to see if
823 * this file is a leaf file (defined as one which
824 * contains all descendants of any section it
825 * contains), because this will play a part in our
826 * decision on whether or not to _output_ the TOC.
828 * Special case: we absolutely do not do this if we're
829 * in single-file mode.
831 if (files
.head
!= files
.tail
) {
832 int ntoc
= 0, tocsize
= 0;
833 htmlsect
**toc
= NULL
;
836 for (s
= sects
.head
; s
; s
= s
->next
) {
841 * Search up from this section until we find
842 * the highest-level one which belongs in this
847 for (ac
= s
; ac
; ac
= ac
->parent
) {
855 if (s
->file
!= f
&& a
!= NULL
)
859 if (adepth
<= a
->contents_depth
) {
860 if (ntoc
>= tocsize
) {
862 toc
= sresize(toc
, tocsize
, htmlsect
*);
869 if (leaf
&& conf
.leaf_contains_contents
&&
870 ntoc
>= conf
.leaf_smallest_contents
) {
873 for (i
= 0; i
< ntoc
; i
++) {
874 htmlsect
*s
= toc
[i
];
875 int hlevel
= (s
->type
== TOP ?
-1 :
876 s
->type
== INDEX ?
0 :
877 heading_depth(s
->title
))
878 - f
->min_heading_depth
+ 1;
881 html_contents_entry(&ho
, hlevel
, s
,
884 html_contents_entry(&ho
, 0, NULL
, f
, keywords
, &conf
);
889 * Now go through the document and output some real
893 for (s
= sects
.head
; s
; s
= s
->next
) {
896 * This section belongs in this file.
907 * Search up from this section until we find
908 * the highest-level one which belongs in this
913 for (ac
= s
; ac
; ac
= ac
->parent
) {
923 * This section does not belong in this
924 * file, but an ancestor of it does. Write
925 * out a contents table entry, if the depth
926 * doesn't exceed the maximum contents
927 * depth for the ancestor section.
929 if (adepth
<= a
->contents_depth
) {
930 html_contents_entry(&ho
, adepth
, s
,
940 html_contents_entry(&ho
, 0, NULL
, f
, keywords
, &conf
);
943 * Display the section heading.
946 hlevel
= (s
->type
== TOP ?
-1 :
947 s
->type
== INDEX ?
0 :
948 heading_depth(s
->title
))
949 - f
->min_heading_depth
+ 1;
951 /* HTML headings only go up to <h6> */
955 htag
[1] = '0' + hlevel
;
957 element_open(&ho
, htag
);
960 * Provide anchor for cross-links to target.
962 * FIXME: AIcurrentlyUI, this needs to be done
963 * differently in XHTML because <a name> is
964 * deprecated or obsolete.
966 * (Also we'll have to do this separately in
967 * other paragraph types - NumberedList and
970 element_open(&ho
, "a");
971 element_attr(&ho
, "name", s
->fragment
);
972 element_close(&ho
, "a");
974 html_section_title(&ho
, s
, f
, keywords
, &conf
);
976 element_close(&ho
, htag
);
979 * Now display the section text.
982 stackhead
= snew(struct stackelement
);
983 stackhead
->next
= NULL
;
984 stackhead
->listtype
= NOLIST
;
985 stackhead
->itemtype
= NOITEM
;
987 for (p
= s
->text
;; p
= p
->next
) {
988 enum LISTTYPE listtype
;
989 struct stackelement
*se
;
992 * Preliminary switch to figure out what
993 * sort of list we expect to be inside at
996 * Since p may still be NULL at this point,
997 * I invent a harmless paragraph type for
1000 switch (p ? p
->type
: para_Normal
) {
1003 case para_Copyright
:
1004 case para_BiblioCited
:
1006 case para_QuotePush
:
1010 case para_UnnumberedChapter
:
1021 case para_NumberedList
:
1025 case para_DescribedThing
:
1026 case para_Description
:
1030 case para_LcontPush
:
1031 se
= snew(struct stackelement
);
1032 se
->next
= stackhead
;
1033 se
->listtype
= NOLIST
;
1034 se
->itemtype
= NOITEM
;
1038 default: /* some totally non-printing para */
1045 * Terminate the most recent list item, if
1046 * any. (We left this until after
1047 * processing LcontPush, since in that case
1048 * the list item won't want to be
1049 * terminated until after the corresponding
1052 if (stackhead
->itemtype
!= NOITEM
) {
1053 element_close(&ho
, itemname(stackhead
->itemtype
));
1056 stackhead
->itemtype
= NOITEM
;
1059 * Terminate the current list, if it's not
1060 * the one we want to be in.
1062 if (listtype
!= stackhead
->listtype
&&
1063 stackhead
->listtype
!= NOLIST
) {
1064 element_close(&ho
, listname(stackhead
->listtype
));
1069 * Leave the loop if our time has come.
1071 if (!p
|| (is_heading_type(p
->type
) &&
1072 p
->type
!= para_Title
))
1073 break; /* end of section text */
1076 * Start a fresh list if necessary.
1078 if (listtype
!= stackhead
->listtype
&&
1080 element_open(&ho
, listname(listtype
));
1082 stackhead
->listtype
= listtype
;
1086 element_empty(&ho
, "hr");
1089 html_codepara(&ho
, p
->words
);
1092 case para_Copyright
:
1093 element_open(&ho
, "p");
1095 html_words(&ho
, p
->words
, ALL
,
1096 f
, keywords
, &conf
);
1098 element_close(&ho
, "p");
1100 case para_BiblioCited
:
1101 element_open(&ho
, "p");
1102 if (p
->private_data
) {
1103 htmlsect
*s
= (htmlsect
*)p
->private_data
;
1104 element_open(&ho
, "a");
1105 element_attr(&ho
, "name", s
->fragment
);
1106 element_close(&ho
, "a");
1109 html_words(&ho
, p
->kwtext
, ALL
,
1110 f
, keywords
, &conf
);
1111 html_text(&ho
, L
" ");
1112 html_words(&ho
, p
->words
, ALL
,
1113 f
, keywords
, &conf
);
1115 element_close(&ho
, "p");
1118 case para_NumberedList
:
1119 element_open(&ho
, "li");
1120 if (p
->private_data
) {
1121 htmlsect
*s
= (htmlsect
*)p
->private_data
;
1122 element_open(&ho
, "a");
1123 element_attr(&ho
, "name", s
->fragment
);
1124 element_close(&ho
, "a");
1127 stackhead
->itemtype
= LI
;
1128 html_words(&ho
, p
->words
, ALL
,
1129 f
, keywords
, &conf
);
1131 case para_DescribedThing
:
1132 element_open(&ho
, "dt");
1134 stackhead
->itemtype
= DT
;
1135 html_words(&ho
, p
->words
, ALL
,
1136 f
, keywords
, &conf
);
1138 case para_Description
:
1139 element_open(&ho
, "dd");
1141 stackhead
->itemtype
= DD
;
1142 html_words(&ho
, p
->words
, ALL
,
1143 f
, keywords
, &conf
);
1146 case para_QuotePush
:
1147 element_open(&ho
, "blockquote");
1150 element_close(&ho
, "blockquote");
1155 stackhead
= stackhead
->next
;
1162 assert(stackhead
&& !stackhead
->next
);
1166 if (s
->type
== INDEX
) {
1171 * This section is the index. I'll just
1172 * render it as a single paragraph, with a
1173 * colon between the index term and the
1174 * references, and <br> in between each
1177 element_open(&ho
, "p");
1179 for (i
= 0; (entry
=
1180 index234(idx
->entries
, i
)) != NULL
; i
++) {
1181 htmlindex
*hi
= (htmlindex
*)entry
->backend_data
;
1185 element_empty(&ho
, "br");
1188 html_words(&ho
, entry
->text
, MARKUP
|LINKS
,
1189 f
, keywords
, &conf
);
1191 html_text(&ho
, L
": ");/* FIXME: configurable */
1193 for (j
= 0; j
< hi
->nrefs
; j
++) {
1195 (htmlindexref
*)hi
->refs
[j
]->private_data
;
1196 paragraph
*p
= hr
->section
->title
;
1199 html_text(&ho
, L
", "); /* FIXME: conf */
1201 html_href(&ho
, f
, hr
->section
->file
,
1204 html_words(&ho
, p
->kwtext
, MARKUP
|LINKS
,
1205 f
, keywords
, &conf
);
1206 else if (p
&& p
->words
)
1207 html_words(&ho
, p
->words
, MARKUP
|LINKS
,
1208 f
, keywords
, &conf
);
1210 html_text(&ho
, L
"FIXME");
1211 element_close(&ho
, "a");
1214 element_close(&ho
, "p");
1219 html_contents_entry(&ho
, 0, NULL
, f
, keywords
, &conf
);
1226 int done_version_ids
= FALSE
;
1228 element_empty(&ho
, "hr");
1231 html_raw(&ho
, conf
.body_end
);
1233 if (conf
.address_section
) {
1234 element_open(&ho
, "address");
1235 if (conf
.addr_start
) {
1236 html_raw(&ho
, conf
.addr_start
);
1239 if (conf
.visible_version_id
) {
1240 int started
= FALSE
;
1241 for (p
= sourceform
; p
; p
= p
->next
)
1242 if (p
->type
== para_VersionID
) {
1244 element_open(&ho
, "p");
1246 element_empty(&ho
, "br");
1248 html_text(&ho
, L
"["); /* FIXME: conf? */
1249 html_words(&ho
, p
->words
, NOTHING
,
1250 f
, keywords
, &conf
);
1251 html_text(&ho
, L
"]"); /* FIXME: conf? */
1255 element_close(&ho
, "p");
1256 done_version_ids
= TRUE
;
1259 html_raw(&ho
, conf
.addr_end
);
1260 element_close(&ho
, "address");
1263 if (!done_version_ids
) {
1265 * If the user didn't want the version IDs
1266 * visible, I think we still have a duty to put
1267 * them in an HTML comment.
1269 int started
= FALSE
;
1270 for (p
= sourceform
; p
; p
= p
->next
)
1271 if (p
->type
== para_VersionID
) {
1273 html_raw(&ho
, "<!-- version IDs:\n");
1276 html_words(&ho
, p
->words
, NOTHING
,
1277 f
, keywords
, &conf
);
1281 html_raw(&ho
, "-->\n");
1285 element_close(&ho
, "body");
1287 element_close(&ho
, "html");
1294 * FIXME: Figure out a way to free the htmlindex and
1295 * htmlindexref structures.
1299 static void html_file_section(htmlconfig
*cfg
, htmlfilelist
*files
,
1300 htmlsect
*sect
, int depth
)
1306 * `depth' is derived from the heading_depth() macro at the top
1307 * of this file, which counts title as -1, chapter as 0,
1308 * heading as 1 and subsection as 2. However, the semantics of
1309 * cfg->leaf_level are defined to count chapter as 1, heading
1310 * as 2 etc. So first I increment depth :-(
1314 if (cfg
->leaf_level
== 0) {
1316 * leaf_level==0 is a special case, in which everything is
1317 * put into a single file.
1320 files
->single
= html_new_file(files
, cfg
->single_filename
);
1322 file
= files
->single
;
1325 * If the depth of this section is at or above leaf_level,
1326 * we invent a fresh file and put this section at its head.
1327 * Otherwise, we put it in the same file as its parent
1330 if (ldepth
> cfg
->leaf_level
) {
1332 * We know that sect->parent cannot be NULL. The only
1333 * circumstance in which it can be is if sect is at
1334 * chapter or appendix level, i.e. ldepth==1; and if
1335 * that's the case, then we cannot have entered this
1336 * branch unless cfg->leaf_level==0, in which case we
1337 * would be in the single-file case above and not here
1340 assert(sect
->parent
);
1342 file
= sect
->parent
->file
;
1344 if (sect
->type
== TOP
) {
1345 file
= html_new_file(files
, cfg
->contents_filename
);
1346 } else if (sect
->type
== INDEX
) {
1347 file
= html_new_file(files
, cfg
->index_filename
);
1351 assert(ldepth
> 0 && sect
->title
);
1352 title
= html_format(sect
->title
, cfg
->template_filename
);
1353 file
= html_new_file(files
, title
);
1361 if (file
->min_heading_depth
> depth
) {
1363 * This heading is at a higher level than any heading we
1364 * have so far placed in this file; so we set the `first'
1367 file
->min_heading_depth
= depth
;
1371 if (file
->min_heading_depth
== depth
)
1375 static htmlfile
*html_new_file(htmlfilelist
*list
, char *filename
)
1377 htmlfile
*ret
= snew(htmlfile
);
1381 list
->tail
->next
= ret
;
1386 ret
->filename
= dupstr(filename
);
1387 ret
->last_fragment_number
= 0;
1388 ret
->min_heading_depth
= INT_MAX
;
1389 ret
->first
= ret
->last
= NULL
;
1394 static htmlsect
*html_new_sect(htmlsectlist
*list
, paragraph
*title
)
1396 htmlsect
*ret
= snew(htmlsect
);
1400 list
->tail
->next
= ret
;
1413 static void html_words(htmloutput
*ho
, word
*words
, int flags
,
1414 htmlfile
*file
, keywordlist
*keywords
, htmlconfig
*cfg
)
1420 for (w
= words
; w
; w
= w
->next
) switch (w
->type
) {
1421 case word_HyperLink
:
1422 if (flags
& LINKS
) {
1423 element_open(ho
, "a");
1424 c
= utoa_dup(w
->text
, CS_ASCII
);
1425 element_attr(ho
, "href", c
);
1429 case word_UpperXref
:
1430 case word_LowerXref
:
1431 if (flags
& LINKS
) {
1432 keyword
*kwl
= kw_lookup(keywords
, w
->text
);
1433 paragraph
*p
= kwl
->para
;
1434 htmlsect
*s
= (htmlsect
*)p
->private_data
;
1438 html_href(ho
, file
, s
->file
, s
->fragment
);
1444 element_close(ho
, "a");
1447 if (flags
& INDEXENTS
) {
1448 htmlindexref
*hr
= (htmlindexref
*)w
->private_data
;
1449 element_open(ho
, "a");
1450 element_attr(ho
, "name", hr
->fragment
);
1451 element_close(ho
, "a");
1458 case word_WhiteSpace
:
1459 case word_EmphSpace
:
1460 case word_CodeSpace
:
1461 case word_WkCodeSpace
:
1463 case word_EmphQuote
:
1464 case word_CodeQuote
:
1465 case word_WkCodeQuote
:
1466 style
= towordstyle(w
->type
);
1467 type
= removeattr(w
->type
);
1468 if (style
== word_Emph
&&
1469 (attraux(w
->aux
) == attr_First
||
1470 attraux(w
->aux
) == attr_Only
) &&
1472 element_open(ho
, "em");
1473 else if ((style
== word_Code
|| style
== word_WeakCode
) &&
1474 (attraux(w
->aux
) == attr_First
||
1475 attraux(w
->aux
) == attr_Only
) &&
1477 element_open(ho
, "code");
1479 if (type
== word_WhiteSpace
)
1480 html_text(ho
, L
" ");
1481 else if (type
== word_Quote
) {
1482 if (quoteaux(w
->aux
) == quote_Open
)
1483 html_text(ho
, cfg
->lquote
);
1485 html_text(ho
, cfg
->rquote
);
1487 if (cvt_ok(ho
->charset
, w
->text
) || !w
->alt
)
1488 html_text(ho
, w
->text
);
1490 html_words(ho
, w
->alt
, flags
, file
, keywords
, cfg
);
1493 if (style
== word_Emph
&&
1494 (attraux(w
->aux
) == attr_Last
||
1495 attraux(w
->aux
) == attr_Only
) &&
1497 element_close(ho
, "em");
1498 else if ((style
== word_Code
|| style
== word_WeakCode
) &&
1499 (attraux(w
->aux
) == attr_Last
||
1500 attraux(w
->aux
) == attr_Only
) &&
1502 element_close(ho
, "code");
1508 static void html_codepara(htmloutput
*ho
, word
*words
)
1510 element_open(ho
, "pre");
1511 element_open(ho
, "code");
1512 for (; words
; words
= words
->next
) if (words
->type
== word_WeakCode
) {
1517 if (words
->next
&& words
->next
->type
== word_Emph
) {
1518 e
= words
->next
->text
;
1519 words
= words
->next
;
1523 while (e
&& *e
&& *t
) {
1527 for (n
= 0; t
[n
] && e
[n
] && e
[n
] == ec
; n
++);
1535 element_open(ho
, open_tag
);
1537 html_text_limit(ho
, t
, n
);
1540 element_close(ho
, open_tag
);
1548 element_close(ho
, "code");
1549 element_close(ho
, "pre");
1552 static void html_charset_cleanup(htmloutput
*ho
)
1557 bytes
= charset_from_unicode(NULL
, NULL
, outbuf
, lenof(outbuf
),
1558 ho
->charset
, &ho
->cstate
, NULL
);
1560 fwrite(outbuf
, 1, bytes
, ho
->fp
);
1563 static void return_to_neutral(htmloutput
*ho
)
1565 if (ho
->state
== HO_IN_TEXT
) {
1566 html_charset_cleanup(ho
);
1567 } else if (ho
->state
== HO_IN_EMPTY_TAG
&& is_xhtml(ho
->ver
)) {
1568 fprintf(ho
->fp
, " />");
1569 } else if (ho
->state
== HO_IN_EMPTY_TAG
|| ho
->state
== HO_IN_TAG
) {
1570 fprintf(ho
->fp
, ">");
1573 ho
->state
= HO_NEUTRAL
;
1576 static void element_open(htmloutput
*ho
, char const *name
)
1578 return_to_neutral(ho
);
1579 fprintf(ho
->fp
, "<%s", name
);
1580 ho
->state
= HO_IN_TAG
;
1583 static void element_close(htmloutput
*ho
, char const *name
)
1585 return_to_neutral(ho
);
1586 fprintf(ho
->fp
, "</%s>", name
);
1587 ho
->state
= HO_NEUTRAL
;
1590 static void element_empty(htmloutput
*ho
, char const *name
)
1592 return_to_neutral(ho
);
1593 fprintf(ho
->fp
, "<%s", name
);
1594 ho
->state
= HO_IN_EMPTY_TAG
;
1597 static void html_nl(htmloutput
*ho
)
1599 return_to_neutral(ho
);
1600 fputc('\n', ho
->fp
);
1603 static void html_raw(htmloutput
*ho
, char *text
)
1605 return_to_neutral(ho
);
1606 fputs(text
, ho
->fp
);
1609 static void html_raw_as_attr(htmloutput
*ho
, char *text
)
1611 assert(ho
->state
== HO_IN_TAG
|| ho
->state
== HO_IN_EMPTY_TAG
);
1613 fputs(text
, ho
->fp
);
1616 static void element_attr(htmloutput
*ho
, char const *name
, char const *value
)
1618 html_charset_cleanup(ho
);
1619 assert(ho
->state
== HO_IN_TAG
|| ho
->state
== HO_IN_EMPTY_TAG
);
1620 fprintf(ho
->fp
, " %s=\"%s\"", name
, value
);
1623 static void element_attr_w(htmloutput
*ho
, char const *name
,
1624 wchar_t const *value
)
1626 html_charset_cleanup(ho
);
1627 fprintf(ho
->fp
, " %s=\"", name
);
1628 html_text_limit_internal(ho
, value
, 0, TRUE
);
1629 html_charset_cleanup(ho
);
1633 static void html_text(htmloutput
*ho
, wchar_t const *text
)
1635 html_text_limit(ho
, text
, 0);
1638 static void html_text_limit(htmloutput
*ho
, wchar_t const *text
, int maxlen
)
1640 return_to_neutral(ho
);
1641 html_text_limit_internal(ho
, text
, maxlen
, FALSE
);
1644 static void html_text_limit_internal(htmloutput
*ho
, wchar_t const *text
,
1645 int maxlen
, int quote_quotes
)
1647 int textlen
= ustrlen(text
);
1651 if (maxlen
> 0 && textlen
> maxlen
)
1654 while (textlen
> 0) {
1655 /* Scan ahead for characters we really can't display in HTML. */
1656 int lenbefore
, lenafter
;
1657 for (lenbefore
= 0; lenbefore
< textlen
; lenbefore
++)
1658 if (text
[lenbefore
] == L
'<' ||
1659 text
[lenbefore
] == L
'>' ||
1660 text
[lenbefore
] == L
'&' ||
1661 (text
[lenbefore
] == L
'"' && quote_quotes
))
1663 lenafter
= lenbefore
;
1664 bytes
= charset_from_unicode(&text
, &lenafter
, outbuf
, lenof(outbuf
),
1665 ho
->charset
, &ho
->cstate
, &err
);
1666 textlen
-= (lenbefore
- lenafter
);
1668 fwrite(outbuf
, 1, bytes
, ho
->fp
);
1671 * We have encountered a character that cannot be
1672 * displayed in the selected output charset. Therefore,
1673 * we use an HTML numeric entity reference.
1675 assert(textlen
> 0);
1676 fprintf(ho
->fp
, "&#%ld;", (long int)*text
);
1678 } else if (lenafter
== 0 && textlen
> 0) {
1680 * We have encountered a character which is special to
1684 fprintf(ho
->fp
, "<");
1685 else if (*text
== L
'>')
1686 fprintf(ho
->fp
, ">");
1687 else if (*text
== L
'&')
1688 fprintf(ho
->fp
, "&");
1689 else if (*text
== L
'"')
1690 fprintf(ho
->fp
, """);
1692 assert(!"Can't happen");
1698 static void cleanup(htmloutput
*ho
)
1700 return_to_neutral(ho
);
1704 static void html_href(htmloutput
*ho
, htmlfile
*thisfile
,
1705 htmlfile
*targetfile
, char *targetfrag
)
1707 rdstringc rs
= { 0, 0, NULL
};
1710 if (targetfile
!= thisfile
)
1711 rdaddsc(&rs
, targetfile
->filename
);
1714 rdaddsc(&rs
, targetfrag
);
1718 element_open(ho
, "a");
1719 element_attr(ho
, "href", url
);
1723 static char *html_format(paragraph
*p
, char *template_string
)
1727 wchar_t *ws
, wsbuf
[2];
1728 rdstringc rs
= { 0, 0, NULL
};
1730 t
= template_string
;
1732 if (*t
== '%' && t
[1]) {
1746 if (p
->kwtext
&& fmt
== 'n')
1748 else if (p
->kwtext2
&& fmt
== 'b') {
1750 * HTML fragment names must start with a letter, so
1751 * simply `1.2.3' is not adequate. In this case I'm
1752 * going to cheat slightly by prepending the first
1753 * character of the first word of kwtext, so that
1754 * we get `C1' for chapter 1, `S2.3' for section
1757 if (p
->kwtext
&& p
->kwtext
->text
[0]) {
1760 wsbuf
[0] = p
->kwtext
->text
[0];
1763 } else if (p
->keyword
&& *p
->keyword
&& fmt
== 'k')
1769 c
= utoa_dup(ws
, CS_ASCII
);
1775 if (removeattr(w
->type
) == word_Normal
) {
1776 c
= utoa_dup(w
->text
, CS_ASCII
);
1787 return rdtrimc(&rs
);
1790 static void html_sanitise_fragment(char *text
)
1793 * The HTML 4 spec's strictest definition of fragment names (<a
1794 * name> and "id" attributes) says that they `must begin with a
1795 * letter and may be followed by any number of letters, digits,
1796 * hyphens, underscores, colons, and periods'.
1798 * So here we unceremoniously rip out any characters not
1799 * conforming to this limitation.
1801 char *p
= text
, *q
= text
;
1803 while (*p
&& !((*p
>='A' && *p
<='Z') || (*p
>='a' && *p
<='z')))
1808 if ((*p
>='A' && *p
<='Z') ||
1809 (*p
>='a' && *p
<='z') ||
1810 (*p
>='0' && *p
<='9') ||
1811 *p
=='-' || *p
=='_' || *p
==':' || *p
=='.')
1819 static void html_contents_entry(htmloutput
*ho
, int depth
, htmlsect
*s
,
1820 htmlfile
*thisfile
, keywordlist
*keywords
,
1823 while (ho
->contents_level
> depth
) {
1824 element_close(ho
, "ul");
1825 ho
->contents_level
--;
1828 while (ho
->contents_level
< depth
) {
1829 element_open(ho
, "ul");
1830 ho
->contents_level
++;
1836 element_open(ho
, "li");
1837 html_href(ho
, thisfile
, s
->file
, s
->fragment
);
1838 html_section_title(ho
, s
, thisfile
, keywords
, cfg
);
1839 element_close(ho
, "a");
1840 element_close(ho
, "li");
1843 static void html_section_title(htmloutput
*ho
, htmlsect
*s
, htmlfile
*thisfile
,
1844 keywordlist
*keywords
, htmlconfig
*cfg
)
1849 int depth
= heading_depth(s
->title
);
1853 else if (depth
== 0)
1854 sl
= &cfg
->achapter
;
1855 else if (depth
<= cfg
->nasect
)
1856 sl
= &cfg
->asect
[depth
-1];
1858 sl
= &cfg
->asect
[cfg
->nasect
-1];
1862 else if (sl
->just_numbers
)
1863 number
= s
->title
->kwtext2
;
1865 number
= s
->title
->kwtext
;
1868 html_words(ho
, number
, MARKUP
,
1869 thisfile
, keywords
, cfg
);
1870 html_text(ho
, sl
->number_suffix
);
1873 html_words(ho
, s
->title
->words
, MARKUP
,
1874 thisfile
, keywords
, cfg
);
1876 assert(s
->type
!= NORMAL
);
1878 html_text(ho
, L
"Preamble");/* FIXME: configure */
1879 else if (s
->type
== INDEX
)
1880 html_text(ho
, L
"Index");/* FIXME: configure */