@adobe/helix-md2docx 2.1.78 → 2.1.79
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/CHANGELOG.md +7 -0
- package/package.json +2 -2
- package/src/mdast2docx/handlers/image.js +17 -118
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
## [2.1.79](https://github.com/adobe/helix-md2docx/compare/v2.1.78...v2.1.79) (2024-10-16)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* **deps:** update dependency docx to v9 ([#495](https://github.com/adobe/helix-md2docx/issues/495)) ([88808e0](https://github.com/adobe/helix-md2docx/commit/88808e0f7a1b1aafb2f8a6a5d39607f1a3315398))
|
|
7
|
+
|
|
1
8
|
## [2.1.78](https://github.com/adobe/helix-md2docx/compare/v2.1.77...v2.1.78) (2024-10-15)
|
|
2
9
|
|
|
3
10
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adobe/helix-md2docx",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.79",
|
|
4
4
|
"description": "Helix Service that converts markdown to word documents",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"@adobe/helix-markdown-support": "7.1.6",
|
|
34
34
|
"@adobe/helix-shared-process-queue": "3.0.4",
|
|
35
35
|
"@adobe/remark-gridtables": "3.0.6",
|
|
36
|
-
"docx": "
|
|
36
|
+
"docx": "9.0.2",
|
|
37
37
|
"github-slugger": "2.0.0",
|
|
38
38
|
"hast-util-is-element": "3.0.0",
|
|
39
39
|
"hast-util-to-mdast": "10.1.0",
|
|
@@ -9,10 +9,7 @@
|
|
|
9
9
|
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
10
|
* governing permissions and limitations under the License.
|
|
11
11
|
*/
|
|
12
|
-
import {
|
|
13
|
-
Drawing, ImageRun, XmlComponent, XmlAttributeComponent,
|
|
14
|
-
} from 'docx';
|
|
15
|
-
import { findXMLComponent } from '../utils.js';
|
|
12
|
+
import { ImageRun } from 'docx';
|
|
16
13
|
|
|
17
14
|
// max image width (6.5") and height (2")
|
|
18
15
|
const LIMITS = {
|
|
@@ -31,6 +28,7 @@ export default async function image(ctx, node) {
|
|
|
31
28
|
if (!data) {
|
|
32
29
|
return undefined;
|
|
33
30
|
}
|
|
31
|
+
|
|
34
32
|
let x = data.dimensions.width * 9525;
|
|
35
33
|
let y = data.dimensions.height * 9525;
|
|
36
34
|
const limits = ctx.tableAlign ? LIMITS_TABLE : LIMITS;
|
|
@@ -43,127 +41,28 @@ export default async function image(ctx, node) {
|
|
|
43
41
|
y = limits.height;
|
|
44
42
|
}
|
|
45
43
|
|
|
46
|
-
const
|
|
47
|
-
|
|
48
|
-
|
|
44
|
+
const options = {
|
|
45
|
+
type: data.dimensions.type || 'png',
|
|
46
|
+
data: data.buffer,
|
|
49
47
|
transformation: {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
y: Math.round(data.dimensions.height),
|
|
53
|
-
},
|
|
54
|
-
emus: {
|
|
55
|
-
x,
|
|
56
|
-
y,
|
|
57
|
-
},
|
|
48
|
+
width: Math.max(x / 9525, 32),
|
|
49
|
+
height: Math.max(y / 9525, 32),
|
|
58
50
|
},
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
const drawing = new Drawing(imageData, {
|
|
62
|
-
floating: false,
|
|
63
|
-
docProperties: {
|
|
51
|
+
altText: {
|
|
64
52
|
title: node.title || '',
|
|
65
53
|
description: node.alt || '',
|
|
66
54
|
name: node.title || node.alt || '',
|
|
67
55
|
},
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
// create picture
|
|
71
|
-
const pic = new ImageRun({
|
|
72
|
-
data: data.buffer,
|
|
73
|
-
transformation: data.dimensions,
|
|
74
|
-
});
|
|
75
|
-
// replace drawing
|
|
76
|
-
const oldDrawing = findXMLComponent(pic, 'w:drawing');
|
|
77
|
-
const idx = pic.root.indexOf(oldDrawing);
|
|
78
|
-
if (idx >= 0) {
|
|
79
|
-
pic.root.splice(idx, 1);
|
|
80
|
-
}
|
|
81
|
-
pic.root.push(drawing);
|
|
82
|
-
pic.key = data.key;
|
|
83
|
-
pic.imageData = imageData;
|
|
84
|
-
|
|
85
|
-
// for SVGs, we need to generate a proper svgBlip
|
|
86
|
-
/*
|
|
87
|
-
<pic:blipFill>
|
|
88
|
-
<a:blip r:embed="rId4">
|
|
89
|
-
<a:extLst>
|
|
90
|
-
<a:ext uri="{28A0092B-C50C-407E-A947-70E740481C1C}">
|
|
91
|
-
<a14:useLocalDpi val="0" xmlns:a14="http://schemas.microsoft.com/office/drawing/2010/main"/>
|
|
92
|
-
</a:ext>
|
|
93
|
-
<a:ext uri="{96DAC541-7B7A-43D3-8B79-37D633B846F1}">
|
|
94
|
-
<asvg:svgBlip r:embed="rId5" xmlns:asvg="http://schemas.microsoft.com/office/drawing/2016/SVG/main"/>
|
|
95
|
-
</a:ext>
|
|
96
|
-
</a:extLst>
|
|
97
|
-
</a:blip>
|
|
98
|
-
<a:stretch>
|
|
99
|
-
<a:fillRect/>
|
|
100
|
-
</a:stretch>
|
|
101
|
-
</pic:blipFill>
|
|
102
|
-
*/
|
|
103
|
-
|
|
104
|
-
class SvgBlip extends XmlComponent {
|
|
105
|
-
constructor(imgData) {
|
|
106
|
-
super('asvg:svgBlip');
|
|
107
|
-
this.imageData = imgData;
|
|
108
|
-
this.addChildElement(new XmlAttributeComponent({
|
|
109
|
-
'xmlns:asvg': 'http://schemas.microsoft.com/office/drawing/2016/SVG/main',
|
|
110
|
-
'r:embed': `rId{${imgData.fileName}}`,
|
|
111
|
-
}));
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
prepForXml(context) {
|
|
115
|
-
// add the svg data if it has a stream
|
|
116
|
-
if (this.imageData.stream) {
|
|
117
|
-
context.file.Media.addImage(this.imageData.fileName, this.imageData);
|
|
118
|
-
}
|
|
56
|
+
};
|
|
119
57
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
}
|
|
128
|
-
return super.prepForXml(context);
|
|
129
|
-
}
|
|
58
|
+
if (data.originalType === 'image/svg' || data.originalType === 'image/svg+xml') {
|
|
59
|
+
options.type = 'svg';
|
|
60
|
+
options.data = data.originalBuffer;
|
|
61
|
+
options.fallback = {
|
|
62
|
+
type: data.ext,
|
|
63
|
+
data: data.buffer,
|
|
64
|
+
};
|
|
130
65
|
}
|
|
131
66
|
|
|
132
|
-
|
|
133
|
-
// create a fake image run for the svg image
|
|
134
|
-
const ir = new ImageRun({
|
|
135
|
-
data: data.originalBuffer,
|
|
136
|
-
transformation: data.dimensions,
|
|
137
|
-
});
|
|
138
|
-
ir.imageData.fileName = data.svgKey;
|
|
139
|
-
|
|
140
|
-
const blipFill = findXMLComponent(drawing, 'wp:inline/a:graphic/a:graphicData/pic:pic/pic:blipFill');
|
|
141
|
-
const blip = findXMLComponent(blipFill, 'a:blip');
|
|
142
|
-
|
|
143
|
-
// const blipAttrs = findXMLComponent(oldBlip, '_attr');
|
|
144
|
-
// blipAttrs.root.embed = `rId{${ir.imageData.fileName}}`;
|
|
145
|
-
|
|
146
|
-
// add svg stuff
|
|
147
|
-
// const newBlip = new XmlComponent('a:blip')
|
|
148
|
-
blip
|
|
149
|
-
.addChildElement(new XmlComponent('a:extLst')
|
|
150
|
-
.addChildElement(new XmlComponent('a:ext')
|
|
151
|
-
.addChildElement(new XmlAttributeComponent({
|
|
152
|
-
uri: '{28A0092B-C50C-407E-A947-70E740481C1C}',
|
|
153
|
-
}))
|
|
154
|
-
.addChildElement(new XmlComponent('a14:useLocalDpi')
|
|
155
|
-
.addChildElement(new XmlAttributeComponent({
|
|
156
|
-
'xmlns:a14': 'http://schemas.microsoft.com/office/drawing/2010/main',
|
|
157
|
-
val: '0',
|
|
158
|
-
}))))
|
|
159
|
-
.addChildElement(new XmlComponent('a:ext')
|
|
160
|
-
.addChildElement(new XmlAttributeComponent({
|
|
161
|
-
uri: '{96DAC541-7B7A-43D3-8B79-37D633B846F1}',
|
|
162
|
-
}))
|
|
163
|
-
.addChildElement(new SvgBlip(ir.imageData))));
|
|
164
|
-
|
|
165
|
-
// replace blip
|
|
166
|
-
// blipFill.root.splice(blipFill.root.indexOf(oldBlip), 1, newBlip);
|
|
167
|
-
}
|
|
168
|
-
return pic;
|
|
67
|
+
return new ImageRun(options);
|
|
169
68
|
}
|