New option *-section-shownumber, alongside *-section-numeric and in
authorsimon <simon@cda61777-01e9-0310-a592-d414129be87e>
Mon, 25 Feb 2008 19:36:12 +0000 (19:36 +0000)
committersimon <simon@cda61777-01e9-0310-a592-d414129be87e>
Mon, 25 Feb 2008 19:36:12 +0000 (19:36 +0000)
both the back ends which currently support that, to leave out
chapter and section numbers totally in section headings. Can be
useful for publishing man pages (which don't normally want section
numbers) on the web.

git-svn-id: svn://svn.tartarus.org/sgt/halibut@7892 cda61777-01e9-0310-a592-d414129be87e

bk_html.c
bk_text.c
doc/output.but

index 0c66eb7..96f3083 100644 (file)
--- a/bk_html.c
+++ b/bk_html.c
@@ -37,7 +37,7 @@
                           (p)->type == para_Title ? -1 : 0 )
 
 typedef struct {
-    int just_numbers;
+    int number_at_all, just_numbers;
     wchar_t *number_suffix;
 } sectlevel;
 
@@ -248,10 +248,12 @@ static htmlconfig html_configure(paragraph *source) {
      */
     ret.leaf_level = 2;
     ret.achapter.just_numbers = FALSE;
+    ret.achapter.number_at_all = TRUE;
     ret.achapter.number_suffix = L": ";
     ret.nasect = 1;
     ret.asect = snewn(ret.nasect, sectlevel);
     ret.asect[0].just_numbers = TRUE;
+    ret.achapter.number_at_all = TRUE;
     ret.asect[0].number_suffix = L" ";
     ret.ncdepths = 0;
     ret.contents_depths = 0;
@@ -382,6 +384,8 @@ static htmlconfig html_configure(paragraph *source) {
                    error(err_cfginsufarg, &p->fpos, p->origkeyword, 1);
            } else if (!ustricmp(k, L"html-chapter-numeric")) {
                ret.achapter.just_numbers = utob(uadv(k));
+           } else if (!ustricmp(k, L"html-chapter-shownumber")) {
+               ret.achapter.number_at_all = utob(uadv(k));
            } else if (!ustricmp(k, L"html-suppress-navlinks")) {
                ret.navlinks = !utob(uadv(k));
            } else if (!ustricmp(k, L"html-rellinks")) {
@@ -411,6 +415,21 @@ static htmlconfig html_configure(paragraph *source) {
                    ret.nasect = n+1;
                }
                ret.asect[n].just_numbers = utob(q);
+           } else if (!ustricmp(k, L"html-section-shownumber")) {
+               wchar_t *q = uadv(k);
+               int n = 0;
+               if (uisdigit(*q)) {
+                   n = utoi(q);
+                   q = uadv(q);
+               }
+               if (n >= ret.nasect) {
+                   int i;
+                   ret.asect = sresize(ret.asect, n+1, sectlevel);
+                   for (i = ret.nasect; i <= n; i++)
+                       ret.asect[i] = ret.asect[ret.nasect-1];
+                   ret.nasect = n+1;
+               }
+               ret.asect[n].number_at_all = utob(q);
            } else if (!ustricmp(k, L"html-section-suffix")) {
                wchar_t *q = uadv(k);
                int n = 0;
@@ -2766,7 +2785,7 @@ static void html_section_title(htmloutput *ho, htmlsect *s, htmlfile *thisfile,
        else
            sl = &cfg->asect[cfg->nasect-1];
 
-       if (!sl)
+       if (!sl || !sl->number_at_all)
            number = NULL;
        else if (sl->just_numbers)
            number = s->title->kwtext2;
index 6df426e..1a1796e 100644 (file)
--- a/bk_text.c
+++ b/bk_text.c
@@ -10,7 +10,7 @@
 typedef enum { LEFT, LEFTPLUS, CENTRE } alignment;
 typedef struct {
     alignment align;
-    int just_numbers;
+    int number_at_all, just_numbers;
     wchar_t *underline;
     wchar_t *number_suffix;
 } alignstruct;
@@ -67,6 +67,7 @@ static textconfig text_configure(paragraph *source) {
     ret.bullet.alt = NULL;
     ret.bullet.type = word_Normal;
     ret.atitle.just_numbers = FALSE;   /* ignored */
+    ret.atitle.number_at_all = TRUE;   /* ignored */
 
     /*
      * Defaults.
@@ -80,12 +81,14 @@ static textconfig text_configure(paragraph *source) {
     ret.atitle.underline = L"\x2550\0=\0\0";
     ret.achapter.align = LEFT;
     ret.achapter.just_numbers = FALSE;
+    ret.achapter.number_at_all = TRUE;
     ret.achapter.number_suffix = L": ";
     ret.achapter.underline = L"\x203E\0-\0\0";
     ret.nasect = 1;
     ret.asect = snewn(ret.nasect, alignstruct);
     ret.asect[0].align = LEFTPLUS;
     ret.asect[0].just_numbers = TRUE;
+    ret.asect[0].number_at_all = TRUE;
     ret.asect[0].number_suffix = L" ";
     ret.asect[0].underline = L"\0";
     ret.include_version_id = TRUE;
@@ -144,6 +147,8 @@ static textconfig text_configure(paragraph *source) {
                ret.achapter.underline = uadv(p->keyword);
            } else if (!ustricmp(p->keyword, L"text-chapter-numeric")) {
                ret.achapter.just_numbers = utob(uadv(p->keyword));
+           } else if (!ustricmp(p->keyword, L"text-chapter-shownumber")) {
+               ret.achapter.number_at_all = utob(uadv(p->keyword));
            } else if (!ustricmp(p->keyword, L"text-chapter-suffix")) {
                ret.achapter.number_suffix = uadv(p->keyword);
            } else if (!ustricmp(p->keyword, L"text-section-align")) {
@@ -191,6 +196,21 @@ static textconfig text_configure(paragraph *source) {
                    ret.nasect = n+1;
                }
                ret.asect[n].just_numbers = utob(q);
+           } else if (!ustricmp(p->keyword, L"text-section-shownumber")) {
+               wchar_t *q = uadv(p->keyword);
+               int n = 0;
+               if (uisdigit(*q)) {
+                   n = utoi(q);
+                   q = uadv(q);
+               }
+               if (n >= ret.nasect) {
+                   int i;
+                   ret.asect = sresize(ret.asect, n+1, alignstruct);
+                   for (i = ret.nasect; i <= n; i++)
+                       ret.asect[i] = ret.asect[ret.nasect-1];
+                   ret.nasect = n+1;
+               }
+               ret.asect[n].number_at_all = utob(q);
            } else if (!ustricmp(p->keyword, L"text-section-suffix")) {
                wchar_t *q = uadv(p->keyword);
                int n = 0;
@@ -615,12 +635,14 @@ static void text_heading(textfile *tf, word *tprefix, word *nprefix,
     int firstlinewidth, wrapwidth;
     wrappedline *wrapping, *p;
 
-    if (align.just_numbers && nprefix) {
-       text_rdaddw(&t, nprefix, NULL, cfg);
-       rdadds(&t, align.number_suffix);
-    } else if (!align.just_numbers && tprefix) {
-       text_rdaddw(&t, tprefix, NULL, cfg);
-       rdadds(&t, align.number_suffix);
+    if (align.number_at_all) {
+       if (align.just_numbers && nprefix) {
+           text_rdaddw(&t, nprefix, NULL, cfg);
+           rdadds(&t, align.number_suffix);
+       } else if (!align.just_numbers && tprefix) {
+           text_rdaddw(&t, tprefix, NULL, cfg);
+           rdadds(&t, align.number_suffix);
+       }
     }
     margin = length = ustrwid(t.text ? t.text : L"", cfg->charset);
 
index 9a9d535..3d9783b 100644 (file)
@@ -142,6 +142,14 @@ they will just contain the chapter \e{number}, followed by the
 chapter title. If you set this to \c{false}, chapter headings will
 be prefixed by \q{Chapter} or equivalent.
 
+\dt \I{\cw{\\cfg\{text-chapter-shownumber\}}}\cw{\\cfg\{text-chapter-shownumber\}\{}\e{boolean}\cw{\}}
+
+\dd If this is set to \c{false}, then chapter headings will \e{only}
+contain the chapter title: they will not contain the word
+\q{Chapter} (or whatever other word you have defined in its place),
+and neither will they contain the chapter number. If set to
+\c{false}, this overrides \cw{\\cfg\{text-chapter-numeric\}}.
+
 \dt \I{\cw{\\cfg\{text-chapter-suffix\}}}\cw{\\cfg\{text-chapter-suffix\}\{}\e{text}\cw{\}}
 
 \dd This specifies the suffix text to be appended to the chapter
@@ -168,6 +176,15 @@ just like the other alignment directives listed above.
 contain the word \q{Section} or equivalent (if \c{false}), or should
 be numeric only (if \c{true}).
 
+\dt \I{\cw{\\cfg\{text-section-shownumber\}}}\cw{\\cfg\{text-section-shownumber\}\{}\e{level}\cw{\}\{}\e{boolean}\cw{\}}
+
+\dd If this is set to \c{false}, then section headings at the
+specified level will \e{only} contain the section title: they will
+not contain the word \q{Section} (or whatever other word you have
+defined in its place), and neither will they contain the section
+number. If set to \c{false}, this overrides
+\cw{\\cfg\{text-section-numeric\}}.
+
 \dt \I{\cw{\\cfg\{text-section-suffix\}}}\cw{\\cfg\{text-section-suffix\}\{}\e{level}\cw{\}\{}\e{text}\cw{\}}
 
 \dd Specifies the \I{suffix text, in section titles}suffix text to
@@ -296,16 +313,19 @@ The \i{default settings} for Halibut's plain text output format are:
 \c \cfg{text-chapter-align}{left}
 \c \cfg{text-chapter-underline}{\u203e}{-}
 \c \cfg{text-chapter-numeric}{false}
+\c \cfg{text-chapter-shownumber}{true}
 \c \cfg{text-chapter-suffix}{: }
 \c
 \c \cfg{text-section-align}{0}{leftplus}
 \c \cfg{text-section-underline}{0}{}
 \c \cfg{text-section-numeric}{0}{true}
+\c \cfg{text-section-shownumber}{0}{true}
 \c \cfg{text-section-suffix}{0}{ }
 \c
 \c \cfg{text-section-align}{1}{leftplus}
 \c \cfg{text-section-underline}{1}{}
 \c \cfg{text-section-numeric}{1}{true}
+\c \cfg{text-section-shownumber}{1}{true}
 \c \cfg{text-section-suffix}{1}{ }
 \c
 \c ... and so on for all section levels below this ...
@@ -586,6 +606,14 @@ they will just contain the chapter \e{number}, followed by the
 chapter title. If you set this to \c{false}, chapter headings will
 be prefixed by \q{Chapter} or equivalent.
 
+\dt \I{\cw{\\cfg\{html-chapter-shownumber\}}}\cw{\\cfg\{html-chapter-shownumber\}\{}\e{boolean}\cw{\}}
+
+\dd If this is set to \c{false}, then chapter headings will \e{only}
+contain the chapter title: they will not contain the word
+\q{Chapter} (or whatever other word you have defined in its place),
+and neither will they contain the chapter number. If set to
+\c{false}, this overrides \cw{\\cfg\{html-chapter-numeric\}}.
+
 \dt \I{\cw{\\cfg\{html-chapter-suffix\}}}\cw{\\cfg\{html-chapter-suffix\}\{}\e{text}\cw{\}}
 
 \dd This specifies the suffix text to be appended to the chapter
@@ -604,6 +632,15 @@ which level of section headings you want to affect: 0 means
 first-level headings (\c{\\H}), 1 means second-level headings
 (\c{\\S}), 2 means the level below that (\c{\\S2}), and so on.
 
+\dt \I{\cw{\\cfg\{html-section-shownumber\}}}\cw{\\cfg\{html-section-shownumber\}\{}\e{level}\cw{\}\{}\e{boolean}\cw{\}}
+
+\dd If this is set to \c{false}, then section headings at the
+specified level will \e{only} contain the section title: they will
+not contain the word \q{Section} (or whatever other word you have
+defined in its place), and neither will they contain the section
+number. If set to \c{false}, this overrides
+\cw{\\cfg\{html-section-numeric\}}.
+
 \dt \I{\cw{\\cfg\{html-section-suffix\}}}\cw{\\cfg\{html-section-suffix\}\{}\e{level}\cw{\}\{}\e{text}\cw{\}}
 
 \# {level} can be omitted (defaults to 0). Is this intentional?
@@ -946,12 +983,15 @@ The \i{default settings} for Halibut's HTML output format are:
 \c \cfg{html-navigation-attributes}{}
 \c
 \c \cfg{html-chapter-numeric}{false}
+\c \cfg{html-chapter-shownumber}{true}
 \c \cfg{html-chapter-suffix}{: }
 \c
 \c \cfg{html-section-numeric}{0}{true}
+\c \cfg{html-section-shownumber}{0}{true}
 \c \cfg{html-section-suffix}{0}{ }
 \c
 \c \cfg{html-section-numeric}{1}{true}
+\c \cfg{html-section-shownumber}{1}{true}
 \c \cfg{html-section-suffix}{1}{ }
 \c
 \c ... and so on for all section levels below this ...