-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathopenxml.js
More file actions
165 lines (145 loc) · 4.55 KB
/
Copy pathopenxml.js
File metadata and controls
165 lines (145 loc) · 4.55 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
// https://c-rex.net/samples/ooxml/e1/Part4/OOXML_P4_DOCX_notes_topic_ID0E3F3GB.html
class Styler {
constructor(stylerXML) {
this.stylerXML = stylerXML;
this.isBullet = false;
this.marL = 0;
this.b = 0;
this.i = 0;
this.u = 0;
if (stylerXML == null)
return;
if (stylerXML.getElementsByTagName("a:buChar").length > 0)
this.isBullet = true;
if (stylerXML.getElementsByTagName("a:buAutoNum").length > 0)
this.isBullet = true;
if (stylerXML.getAttribute("marL") != null)
this.marL = parseInt(stylerXML.getAttribute("marL")) / 10000;
if (stylerXML.getAttribute("indent") != null)
this.marL += parseInt(stylerXML.getAttribute("indent")) / 10000;
if (stylerXML.getAttribute("b") != null)
this.b = parseInt(stylerXML.getAttribute("b"));
if (stylerXML.getAttribute("i") != null)
this.i = parseInt(stylerXML.getAttribute("i"));
if (stylerXML.getAttribute("u") != null && stylerXML.getAttribute("u") != 'none') {
this.u = stylerXML.getAttribute("u");
}
}
getContent(content) {
return this.getRawContent(content);
}
getRawContent(content) {
return "<span " + this.getStyle() + ">" + content + "</span>"
}
hasWrap() {
return this.isBullet;
}
getStyle() {
var style = 'style="' + this.getRawStyle() + '"';
return style
}
getRawStyle() {
var style = '';
if (this.marL != 0) {
style += "margin-left: " + this.marL + "px;";
}
if (this.b == 1) {
style += "font-weight: bold;";
}
if (this.i != 0) {
style += "font-style: italic;";
}
if (this.u != 0) {
style += "text-decoration: underline;";
}
return style;
}
wrap(content) {
if (this.isBullet && content.length > 0)
return "<li " + this.getStyle() + ">" + content + "</li>"
else
return "<p " + this.getStyle() + ">" + content + "</p>";
}
}
class Run {
constructor(runXML) {
this.runXML = runXML;
this.styler = new Styler();
var rPr = this.runXML.getElementsByTagName("a:rPr");
if (rPr.length > 0)
this.styler = new Styler(rPr[0]);
}
getContent() {
return this.styler.getContent(this.runXML.textContent);
}
getRawContent() {
return this.styler.getRawContent(this.runXML.textContent);
}
}
class Paragraph {
constructor(paragraphXML) {
this.paragraphXML = paragraphXML;
this.runs = []
this.styler = new Styler();
var runs = this.paragraphXML.getElementsByTagName("a:r");
for (let run of runs) {
this.runs.push(new Run(run));
}
var pPr = this.paragraphXML.getElementsByTagName("a:pPr");
if (pPr.length > 0)
this.styler = new Styler(pPr[0]);
}
wrap(content) {
return this.styler.wrap(content);
}
getContent() {
var content = '';
for (let run of this.runs) {
content += run.getContent();
}
content = this.wrap(content);
return content;
}
getRawContent() {
var content = '';
for (let run of this.runs) {
content += run.getRawContent();
}
content = this.wrap(content);
return content;
}
}
class Page {
constructor(pageXML) {
this.pageXML = pageXML;
this.sldNum = -1;
this.paragraphs = [];
var shapes = this.pageXML.getElementsByTagName("p:sp");
for (let shape of shapes) {
if (shape.querySelector('ph[type="body"]')) {
var body = shape.getElementsByTagName("p:txBody");
if (body.length > 0) {
var ps = body[0].getElementsByTagName("a:p");
for (let p of ps)
this.paragraphs.push(new Paragraph(p));
}
} else if (shape.querySelector('ph[type="sldNum"]')) {
this.sldNum = parseInt(shape.textContent);
}
}
}
getContent() {
var content = '';
for (let paragraph of this.paragraphs) {
content += paragraph.getContent();
}
return content;
}
getRawContent() {
var content = '';
for (let paragraph of this.paragraphs) {
content += paragraph.getRawContent();
}
return content;
}
}