diff options
-rw-r--r-- | regress/usr.bin/mandoc/char/space/leading-mdoc.in | 10 | ||||
-rw-r--r-- | regress/usr.bin/mandoc/char/space/leading-mdoc.out_ascii | 7 | ||||
-rw-r--r-- | usr.bin/mandoc/html.h | 7 | ||||
-rw-r--r-- | usr.bin/mandoc/mdoc_html.c | 20 |
4 files changed, 38 insertions, 6 deletions
diff --git a/regress/usr.bin/mandoc/char/space/leading-mdoc.in b/regress/usr.bin/mandoc/char/space/leading-mdoc.in index 9b806cf18d2..171da4a0a73 100644 --- a/regress/usr.bin/mandoc/char/space/leading-mdoc.in +++ b/regress/usr.bin/mandoc/char/space/leading-mdoc.in @@ -12,3 +12,13 @@ second normal line normal line after a macro line .Ux leading space after a macro line +.Bd -literal +normal line in a literal display + leading space in a literal display +another normal line +.Ed +.Bd -filled +normal line in a filled display + leading space in a filled display +another normal line +.Ed diff --git a/regress/usr.bin/mandoc/char/space/leading-mdoc.out_ascii b/regress/usr.bin/mandoc/char/space/leading-mdoc.out_ascii index eda38c67b4e..4a8f24ac622 100644 --- a/regress/usr.bin/mandoc/char/space/leading-mdoc.out_ascii +++ b/regress/usr.bin/mandoc/char/space/leading-mdoc.out_ascii @@ -8,3 +8,10 @@ DDEESSCCRRIIPPTTIIOONN line with a leading space UNIX normal line after a macro line UNIX leading space after a macro line + normal line in a literal display + leading space in a literal display + another normal line + + normal line in a filled display + leading space in a filled display another normal line + diff --git a/usr.bin/mandoc/html.h b/usr.bin/mandoc/html.h index 482eabe960b..4643e81afd9 100644 --- a/usr.bin/mandoc/html.h +++ b/usr.bin/mandoc/html.h @@ -1,4 +1,4 @@ -/* $Id: html.h,v 1.14 2011/01/16 19:41:16 schwarze Exp $ */ +/* $Id: html.h,v 1.15 2011/01/31 03:04:26 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv> * @@ -111,11 +111,12 @@ enum htmltype { struct html { int flags; -#define HTML_NOSPACE (1 << 0) +#define HTML_NOSPACE (1 << 0) /* suppress next space */ #define HTML_IGNDELIM (1 << 1) #define HTML_KEEP (1 << 2) #define HTML_PREKEEP (1 << 3) -#define HTML_NONOSPACE (1 << 4) +#define HTML_NONOSPACE (1 << 4) /* never add spaces */ +#define HTML_LITERAL (1 << 5) /* literal (e.g., <PRE>) context */ struct tagq tags; /* stack of open tags */ struct rofftbl tbl; /* current table */ struct tag *tblt; /* current open table scope */ diff --git a/usr.bin/mandoc/mdoc_html.c b/usr.bin/mandoc/mdoc_html.c index 320298b928f..5aec02fa59d 100644 --- a/usr.bin/mandoc/mdoc_html.c +++ b/usr.bin/mandoc/mdoc_html.c @@ -1,4 +1,4 @@ -/* $Id: mdoc_html.c,v 1.49 2011/01/30 18:28:01 schwarze Exp $ */ +/* $Id: mdoc_html.c,v 1.50 2011/01/31 03:04:26 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv> * @@ -418,8 +418,14 @@ print_mdoc_node(MDOC_ARGS) case (MDOC_TEXT): /* No tables in this mode... */ assert(NULL == h->tblt); + + /* + * Make sure that if we're in a literal mode already + * (i.e., within a <PRE>) don't print the newline. + */ if (' ' == *n->string && MDOC_LINE & n->flags) - print_otag(h, TAG_BR, 0, NULL); + if ( ! (HTML_LITERAL & h->flags)) + print_otag(h, TAG_BR, 0, NULL); print_text(h, n->string); return; case (MDOC_TBL): @@ -1165,7 +1171,7 @@ static int mdoc_bd_pre(MDOC_ARGS) { struct htmlpair tag[2]; - int comp; + int comp, sv; const struct mdoc_node *nn; struct roffsu su; @@ -1204,6 +1210,11 @@ mdoc_bd_pre(MDOC_ARGS) PAIR_CLASS_INIT(&tag[1], "lit display"); print_otag(h, TAG_PRE, 2, tag); + /* This can be recursive: save & set our literal state. */ + + sv = h->flags & HTML_LITERAL; + h->flags |= HTML_LITERAL; + for (nn = n->child; nn; nn = nn->next) { print_mdoc_node(m, nn, h); /* @@ -1240,6 +1251,9 @@ mdoc_bd_pre(MDOC_ARGS) h->flags |= HTML_NOSPACE; } + if (0 == sv) + h->flags &= ~HTML_LITERAL; + return(0); } |