Exemplo n.º 1
0
/*
 * See the same function in mdoc_term.c for documentation.
 */
static void
synopsis_pre(struct html *h, const struct roff_node *n)
{

	if (NULL == n->prev || ! (NODE_SYNPRETTY & n->flags))
		return;

	if (n->prev->tok == n->tok &&
	    MDOC_Fo != n->tok &&
	    MDOC_Ft != n->tok &&
	    MDOC_Fn != n->tok) {
		print_otag(h, TAG_BR, "");
		return;
	}

	switch (n->prev->tok) {
	case MDOC_Fd:
	case MDOC_Fn:
	case MDOC_Fo:
	case MDOC_In:
	case MDOC_Vt:
		print_paragraph(h);
		break;
	case MDOC_Ft:
		if (MDOC_Fn != n->tok && MDOC_Fo != n->tok) {
			print_paragraph(h);
			break;
		}
		/* FALLTHROUGH */
	default:
		print_otag(h, TAG_BR, "");
		break;
	}
}
Exemplo n.º 2
0
static int
mdoc_pp_pre(MDOC_ARGS)
{

	print_paragraph(h);
	return 0;
}
Exemplo n.º 3
0
static int
mdoc_rs_pre(MDOC_ARGS)
{
	if (n->type != ROFFT_BLOCK)
		return 1;

	if (n->prev && SEC_SEE_ALSO == n->sec)
		print_paragraph(h);

	print_otag(h, TAG_CITE, "cT", "Rs");
	return 1;
}
Exemplo n.º 4
0
/*
 * Printing leading vertical space before a block.
 * This is used for the paragraph macros.
 * The rules are pretty simple, since there's very little nesting going
 * on here.  Basically, if we're the first within another block (SS/SH),
 * then don't emit vertical space.  If we are (RS), then do.  If not the
 * first, print it.
 */
static void
print_bvspace(struct html *h, const struct man_node *n)
{

	if (n->body && n->body->child)
		if (MAN_TBL == n->body->child->type)
			return;

	if (MAN_ROOT == n->parent->type || MAN_RS != n->parent->tok)
		if (NULL == n->prev)
			return;

	print_paragraph(h);
}
Exemplo n.º 5
0
/*
 * Printing leading vertical space before a block.
 * This is used for the paragraph macros.
 * The rules are pretty simple, since there's very little nesting going
 * on here.  Basically, if we're the first within another block (SS/SH),
 * then don't emit vertical space.  If we are (RS), then do.  If not the
 * first, print it.
 */
static void
print_bvspace(struct html *h, const struct roff_node *n)
{

	if (n->body && n->body->child)
		if (n->body->child->type == ROFFT_TBL)
			return;

	if (n->parent->type == ROFFT_ROOT || n->parent->tok != MAN_RS)
		if (NULL == n->prev)
			return;

	print_paragraph(h);
}
Exemplo n.º 6
0
static int
mdoc_rs_pre(MDOC_ARGS)
{
	struct htmlpair	 tag;

	if (MDOC_BLOCK != n->type)
		return(1);

	if (n->prev && SEC_SEE_ALSO == n->sec)
		print_paragraph(h);

	PAIR_CLASS_INIT(&tag, "ref");
	print_otag(h, TAG_SPAN, 1, &tag);
	return(1);
}
Exemplo n.º 7
0
static int
mdoc_bd_pre(MDOC_ARGS)
{
	int			 comp, sv;
	struct roff_node	*nn;

	if (n->type == ROFFT_HEAD)
		return 0;

	if (n->type == ROFFT_BLOCK) {
		comp = n->norm->Bd.comp;
		for (nn = n; nn && ! comp; nn = nn->parent) {
			if (nn->type != ROFFT_BLOCK)
				continue;
			if (MDOC_Ss == nn->tok || MDOC_Sh == nn->tok)
				comp = 1;
			if (nn->prev)
				break;
		}
		if ( ! comp)
			print_paragraph(h);
		return 1;
	}

	/* Handle the -offset argument. */

	if (n->norm->Bd.offs == NULL ||
	    ! strcmp(n->norm->Bd.offs, "left"))
		print_otag(h, TAG_DIV, "c", "Bd");
	else
		print_otag(h, TAG_DIV, "c", "Bd Bd-indent");

	if (n->norm->Bd.type != DISP_unfilled &&
	    n->norm->Bd.type != DISP_literal)
		return 1;

	print_otag(h, TAG_PRE, "c", "Li");

	/* 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(meta, nn, h);
		/*
		 * If the printed node flushes its own line, then we
		 * needn't do it here as well.  This is hacky, but the
		 * notion of selective eoln whitespace is pretty dumb
		 * anyway, so don't sweat it.
		 */
		switch (nn->tok) {
		case ROFF_br:
		case ROFF_sp:
		case MDOC_Sm:
		case MDOC_Bl:
		case MDOC_D1:
		case MDOC_Dl:
		case MDOC_Lp:
		case MDOC_Pp:
			continue;
		default:
			break;
		}
		if (h->flags & HTML_NONEWLINE ||
		    (nn->next && ! (nn->next->flags & NODE_LINE)))
			continue;
		else if (nn->next)
			print_text(h, "\n");

		h->flags |= HTML_NOSPACE;
	}

	if (0 == sv)
		h->flags &= ~HTML_LITERAL;

	return 0;
}
Exemplo n.º 8
0
static void
print_man_node(MAN_ARGS)
{
	int		 child;
	struct tag	*t;

	child = 1;
	t = h->tags.head;

	switch (n->type) {
	case MAN_ROOT:
		man_root_pre(man, n, mh, h);
		break;
	case MAN_TEXT:
		if ('\0' == *n->string) {
			print_paragraph(h);
			return;
		}
		if (n->flags & MAN_LINE && (*n->string == ' ' || 
		    (n->prev != NULL && mh->fl & MANH_LITERAL &&
		     ! (h->flags & HTML_NONEWLINE))))
			print_otag(h, TAG_BR, 0, NULL);
		print_text(h, n->string);
		return;
	case MAN_EQN:
		print_eqn(h, n->eqn);
		break;
	case MAN_TBL:
		/*
		 * This will take care of initialising all of the table
		 * state data for the first table, then tearing it down
		 * for the last one.
		 */
		print_tbl(h, n->span);
		return;
	default:
		/*
		 * Close out scope of font prior to opening a macro
		 * scope.
		 */
		if (HTMLFONT_NONE != h->metac) {
			h->metal = h->metac;
			h->metac = HTMLFONT_NONE;
		}

		/*
		 * Close out the current table, if it's open, and unset
		 * the "meta" table state.  This will be reopened on the
		 * next table element.
		 */
		if (h->tblt) {
			print_tblclose(h);
			t = h->tags.head;
		}
		if (mans[n->tok].pre)
			child = (*mans[n->tok].pre)(man, n, mh, h);
		break;
	}

	if (child && n->child)
		print_man_nodelist(man, n->child, mh, h);

	/* This will automatically close out any font scope. */
	print_stagq(h, t);

	switch (n->type) {
	case MAN_ROOT:
		man_root_post(man, n, mh, h);
		break;
	case MAN_EQN:
		break;
	default:
		if (mans[n->tok].post)
			(*mans[n->tok].post)(man, n, mh, h);
		break;
	}
}
Exemplo n.º 9
0
static int
mdoc_bd_pre(MDOC_ARGS)
{
	struct htmlpair		 tag[2];
	int			 comp, sv;
	struct mdoc_node	*nn;
	struct roffsu		 su;

	if (MDOC_HEAD == n->type)
		return(0);

	if (MDOC_BLOCK == n->type) {
		comp = n->norm->Bd.comp;
		for (nn = n; nn && ! comp; nn = nn->parent) {
			if (MDOC_BLOCK != nn->type)
				continue;
			if (MDOC_Ss == nn->tok || MDOC_Sh == nn->tok)
				comp = 1;
			if (nn->prev)
				break;
		}
		if ( ! comp)
			print_paragraph(h);
		return(1);
	}

	/* Handle the -offset argument. */

	if (n->norm->Bd.offs == NULL ||
	    ! strcmp(n->norm->Bd.offs, "left"))
		SCALE_HS_INIT(&su, 0);
	else if ( ! strcmp(n->norm->Bd.offs, "indent"))
		SCALE_HS_INIT(&su, INDENT);
	else if ( ! strcmp(n->norm->Bd.offs, "indent-two"))
		SCALE_HS_INIT(&su, INDENT * 2);
	else
		a2width(n->norm->Bd.offs, &su);

	bufinit(h);
	bufcat_su(h, "margin-left", &su);
	PAIR_STYLE_INIT(&tag[0], h);

	if (DISP_unfilled != n->norm->Bd.type &&
	    DISP_literal != n->norm->Bd.type) {
		PAIR_CLASS_INIT(&tag[1], "display");
		print_otag(h, TAG_DIV, 2, tag);
		return(1);
	}

	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(meta, nn, h);
		/*
		 * If the printed node flushes its own line, then we
		 * needn't do it here as well.  This is hacky, but the
		 * notion of selective eoln whitespace is pretty dumb
		 * anyway, so don't sweat it.
		 */
		switch (nn->tok) {
		case MDOC_Sm:
			/* FALLTHROUGH */
		case MDOC_br:
			/* FALLTHROUGH */
		case MDOC_sp:
			/* FALLTHROUGH */
		case MDOC_Bl:
			/* FALLTHROUGH */
		case MDOC_D1:
			/* FALLTHROUGH */
		case MDOC_Dl:
			/* FALLTHROUGH */
		case MDOC_Lp:
			/* FALLTHROUGH */
		case MDOC_Pp:
			continue;
		default:
			break;
		}
		if (h->flags & HTML_NONEWLINE ||
		    (nn->next && ! (nn->next->flags & MDOC_LINE)))
			continue;
		else if (nn->next)
			print_text(h, "\n");

		h->flags |= HTML_NOSPACE;
	}

	if (0 == sv)
		h->flags &= ~HTML_LITERAL;

	return(0);
}
Exemplo n.º 10
0
static void
print_man_node(MAN_ARGS)
{
	static int	 want_fillmode = MAN_fi;
	static int	 save_fillmode;

	struct tag	*t;
	int		 child;

	/*
	 * Handle fill mode switch requests up front,
	 * they would just cause trouble in the subsequent code.
	 */

	switch (n->tok) {
	case MAN_nf:
	case MAN_EX:
		want_fillmode = MAN_nf;
		return;
	case MAN_fi:
	case MAN_EE:
		want_fillmode = MAN_fi;
		if (fillmode(h, 0) == MAN_fi)
			print_otag(h, TAG_BR, "");
		return;
	default:
		break;
	}

	/* Set up fill mode for the upcoming node. */

	switch (n->type) {
	case ROFFT_BLOCK:
		save_fillmode = 0;
		/* Some block macros suspend or cancel .nf. */
		switch (n->tok) {
		case MAN_TP:  /* Tagged paragraphs		*/
		case MAN_IP:  /* temporarily disable .nf	*/
		case MAN_HP:  /* for the head.			*/
			save_fillmode = want_fillmode;
			/* FALLTHROUGH */
		case MAN_SH:  /* Section headers		*/
		case MAN_SS:  /* permanently cancel .nf.	*/
			want_fillmode = MAN_fi;
			/* FALLTHROUGH */
		case MAN_PP:  /* These have no head.		*/
		case MAN_LP:  /* They will simply		*/
		case MAN_P:   /* reopen .nf in the body.	*/
		case MAN_RS:
		case MAN_UR:
			fillmode(h, MAN_fi);
			break;
		default:
			break;
		}
		break;
	case ROFFT_TBL:
		fillmode(h, MAN_fi);
		break;
	case ROFFT_ELEM:
		/*
		 * Some in-line macros produce tags and/or text
		 * in the handler, so they require fill mode to be
		 * configured up front just like for text nodes.
		 * For the others, keep the traditional approach
		 * of doing the same, for now.
		 */
		fillmode(h, want_fillmode);
		break;
	case ROFFT_TEXT:
		if (fillmode(h, want_fillmode) == MAN_fi &&
		    want_fillmode == MAN_fi &&
		    n->flags & NODE_LINE && *n->string == ' ' &&
		    (h->flags & HTML_NONEWLINE) == 0)
			print_otag(h, TAG_BR, "");
		if (*n->string != '\0')
			break;
		print_paragraph(h);
		return;
	default:
		break;
	}

	/* Produce output for this node. */

	child = 1;
	switch (n->type) {
	case ROFFT_TEXT:
		t = h->tag;
		print_text(h, n->string);
		break;
	case ROFFT_EQN:
		t = h->tag;
		print_eqn(h, n->eqn);
		break;
	case ROFFT_TBL:
		/*
		 * This will take care of initialising all of the table
		 * state data for the first table, then tearing it down
		 * for the last one.
		 */
		print_tbl(h, n->span);
		return;
	default:
		/*
		 * Close out scope of font prior to opening a macro
		 * scope.
		 */
		if (HTMLFONT_NONE != h->metac) {
			h->metal = h->metac;
			h->metac = HTMLFONT_NONE;
		}

		/*
		 * Close out the current table, if it's open, and unset
		 * the "meta" table state.  This will be reopened on the
		 * next table element.
		 */
		if (h->tblt)
			print_tblclose(h);

		t = h->tag;
		if (n->tok < ROFF_MAX) {
			roff_html_pre(h, n);
			child = 0;
			break;
		}

		assert(n->tok >= MAN_TH && n->tok < MAN_MAX);
		if (mans[n->tok].pre)
			child = (*mans[n->tok].pre)(man, n, h);

		/* Some block macros resume .nf in the body. */
		if (save_fillmode && n->type == ROFFT_BODY)
			want_fillmode = save_fillmode;

		break;
	}

	if (child && n->child)
		print_man_nodelist(man, n->child, h);

	/* This will automatically close out any font scope. */
	print_stagq(h, t);

	if (fillmode(h, 0) == MAN_nf &&
	    n->next != NULL && n->next->flags & NODE_LINE)
		print_endline(h);
}