w-html2docx 1.0.10 → 1.0.11

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.
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * w-html2docx v1.0.10
2
+ * w-html2docx v1.0.11
3
3
  * (c) 2018-2021 yuda-lyu(semisphere)
4
4
  * Released under the MIT License.
5
5
  */
@@ -246,7 +246,7 @@ export default WHtml2docx
246
246
  <br class="clear">
247
247
 
248
248
  <footer>
249
- Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.5</a> on Sun Jul 12 2026 14:01:14 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
249
+ Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.5</a> on Sun Jul 19 2026 19:35:35 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
250
250
  </footer>
251
251
 
252
252
  <script>prettyPrint();</script>
package/docs/global.html CHANGED
@@ -593,7 +593,7 @@
593
593
  <br class="clear">
594
594
 
595
595
  <footer>
596
- Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.5</a> on Sun Jul 12 2026 14:01:14 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
596
+ Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.5</a> on Sun Jul 19 2026 19:35:35 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
597
597
  </footer>
598
598
 
599
599
  <script>prettyPrint();</script>
package/docs/index.html CHANGED
@@ -71,7 +71,7 @@
71
71
  <br class="clear">
72
72
 
73
73
  <footer>
74
- Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.5</a> on Sun Jul 12 2026 14:01:14 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
74
+ Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.5</a> on Sun Jul 19 2026 19:35:35 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
75
75
  </footer>
76
76
 
77
77
  <script>prettyPrint();</script>
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "w-html2docx",
3
- "version": "1.0.10",
3
+ "version": "1.0.11",
4
4
  "main": "dist/w-html2docx.umd.js",
5
5
  "dependencies": {
6
6
  "lodash-es": "^4.18.1",
7
- "wsemi": "^1.8.64"
7
+ "wsemi": "^1.8.65"
8
8
  },
9
9
  "devDependencies": {
10
10
  "fflate": "^0.8.3",
@@ -53,6 +53,24 @@ function getParagraphs(xml) {
53
53
  }
54
54
 
55
55
 
56
+ function getTables(xml) {
57
+ //切出全部表格<w:tbl>
58
+ return [...xml.matchAll(/<w:tbl>[\s\S]*?<\/w:tbl>/g)].map((v) => v[0])
59
+ }
60
+
61
+
62
+ function getCells(tbl) {
63
+ //切出表格內全部儲存格<w:tc>, 並標記其文字與是否設定不換行
64
+ return [...tbl.matchAll(/<w:tc>[\s\S]*?<\/w:tc>/g)].map((v) => {
65
+ let s = v[0]
66
+ return {
67
+ noWrap: /<w:noWrap\s*\/>/.test(s), //來源html之white-space:nowrap匯入後為w:tcPr內之w:noWrap
68
+ text: [...s.matchAll(/<w:t[^>]*>([^<]*)<\/w:t>/g)].map((v) => v[1]).join(''),
69
+ }
70
+ })
71
+ }
72
+
73
+
56
74
  describe('WHtml2docx', function() {
57
75
 
58
76
  //check
@@ -143,6 +161,40 @@ describe('WHtml2docx', function() {
143
161
  assert.strict.deepEqual([], rsErr)
144
162
  })
145
163
 
164
+ it('表格內設定white-space:nowrap之儲存格已轉為不換行(w:noWrap)', function() {
165
+
166
+ //tbl, 來源html之4.3表格, 以其獨有之'編號'欄位定位
167
+ let tbl = getTables(xml).find((v) => v.includes('編號'))
168
+ assert.strict.deepEqual(true, w.isestr(tbl))
169
+
170
+ //cells
171
+ let cells = getCells(tbl)
172
+ assert.strict.deepEqual(true, cells.length > 0)
173
+
174
+ //來源html內有設定white-space:nowrap之短欄位, 均須為不換行
175
+ let tsNoWrap = ['編號', '項目', '單位', '狀態', '001', '甲項', '公尺', '完成', '002', '乙項', '公噸', '進行']
176
+ let rsErr = tsNoWrap.filter((t) => {
177
+ let c = cells.find((v) => v.text === t)
178
+ return !c || !c.noWrap
179
+ })
180
+ assert.strict.deepEqual([], rsErr)
181
+
182
+ })
183
+
184
+ it('表格內未設定white-space:nowrap之儲存格維持可換行', function() {
185
+
186
+ //tbl, 來源html之4.3表格
187
+ let tbl = getTables(xml).find((v) => v.includes('編號'))
188
+ let cells = getCells(tbl)
189
+
190
+ //長文字欄位未設定white-space:nowrap, 須維持可換行
191
+ let rs = cells.filter((v) => v.text.length > 10)
192
+ assert.strict.deepEqual(true, rs.length > 0)
193
+ let rsErr = rs.filter((v) => v.noWrap)
194
+ assert.strict.deepEqual([], rsErr)
195
+
196
+ })
197
+
146
198
  it('已移除零寬空格佔位字元(U+200B)', function() {
147
199
  assert.strict.deepEqual(false, xml.includes(String.fromCharCode(0x200B)))
148
200
  })
package/test/ztmp.html CHANGED
@@ -351,6 +351,37 @@
351
351
  </table>
352
352
  </div>
353
353
 
354
+ <h3>4.3 表格測試(寬表格內短欄位不換行 white-space:nowrap)</h3>
355
+ <table style="width:100%;">
356
+ <thead>
357
+ <tr>
358
+ <th style="white-space:nowrap;">編號</th>
359
+ <th style="white-space:nowrap;">項目</th>
360
+ <th>工作內容說明工作內容說明工作內容說明工作內容說明</th>
361
+ <th style="white-space:nowrap;">單位</th>
362
+ <th>後續處理建議後續處理建議後續處理建議後續處理建議</th>
363
+ <th style="white-space:nowrap;">狀態</th>
364
+ </tr>
365
+ </thead>
366
+ <tbody><tr>
367
+ <td style="white-space:nowrap;">001</td>
368
+ <td style="white-space:nowrap;">甲項</td>
369
+ <td>這是一段用來把表格撐寬的說明文字這是一段用來把表格撐寬的說明文字</td>
370
+ <td style="white-space:nowrap;">公尺</td>
371
+ <td>另一段用來擠壓欄寬的長敘述文字另一段用來擠壓欄寬的長敘述文字</td>
372
+ <td style="white-space:nowrap;">完成</td>
373
+ </tr>
374
+ <tr>
375
+ <td style="white-space:nowrap;">002</td>
376
+ <td style="white-space:nowrap;">乙項</td>
377
+ <td>持續追蹤各分項執行進度並定期彙整成果報告與相關佐證資料</td>
378
+ <td style="white-space:nowrap;">公噸</td>
379
+ <td>建議於次期計畫納入延伸應用並擴大場域驗證範圍</td>
380
+ <td style="white-space:nowrap;">進行</td>
381
+ </tr>
382
+ </tbody>
383
+ </table>
384
+
354
385
  <hr>
355
386
 
356
387
  <h2>五、圖片、連結與註腳</h2>
Binary file