summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorKristaps Dzonsons <kristaps@bsd.lv>2010-07-06 12:37:17 +0000
committerKristaps Dzonsons <kristaps@bsd.lv>2010-07-06 12:37:17 +0000
commitb5257bc3473c0f02c94b7717debac9dc6b0738f4 (patch)
treedea841229e4f16df1ee64d746bb20d0f7759469c
parented642de7ca282d168ea118d0860186abb1abcd59 (diff)
downloadmandoc-b5257bc3473c0f02c94b7717debac9dc6b0738f4.tar.gz
mandoc-b5257bc3473c0f02c94b7717debac9dc6b0738f4.tar.zst
mandoc-b5257bc3473c0f02c94b7717debac9dc6b0738f4.zip
Give -T[x]html `Bk -words' capability.
-rw-r--r--html.c24
-rw-r--r--html.h6
-rw-r--r--mdoc_html.c50
3 files changed, 71 insertions, 9 deletions
diff --git a/html.c b/html.c
index f7bfa3c2..15b8b467 100644
--- a/html.c
+++ b/html.c
@@ -1,4 +1,4 @@
-/* $Id: html.c,v 1.104 2010/07/06 11:10:53 kristaps Exp $ */
+/* $Id: html.c,v 1.105 2010/07/06 12:37:17 kristaps Exp $ */
/*
* Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@bsd.lv>
*
@@ -393,8 +393,15 @@ print_otag(struct html *h, enum htmltag tag,
t = NULL;
if ( ! (HTML_NOSPACE & h->flags))
- if ( ! (HTML_CLRLINE & htmltags[tag].flags))
- putchar(' ');
+ if ( ! (HTML_CLRLINE & htmltags[tag].flags)) {
+ /* Manage keeps! */
+ if ( ! (HTML_KEEP & h->flags)) {
+ if (HTML_PREKEEP & h->flags)
+ h->flags |= HTML_KEEP;
+ putchar(' ');
+ } else
+ printf("&#160;");
+ }
/* Print out the tag name and attributes. */
@@ -511,8 +518,15 @@ print_text(struct html *h, const char *word)
break;
}
- if ( ! (h->flags & HTML_NOSPACE))
- putchar(' ');
+ if ( ! (HTML_NOSPACE & h->flags)) {
+ /* Manage keeps! */
+ if ( ! (HTML_KEEP & h->flags)) {
+ if (HTML_PREKEEP & h->flags)
+ h->flags |= HTML_KEEP;
+ putchar(' ');
+ } else
+ printf("&#160;");
+ }
assert(word);
if ( ! print_encode(h, word, 0))
diff --git a/html.h b/html.h
index 874adc07..503acd57 100644
--- a/html.h
+++ b/html.h
@@ -1,4 +1,4 @@
-/* $Id: html.h,v 1.24 2010/06/19 20:46:27 kristaps Exp $ */
+/* $Id: html.h,v 1.25 2010/07/06 12:37:17 kristaps Exp $ */
/*
* Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@bsd.lv>
*
@@ -110,7 +110,9 @@ enum htmltype {
struct html {
int flags;
#define HTML_NOSPACE (1 << 0)
-#define HTML_IGNDELIM (1 << 2)
+#define HTML_IGNDELIM (1 << 1)
+#define HTML_KEEP (1 << 2)
+#define HTML_PREKEEP (1 << 3)
struct tagq tags;
struct ordq ords;
void *symtab;
diff --git a/mdoc_html.c b/mdoc_html.c
index d8bad8d0..062ab4c4 100644
--- a/mdoc_html.c
+++ b/mdoc_html.c
@@ -1,4 +1,4 @@
-/* $Id: mdoc_html.c,v 1.93 2010/07/04 21:59:30 kristaps Exp $ */
+/* $Id: mdoc_html.c,v 1.94 2010/07/06 12:37:17 kristaps Exp $ */
/*
* Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@bsd.lv>
*
@@ -73,6 +73,8 @@ static int mdoc_aq_pre(MDOC_ARGS);
static int mdoc_ar_pre(MDOC_ARGS);
static int mdoc_bd_pre(MDOC_ARGS);
static int mdoc_bf_pre(MDOC_ARGS);
+static void mdoc_bk_post(MDOC_ARGS);
+static int mdoc_bk_pre(MDOC_ARGS);
static void mdoc_bl_post(MDOC_ARGS);
static int mdoc_bl_pre(MDOC_ARGS);
static void mdoc_bq_post(MDOC_ARGS);
@@ -237,7 +239,7 @@ static const struct htmlmdoc mdocs[MDOC_MAX] = {
{NULL, NULL}, /* Fc */
{mdoc_op_pre, mdoc_op_post}, /* Oo */
{NULL, NULL}, /* Oc */
- {NULL, NULL}, /* Bk */
+ {mdoc_bk_pre, mdoc_bk_post}, /* Bk */
{NULL, NULL}, /* Ek */
{mdoc_bt_pre, NULL}, /* Bt */
{NULL, NULL}, /* Hf */
@@ -442,6 +444,18 @@ print_mdoc_node(MDOC_ARGS)
break;
}
+ if (HTML_KEEP & h->flags) {
+ if (n->prev && n->prev->line != n->line) {
+ h->flags &= ~HTML_KEEP;
+ h->flags |= HTML_PREKEEP;
+ } else if (NULL == n->prev) {
+ if (n->parent && n->parent->line != n->line) {
+ h->flags &= ~HTML_KEEP;
+ h->flags |= HTML_PREKEEP;
+ }
+ }
+ }
+
if (child && n->child)
print_mdoc_nodelist(m, n->child, h);
@@ -2227,3 +2241,35 @@ mdoc__x_post(MDOC_ARGS)
h->flags |= HTML_NOSPACE;
print_text(h, n->next ? "," : ".");
}
+
+
+/* ARGSUSED */
+static int
+mdoc_bk_pre(MDOC_ARGS)
+{
+
+ switch (n->type) {
+ case (MDOC_BLOCK):
+ break;
+ case (MDOC_HEAD):
+ return(0);
+ case (MDOC_BODY):
+ h->flags |= HTML_PREKEEP;
+ break;
+ default:
+ abort();
+ /* NOTREACHED */
+ }
+
+ return(1);
+}
+
+
+/* ARGSUSED */
+static void
+mdoc_bk_post(MDOC_ARGS)
+{
+
+ if (MDOC_BODY == n->type)
+ h->flags &= ~(HTML_KEEP | HTML_PREKEEP);
+}