diff options
| author | Simon Tatham <anakin@pobox.com> | 2004-03-24 19:23:21 +0000 |
|---|---|---|
| committer | Simon Tatham <anakin@pobox.com> | 2004-03-24 19:23:21 +0000 |
| commit | 674cfb5f4f4ed5a7e8df0fe330120784df889bbf (patch) | |
| tree | 0b3523cf589639ac5b8e5c3cb69237acf563af5e /bk_xhtml.c | |
| parent | c2dc0207e325bd3e15929bcf0397e92d5fe33bba (diff) | |
| download | halibut-674cfb5f4f4ed5a7e8df0fe330120784df889bbf.zip halibut-674cfb5f4f4ed5a7e8df0fe330120784df889bbf.tar.gz halibut-674cfb5f4f4ed5a7e8df0fe330120784df889bbf.tar.bz2 halibut-674cfb5f4f4ed5a7e8df0fe330120784df889bbf.tar.xz | |
Cleanups to complete the man page backend. Also, an additional new
markup feature: a \c line in a code paragraph can now be followed by
an optional \e line indicating emphasised bits of its preceding \c.
This allows discretionary bolding and (italic/underline) emphasis
within code paragraphs, but without introducing an escape character
or breaking any existing input files. Users are warned that not all
backends are required to actually render these hints, and so they
should avoid depending on them 100% to convey semantic information
unless they know they're writing for a restricted range of backends.
[originally from svn r3965]
Diffstat (limited to 'bk_xhtml.c')
| -rw-r--r-- | bk_xhtml.c | 61 |
1 files changed, 52 insertions, 9 deletions
@@ -94,7 +94,7 @@ static void xhtml_utostr(wchar_t *, char **); static int xhtml_para_level(paragraph *); static int xhtml_reservedchar(int); -static int xhtml_convert(wchar_t *, char **, int); +static int xhtml_convert(wchar_t *, int, char **, int); static void xhtml_rdaddwc(rdstringc *, word *, word *); static void xhtml_para(FILE *, word *); static void xhtml_codepara(FILE *, word *); @@ -1331,13 +1331,17 @@ static int xhtml_reservedchar(int c) * characters are OK but `result' is non-NULL, a result _will_ * still be generated! */ -static int xhtml_convert(wchar_t *s, char **result, int hard_spaces) { +static int xhtml_convert(wchar_t *s, int maxlen, char **result, + int hard_spaces) { int doing = (result != 0); int ok = TRUE; char *p = NULL; int plen = 0, psize = 0; - for (; *s; s++) { + if (maxlen <= 0) + maxlen = -1; + + for (; *s && maxlen != 0; s++, maxlen--) { wchar_t c = *s; #define ensure_size(i) if (i>=psize) { psize = i+256; p = resize(p, psize); } @@ -1504,7 +1508,7 @@ static void xhtml_rdaddwc(rdstringc *rs, word *text, word *end) { rdaddsc(rs, "<code>"); if (removeattr(text->type) == word_Normal) { - if (xhtml_convert(text->text, &c, TRUE)) /* spaces in the word are hard */ + if (xhtml_convert(text->text, 0, &c, TRUE)) /* spaces in the word are hard */ rdaddsc(rs, c); else xhtml_rdaddwc(rs, text->alt, NULL); @@ -1564,7 +1568,7 @@ static void xhtml_heading(FILE *fp, paragraph *p) xhtml_rdaddwc(&t, nprefix, NULL); if (fmt) { char *c; - if (xhtml_convert(fmt->number_suffix, &c, FALSE)) { + if (xhtml_convert(fmt->number_suffix, 0, &c, FALSE)) { rdaddsc(&t, c); sfree(c); } @@ -1573,7 +1577,7 @@ static void xhtml_heading(FILE *fp, paragraph *p) xhtml_rdaddwc(&t, tprefix, NULL); if (fmt) { char *c; - if (xhtml_convert(fmt->number_suffix, &c, FALSE)) { + if (xhtml_convert(fmt->number_suffix, 0, &c, FALSE)) { rdaddsc(&t, c); sfree(c); } @@ -1616,10 +1620,49 @@ static void xhtml_codepara(FILE *fp, word *text) { fprintf(fp, "<pre>"); for (; text; text = text->next) if (text->type == word_WeakCode) { + word *here, *next; char *c; - xhtml_convert(text->text, &c, FALSE); - fprintf(fp, "%s\n", c); - sfree(c); + + /* + * See if this WeakCode is followed by an Emph to indicate + * emphasis. + */ + here = text; + if (text->next && text->next->type == word_Emph) { + next = text = text->next; + } else + next = NULL; + + if (next) { + wchar_t *t, *e; + int n; + + t = here->text; + e = next->text; + + while (*e) { + int ec = *e; + + for (n = 0; t[n] && e[n] && e[n] == ec; n++); + xhtml_convert(t, n, &c, FALSE); + fprintf(fp, "%s%s%s", + (ec == 'i' ? "<em>" : ec == 'b' ? "<b>" : ""), + c, + (ec == 'i' ? "</em>" : ec == 'b' ? "</b>" : "")); + sfree(c); + + t += n; + e += n; + } + + xhtml_convert(t, 0, &c, FALSE); + fprintf(fp, "%s\n", c); + sfree(c); + } else { + xhtml_convert(here->text, 0, &c, FALSE); + fprintf(fp, "%s\n", c); + sfree(c); + } } fprintf(fp, "</pre>\n"); } |