]>
git.cameronkatri.com Git - mandoc.git/blob - eqn_html.c
1 /* $Id: eqn_html.c,v 1.19 2019/03/17 18:21:45 schwarze Exp $ */
3 * Copyright (c) 2011, 2014 Kristaps Dzonsons <kristaps@bsd.lv>
4 * Copyright (c) 2017 Ingo Schwarze <schwarze@openbsd.org>
6 * Permission to use, copy, modify, and distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20 #include <sys/types.h>
35 eqn_box(struct html
*p
, const struct eqn_box
*bp
)
37 struct tag
*post
, *row
, *cell
, *t
;
38 const struct eqn_box
*child
, *parent
;
50 * Special handling for a matrix, which is presented to us in
51 * column order, but must be printed in row-order.
53 if (EQN_MATRIX
== bp
->type
) {
54 if (NULL
== bp
->first
)
56 if (bp
->first
->type
!= EQN_LIST
||
57 bp
->first
->expectargs
== 1) {
58 eqn_box(p
, bp
->first
);
61 if (NULL
== (parent
= bp
->first
->first
))
63 /* Estimate the number of rows, first. */
64 if (NULL
== (child
= parent
->first
))
66 for (rows
= 0; NULL
!= child
; rows
++)
68 /* Print row-by-row. */
69 post
= print_otag(p
, TAG_MTABLE
, "");
70 for (i
= 0; i
< rows
; i
++) {
71 parent
= bp
->first
->first
;
72 row
= print_otag(p
, TAG_MTR
, "");
73 while (NULL
!= parent
) {
74 child
= parent
->first
;
75 for (j
= 0; j
< i
; j
++) {
80 cell
= print_otag(p
, TAG_MTD
, "");
82 * If we have no data for this
83 * particular cell, then print a
84 * placeholder and continue--don't puke.
87 eqn_box(p
, child
->first
);
89 parent
= parent
->next
;
98 post
= print_otag(p
, TAG_MOVER
, "");
101 post
= print_otag(p
, TAG_MSUP
, "");
104 post
= print_otag(p
, TAG_MUNDER
, "");
107 post
= print_otag(p
, TAG_MSUB
, "");
110 post
= print_otag(p
, TAG_MFRAC
, "");
113 post
= print_otag(p
, TAG_MUNDEROVER
, "");
116 post
= print_otag(p
, TAG_MSUBSUP
, "");
119 post
= print_otag(p
, TAG_MSQRT
, "");
125 if (bp
->top
|| bp
->bottom
) {
126 assert(NULL
== post
);
127 if (bp
->top
&& NULL
== bp
->bottom
)
128 post
= print_otag(p
, TAG_MOVER
, "");
129 else if (bp
->top
&& bp
->bottom
)
130 post
= print_otag(p
, TAG_MUNDEROVER
, "");
132 post
= print_otag(p
, TAG_MUNDER
, "");
135 if (EQN_PILE
== bp
->type
) {
136 assert(NULL
== post
);
137 if (bp
->first
!= NULL
&&
138 bp
->first
->type
== EQN_LIST
&&
139 bp
->first
->expectargs
> 1)
140 post
= print_otag(p
, TAG_MTABLE
, "");
141 } else if (bp
->type
== EQN_LIST
&& bp
->expectargs
> 1 &&
142 bp
->parent
&& bp
->parent
->type
== EQN_PILE
) {
143 assert(NULL
== post
);
144 post
= print_otag(p
, TAG_MTR
, "");
145 print_otag(p
, TAG_MTD
, "");
148 if (bp
->text
!= NULL
) {
149 assert(post
== NULL
);
152 if (isdigit((unsigned char)cp
[0]) ||
153 (cp
[0] == '.' && isdigit((unsigned char)cp
[1]))) {
155 while (*++cp
!= '\0') {
157 isdigit((unsigned char)*cp
) == 0) {
162 } else if (*cp
!= '\0' && isalpha((unsigned char)*cp
) == 0) {
164 while (*cp
!= '\0') {
165 if (cp
[0] == '\\' && cp
[1] != '\0') {
167 mandoc_escape(&cp
, NULL
, NULL
);
168 } else if (isalnum((unsigned char)*cp
)) {
176 if (bp
->text
[0] != '\0' &&
177 (((tag
== TAG_MN
|| tag
== TAG_MO
) &&
178 font
== EQNFONT_ROMAN
) ||
179 (tag
== TAG_MI
&& font
== (bp
->text
[1] == '\0' ?
180 EQNFONT_ITALIC
: EQNFONT_ROMAN
))))
184 post
= print_otag(p
, tag
, "");
187 post
= print_otag(p
, tag
, "?", "fontstyle", "normal");
191 post
= print_otag(p
, tag
, "?", "fontweight", "bold");
194 post
= print_otag(p
, tag
, "?", "fontstyle", "italic");
199 print_text(p
, bp
->text
);
200 } else if (NULL
== post
) {
201 if (NULL
!= bp
->left
|| NULL
!= bp
->right
)
202 post
= print_otag(p
, TAG_MFENCED
, "??",
203 "open", bp
->left
== NULL
? "" : bp
->left
,
204 "close", bp
->right
== NULL
? "" : bp
->right
);
206 post
= print_otag(p
, TAG_MROW
, "");
208 print_otag(p
, TAG_MROW
, "");
211 eqn_box(p
, bp
->first
);
214 if (NULL
!= bp
->bottom
) {
215 t
= print_otag(p
, TAG_MO
, "");
216 print_text(p
, bp
->bottom
);
219 if (NULL
!= bp
->top
) {
220 t
= print_otag(p
, TAG_MO
, "");
221 print_text(p
, bp
->top
);
228 eqn_box(p
, bp
->next
);
232 print_eqn(struct html
*p
, const struct eqn_box
*bp
)
236 if (bp
->first
== NULL
)
239 t
= print_otag(p
, TAG_MATH
, "c", "eqn");
241 p
->flags
|= HTML_NONOSPACE
;
243 p
->flags
&= ~HTML_NONOSPACE
;