Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ li.ProseMirror-selectednode:after {
pointer-events: none;
}

.ProseMirror img {
height: auto;
max-width: 100%;
}

/* Protect against generic img rules */
img.ProseMirror-separator {
display: inline !important;
Expand Down
28 changes: 26 additions & 2 deletions packages/super-editor/src/core/super-converter/exporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -918,9 +918,12 @@ function generateTableRowProperties(node) {
* @returns {XmlReadyNode} The translated table cell node
*/
function translateTableCell(params) {
const elements = translateChildNodes(params);
const elements = translateChildNodes({
...params,
tableCell: params.node,
});
const cellProps = generateTableCellProperties(params.node);

elements.unshift(cellProps);
return {
name: 'w:tc',
Expand Down Expand Up @@ -1179,6 +1182,7 @@ function getScaledSize(originalWidth, originalHeight, maxWidth, maxHeight) {
function translateImageNode(params, imageSize) {
const {
node: { attrs = {}, marks = [] },
tableCell,
} = params;

let imageId = attrs.rId;
Expand All @@ -1202,6 +1206,16 @@ function translateImageNode(params, imageSize) {
};
}

if (tableCell) {
// Image inside tableCell
const colwidthSum = tableCell.attrs.colwidth.reduce((acc, curr) => acc + curr, 0);
const leftMargin = tableCell.attrs.cellMargins?.left || 8;
const rightMargin = tableCell.attrs.cellMargins?.right || 8;
const maxWidthEmu = pixelsToEmu(colwidthSum - (leftMargin + rightMargin));
const { width: w, height: h } = resizeKeepAspectRatio(size.w, size.h, maxWidthEmu);
if (w && h) size = { w, h };
}

if (params.node.type === 'image' && !imageId) {
const path = src?.split('word/')[1];
imageId = addNewImageRelationship(params, path);
Expand Down Expand Up @@ -1655,3 +1669,13 @@ export class DocxExporter {
return tags;
}
}


function resizeKeepAspectRatio(width, height, maxWidth) {
if (width > maxWidth) {
let scale = maxWidth / width;
let newHeight = Math.round(height * scale);
return { width: maxWidth, height: newHeight };
}
return { width, height };
}