forked from source-academy/sicp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprocessTablePdf.js
44 lines (42 loc) · 1.43 KB
/
processTablePdf.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import { recursiveProcessTextLatex } from "../parseXmlLatex";
export const processTable = (node, writeTo) => {
const firstRow = node.getElementsByTagName("TR")[0];
if (firstRow) {
const colNum = firstRow.getElementsByTagName("TD").length;
writeTo.push(
"\n\\begin{quote}\n\\noindent\n\\bgroup\\def\\arraystretch{1.5}\\begin{tabular}{"
);
for (let i = 0; i < colNum; i++) {
writeTo.push("l ");
}
writeTo.push("} \n");
for (let row = node.firstChild; row; row = row.nextSibling) {
if (row.nodeName != "TR") continue;
let first = true;
for (let col = row.firstChild; col; col = col.nextSibling) {
if (col.nodeName != "TD") continue;
if (first) {
first = false;
} else {
writeTo.push(" & ");
}
recursiveProcessTextLatex(col.firstChild, writeTo);
}
let nextRow = row.nextSibling;
while (nextRow && nextRow.nodeName != "TR") {
nextRow = nextRow.nextSibling;
}
if (nextRow && nextRow.getAttribute("SINGLESPACE") === "yes") {
writeTo.push(" \\\\[-6pt]\n");
} else if (nextRow && nextRow.getAttribute("DOUBLESPACE") === "yes") {
writeTo.push(" \\\\[6pt]\n");
} else {
writeTo.push(" \\\\ \n");
}
}
writeTo.push("\\end{tabular}\\egroup\n\\end{quote}\n");
} else {
recursiveProcessTextLatex(node.firstChild, writeTo);
}
};
export default processTable;