Oops, overzealous search-and-replace
[sgt/halibut] / bk_html.c
index 86abd62..7914024 100644 (file)
--- a/bk_html.c
+++ b/bk_html.c
@@ -267,13 +267,9 @@ static htmlconfig html_configure(paragraph *source) {
                k++;                /* treat `xhtml-' and `html-' the same */
 
            if (!ustricmp(k, L"html-restrict-charset")) {
-               char *csname = utoa_dup(uadv(k), CS_ASCII);
-               ret.restrict_charset = charset_from_localenc(csname);
-               sfree(csname);
+               ret.restrict_charset = charset_from_ustr(&p->fpos, uadv(k));
            } else if (!ustricmp(k, L"html-output-charset")) {
-               char *csname = utoa_dup(uadv(k), CS_ASCII);
-               ret.output_charset = charset_from_localenc(csname);
-               sfree(csname);
+               ret.output_charset = charset_from_ustr(&p->fpos, uadv(k));
            } else if (!ustricmp(k, L"html-version")) {
                wchar_t *vername = uadv(k);
                static const struct {
@@ -468,6 +464,7 @@ void html_backend(paragraph *sourceform, keywordlist *keywords,
     htmlconfig conf;
     htmlfilelist files = { NULL, NULL, NULL, NULL, NULL };
     htmlsectlist sects = { NULL, NULL }, nonsects = { NULL, NULL };
+    int has_index;
 
     IGNORE(unused);
 
@@ -536,16 +533,20 @@ void html_backend(paragraph *sourceform, keywordlist *keywords,
                                                        sect->fragment);
            }
 
-       /* And the index. */
-       sect = html_new_sect(&sects, NULL);
-       sect->text = NULL;
-       sect->type = INDEX;
-       sect->parent = topsect;
-       html_file_section(&conf, &files, sect, 0);   /* peer of chapters */
-       sect->fragment = utoa_dup(conf.index_text, CS_ASCII);
-       sect->fragment = html_sanitise_fragment(&files, sect->file,
-                                               sect->fragment);
-       files.index = sect->file;
+       /* And the index, if we have one. */
+       has_index = (count234(idx->entries) > 0);
+       if (has_index) {
+           sect = html_new_sect(&sects, NULL);
+           sect->text = NULL;
+           sect->type = INDEX;
+           sect->parent = topsect;
+            sect->contents_depth = 0;
+           html_file_section(&conf, &files, sect, 0);   /* peer of chapters */
+           sect->fragment = utoa_dup(conf.index_text, CS_ASCII);
+           sect->fragment = html_sanitise_fragment(&files, sect->file,
+                                                   sect->fragment);
+           files.index = sect->file;
+       }
     }
 
     /*
@@ -825,6 +826,26 @@ void html_backend(paragraph *sourceform, keywordlist *keywords,
            if (conf.head_end)
                html_raw(&ho, conf.head_end);
 
+           /*
+            * Add any <head> data defined in specific sections
+            * that go in this file. (This is mostly to allow <meta
+            * name="AppleTitle"> tags for Mac online help.)
+            */
+           for (s = sects.head; s; s = s->next) {
+               if (s->file == f && s->text) {
+                   for (p = s->text;
+                        p && (p == s->text || p->type == para_Title ||
+                              !is_heading_type(p->type));
+                        p = p->next) {
+                       if (p->type == para_Config) {
+                           if (!ustricmp(p->keyword, L"html-local-head")) {
+                               html_raw(&ho, adv(p->origkeyword));
+                           }
+                       }
+                   }
+               }
+           }
+
            element_close(&ho, "head");
            html_nl(&ho);
 
@@ -866,13 +887,15 @@ void html_backend(paragraph *sourceform, keywordlist *keywords,
 
                html_text(&ho, conf.nav_separator);
 
-               if (f != files.index) {
-                   element_open(&ho, "a");
-                   element_attr(&ho, "href", files.index->filename);
+               if (has_index) {
+                   if (f != files.index) {
+                       element_open(&ho, "a");
+                       element_attr(&ho, "href", files.index->filename);
+                   }
+                   html_text(&ho, conf.index_text);
+                   if (f != files.index)
+                       element_close(&ho, "a");
                }
-               html_text(&ho, conf.index_text);
-               if (f != files.index)
-                   element_close(&ho, "a");
 
                html_text(&ho, conf.nav_separator);
 
@@ -1602,8 +1625,12 @@ static void html_words(htmloutput *ho, word *words, int flags,
       case word_LowerXref:
        if (flags & LINKS) {
            keyword *kwl = kw_lookup(keywords, w->text);
-           paragraph *p = kwl->para;
-           htmlsect *s = (htmlsect *)p->private_data;
+           paragraph *p;
+           htmlsect *s;
+
+           assert(kwl);
+           p = kwl->para;
+           s = (htmlsect *)p->private_data;
 
            assert(s);
 
@@ -1961,6 +1988,7 @@ static char *html_format(paragraph *p, char *template_string)
            } else if (p->keyword && *p->keyword && fmt == 'k')
                ws = p->keyword;
            else
+               /* %N comes here; also failure cases of other fmts */
                w = p->words;
 
            if (ws) {