]>
git.cameronkatri.com Git - mandoc.git/blob - eqn_html.c
1 /* $Id: eqn_html.c,v 1.18 2018/12/13 05:23:38 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>
34 eqn_box(struct html
*p
, const struct eqn_box
*bp
)
36 struct tag
*post
, *row
, *cell
, *t
;
37 const struct eqn_box
*child
, *parent
;
49 * Special handling for a matrix, which is presented to us in
50 * column order, but must be printed in row-order.
52 if (EQN_MATRIX
== bp
->type
) {
53 if (NULL
== bp
->first
)
55 if (bp
->first
->type
!= EQN_LIST
||
56 bp
->first
->expectargs
== 1) {
57 eqn_box(p
, bp
->first
);
60 if (NULL
== (parent
= bp
->first
->first
))
62 /* Estimate the number of rows, first. */
63 if (NULL
== (child
= parent
->first
))
65 for (rows
= 0; NULL
!= child
; rows
++)
67 /* Print row-by-row. */
68 post
= print_otag(p
, TAG_MTABLE
, "");
69 for (i
= 0; i
< rows
; i
++) {
70 parent
= bp
->first
->first
;
71 row
= print_otag(p
, TAG_MTR
, "");
72 while (NULL
!= parent
) {
73 child
= parent
->first
;
74 for (j
= 0; j
< i
; j
++) {
79 cell
= print_otag(p
, TAG_MTD
, "");
81 * If we have no data for this
82 * particular cell, then print a
83 * placeholder and continue--don't puke.
86 eqn_box(p
, child
->first
);
88 parent
= parent
->next
;
97 post
= print_otag(p
, TAG_MOVER
, "");
100 post
= print_otag(p
, TAG_MSUP
, "");
103 post
= print_otag(p
, TAG_MUNDER
, "");
106 post
= print_otag(p
, TAG_MSUB
, "");
109 post
= print_otag(p
, TAG_MFRAC
, "");
112 post
= print_otag(p
, TAG_MUNDEROVER
, "");
115 post
= print_otag(p
, TAG_MSUBSUP
, "");
118 post
= print_otag(p
, TAG_MSQRT
, "");
124 if (bp
->top
|| bp
->bottom
) {
125 assert(NULL
== post
);
126 if (bp
->top
&& NULL
== bp
->bottom
)
127 post
= print_otag(p
, TAG_MOVER
, "");
128 else if (bp
->top
&& bp
->bottom
)
129 post
= print_otag(p
, TAG_MUNDEROVER
, "");
131 post
= print_otag(p
, TAG_MUNDER
, "");
134 if (EQN_PILE
== bp
->type
) {
135 assert(NULL
== post
);
136 if (bp
->first
!= NULL
&&
137 bp
->first
->type
== EQN_LIST
&&
138 bp
->first
->expectargs
> 1)
139 post
= print_otag(p
, TAG_MTABLE
, "");
140 } else if (bp
->type
== EQN_LIST
&& bp
->expectargs
> 1 &&
141 bp
->parent
&& bp
->parent
->type
== EQN_PILE
) {
142 assert(NULL
== post
);
143 post
= print_otag(p
, TAG_MTR
, "");
144 print_otag(p
, TAG_MTD
, "");
147 if (bp
->text
!= NULL
) {
148 assert(post
== NULL
);
151 if (isdigit((unsigned char)cp
[0]) ||
152 (cp
[0] == '.' && isdigit((unsigned char)cp
[1]))) {
154 while (*++cp
!= '\0') {
156 isdigit((unsigned char)*cp
) == 0) {
161 } else if (*cp
!= '\0' && isalpha((unsigned char)*cp
) == 0) {
163 while (*cp
!= '\0') {
164 if (cp
[0] == '\\' && cp
[1] != '\0') {
166 mandoc_escape(&cp
, NULL
, NULL
);
167 } else if (isalnum((unsigned char)*cp
)) {
175 if (bp
->text
[0] != '\0' &&
176 (((tag
== TAG_MN
|| tag
== TAG_MO
) &&
177 font
== EQNFONT_ROMAN
) ||
178 (tag
== TAG_MI
&& font
== (bp
->text
[1] == '\0' ?
179 EQNFONT_ITALIC
: EQNFONT_ROMAN
))))
183 post
= print_otag(p
, tag
, "");
186 post
= print_otag(p
, tag
, "?", "fontstyle", "normal");
190 post
= print_otag(p
, tag
, "?", "fontweight", "bold");
193 post
= print_otag(p
, tag
, "?", "fontstyle", "italic");
198 print_text(p
, bp
->text
);
199 } else if (NULL
== post
) {
200 if (NULL
!= bp
->left
|| NULL
!= bp
->right
)
201 post
= print_otag(p
, TAG_MFENCED
, "??",
202 "open", bp
->left
== NULL
? "" : bp
->left
,
203 "close", bp
->right
== NULL
? "" : bp
->right
);
205 post
= print_otag(p
, TAG_MROW
, "");
207 print_otag(p
, TAG_MROW
, "");
210 eqn_box(p
, bp
->first
);
213 if (NULL
!= bp
->bottom
) {
214 t
= print_otag(p
, TAG_MO
, "");
215 print_text(p
, bp
->bottom
);
218 if (NULL
!= bp
->top
) {
219 t
= print_otag(p
, TAG_MO
, "");
220 print_text(p
, bp
->top
);
227 eqn_box(p
, bp
->next
);
231 print_eqn(struct html
*p
, const struct eqn_box
*bp
)
235 if (bp
->first
== NULL
)
238 t
= print_otag(p
, TAG_MATH
, "c", "eqn");
240 p
->flags
|= HTML_NONOSPACE
;
242 p
->flags
&= ~HTML_NONOSPACE
;