summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKristaps Dzonsons <kristaps@bsd.lv>2011-01-29 14:49:44 +0000
committerKristaps Dzonsons <kristaps@bsd.lv>2011-01-29 14:49:44 +0000
commit640a3cb4e4b0817868c63e57d68bbbf3229fb254 (patch)
treeb967b9c40f409292f7a8d5a23a6df62e38050831
parent488122cea4707e12b07fcc3116f7b07b4ddd7ab0 (diff)
downloadmandoc-640a3cb4e4b0817868c63e57d68bbbf3229fb254.tar.gz
When in a <PRE>, don't print out the <BR> before lines that have leading
whitespace.
-rw-r--r--html.h5
-rw-r--r--mdoc_html.c18
2 files changed, 19 insertions, 4 deletions
diff --git a/html.h b/html.h
index e5320624..8cb83954 100644
--- a/html.h
+++ b/html.h
@@ -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/mdoc_html.c b/mdoc_html.c
index 831580ec..11171c21 100644
--- a/mdoc_html.c
+++ b/mdoc_html.c
@@ -422,8 +422,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):
@@ -1175,7 +1181,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;
@@ -1214,6 +1220,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);
/*
@@ -1250,6 +1261,9 @@ mdoc_bd_pre(MDOC_ARGS)
h->flags |= HTML_NOSPACE;
}
+ if (0 == sv)
+ h->flags &= ~HTML_LITERAL;
+
return(0);
}