office-viewer 0.1.4 → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/esm/render/renderParagraph.js +21 -42
- package/esm/util/mergeRun.js +7 -1
- package/lib/render/renderParagraph.js +21 -42
- package/lib/util/mergeRun.js +7 -1
- package/package.json +1 -1
|
@@ -11,14 +11,13 @@ import { setElementStyle } from './setElementStyle.js';
|
|
|
11
11
|
import { renderTab } from './renderTab.js';
|
|
12
12
|
import { OMath } from '../openxml/math/OMath.js';
|
|
13
13
|
import { renderOMath } from './renderMath.js';
|
|
14
|
-
import { Tab } from '../openxml/word/Tab.js';
|
|
15
14
|
|
|
16
15
|
/**
|
|
17
16
|
* 渲染段落
|
|
18
17
|
* @param renderEmptySpace 如果是 true 的话,当内容为空时会自动加上
|
|
19
18
|
*/
|
|
20
19
|
function renderParagraph(word, paragraph, renderEmptySpace, inHeader) {
|
|
21
|
-
var e_1, _a
|
|
20
|
+
var e_1, _a;
|
|
22
21
|
if (renderEmptySpace === void 0) { renderEmptySpace = true; }
|
|
23
22
|
if (inHeader === void 0) { inHeader = false; }
|
|
24
23
|
word.currentParagraph = paragraph;
|
|
@@ -38,45 +37,25 @@ function renderParagraph(word, paragraph, renderEmptySpace, inHeader) {
|
|
|
38
37
|
// 虽然目前这个实现很 hack,但可以支持常见情况
|
|
39
38
|
appendChild(p, renderTab(word, properties.tabs[0], true));
|
|
40
39
|
// 同时删掉第一个 run 中的 tab
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
60
|
-
finally {
|
|
61
|
-
try {
|
|
62
|
-
if (_g && !_g.done && (_b = _f.return)) _b.call(_f);
|
|
63
|
-
}
|
|
64
|
-
finally { if (e_2) throw e_2.error; }
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
70
|
-
finally {
|
|
71
|
-
try {
|
|
72
|
-
if (_e && !_e.done && (_a = _d.return)) _a.call(_d);
|
|
73
|
-
}
|
|
74
|
-
finally { if (e_1) throw e_1.error; }
|
|
75
|
-
}
|
|
40
|
+
// let done = false;
|
|
41
|
+
// for (const child of paragraph.children) {
|
|
42
|
+
// if (done) {
|
|
43
|
+
// break;
|
|
44
|
+
// }
|
|
45
|
+
// if (child instanceof Run) {
|
|
46
|
+
// for (const runChild of child.children) {
|
|
47
|
+
// if (runChild instanceof Tab) {
|
|
48
|
+
// child.children.splice(child.children.indexOf(runChild), 1);
|
|
49
|
+
// done = true;
|
|
50
|
+
// break;
|
|
51
|
+
// }
|
|
52
|
+
// }
|
|
53
|
+
// }
|
|
54
|
+
// }
|
|
76
55
|
}
|
|
77
56
|
try {
|
|
78
|
-
for (var
|
|
79
|
-
var child =
|
|
57
|
+
for (var _b = __values(paragraph.children), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
58
|
+
var child = _c.value;
|
|
80
59
|
if (child instanceof Run) {
|
|
81
60
|
if (child.fldChar === 'begin') {
|
|
82
61
|
inFldChar = true;
|
|
@@ -101,12 +80,12 @@ function renderParagraph(word, paragraph, renderEmptySpace, inHeader) {
|
|
|
101
80
|
}
|
|
102
81
|
}
|
|
103
82
|
}
|
|
104
|
-
catch (
|
|
83
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
105
84
|
finally {
|
|
106
85
|
try {
|
|
107
|
-
if (
|
|
86
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
108
87
|
}
|
|
109
|
-
finally { if (
|
|
88
|
+
finally { if (e_1) throw e_1.error; }
|
|
110
89
|
}
|
|
111
90
|
// 空行自动加个空格,不然会没高度
|
|
112
91
|
if (p.innerHTML === '' && renderEmptySpace) {
|
package/esm/util/mergeRun.js
CHANGED
|
@@ -35,7 +35,13 @@ function canMerge(element) {
|
|
|
35
35
|
if (childChild.tagName === 'w:t') {
|
|
36
36
|
hasText = true;
|
|
37
37
|
textHasSpace = childChild.getAttribute('xml:space') === 'preserve';
|
|
38
|
-
|
|
38
|
+
if (textHasSpace) {
|
|
39
|
+
break;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
// 有 tab 的情况下不能合并
|
|
43
|
+
if (childChild.tagName === 'w:tab') {
|
|
44
|
+
return false;
|
|
39
45
|
}
|
|
40
46
|
}
|
|
41
47
|
}
|
|
@@ -15,14 +15,13 @@ var setElementStyle = require('./setElementStyle.js');
|
|
|
15
15
|
var renderTab = require('./renderTab.js');
|
|
16
16
|
var OMath = require('../openxml/math/OMath.js');
|
|
17
17
|
var renderMath = require('./renderMath.js');
|
|
18
|
-
var Tab = require('../openxml/word/Tab.js');
|
|
19
18
|
|
|
20
19
|
/**
|
|
21
20
|
* 渲染段落
|
|
22
21
|
* @param renderEmptySpace 如果是 true 的话,当内容为空时会自动加上
|
|
23
22
|
*/
|
|
24
23
|
function renderParagraph(word, paragraph, renderEmptySpace, inHeader) {
|
|
25
|
-
var e_1, _a
|
|
24
|
+
var e_1, _a;
|
|
26
25
|
if (renderEmptySpace === void 0) { renderEmptySpace = true; }
|
|
27
26
|
if (inHeader === void 0) { inHeader = false; }
|
|
28
27
|
word.currentParagraph = paragraph;
|
|
@@ -42,45 +41,25 @@ function renderParagraph(word, paragraph, renderEmptySpace, inHeader) {
|
|
|
42
41
|
// 虽然目前这个实现很 hack,但可以支持常见情况
|
|
43
42
|
dom.appendChild(p, renderTab.renderTab(word, properties.tabs[0], true));
|
|
44
43
|
// 同时删掉第一个 run 中的 tab
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
64
|
-
finally {
|
|
65
|
-
try {
|
|
66
|
-
if (_g && !_g.done && (_b = _f.return)) _b.call(_f);
|
|
67
|
-
}
|
|
68
|
-
finally { if (e_2) throw e_2.error; }
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
74
|
-
finally {
|
|
75
|
-
try {
|
|
76
|
-
if (_e && !_e.done && (_a = _d.return)) _a.call(_d);
|
|
77
|
-
}
|
|
78
|
-
finally { if (e_1) throw e_1.error; }
|
|
79
|
-
}
|
|
44
|
+
// let done = false;
|
|
45
|
+
// for (const child of paragraph.children) {
|
|
46
|
+
// if (done) {
|
|
47
|
+
// break;
|
|
48
|
+
// }
|
|
49
|
+
// if (child instanceof Run) {
|
|
50
|
+
// for (const runChild of child.children) {
|
|
51
|
+
// if (runChild instanceof Tab) {
|
|
52
|
+
// child.children.splice(child.children.indexOf(runChild), 1);
|
|
53
|
+
// done = true;
|
|
54
|
+
// break;
|
|
55
|
+
// }
|
|
56
|
+
// }
|
|
57
|
+
// }
|
|
58
|
+
// }
|
|
80
59
|
}
|
|
81
60
|
try {
|
|
82
|
-
for (var
|
|
83
|
-
var child =
|
|
61
|
+
for (var _b = tslib.__values(paragraph.children), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
62
|
+
var child = _c.value;
|
|
84
63
|
if (child instanceof Run.Run) {
|
|
85
64
|
if (child.fldChar === 'begin') {
|
|
86
65
|
inFldChar = true;
|
|
@@ -105,12 +84,12 @@ function renderParagraph(word, paragraph, renderEmptySpace, inHeader) {
|
|
|
105
84
|
}
|
|
106
85
|
}
|
|
107
86
|
}
|
|
108
|
-
catch (
|
|
87
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
109
88
|
finally {
|
|
110
89
|
try {
|
|
111
|
-
if (
|
|
90
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
112
91
|
}
|
|
113
|
-
finally { if (
|
|
92
|
+
finally { if (e_1) throw e_1.error; }
|
|
114
93
|
}
|
|
115
94
|
// 空行自动加个空格,不然会没高度
|
|
116
95
|
if (p.innerHTML === '' && renderEmptySpace) {
|
package/lib/util/mergeRun.js
CHANGED
|
@@ -39,7 +39,13 @@ function canMerge(element) {
|
|
|
39
39
|
if (childChild.tagName === 'w:t') {
|
|
40
40
|
hasText = true;
|
|
41
41
|
textHasSpace = childChild.getAttribute('xml:space') === 'preserve';
|
|
42
|
-
|
|
42
|
+
if (textHasSpace) {
|
|
43
|
+
break;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
// 有 tab 的情况下不能合并
|
|
47
|
+
if (childChild.tagName === 'w:tab') {
|
|
48
|
+
return false;
|
|
43
49
|
}
|
|
44
50
|
}
|
|
45
51
|
}
|