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
19 changes: 18 additions & 1 deletion packages/super-editor/src/core/super-converter/exporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -1305,7 +1305,16 @@ function generateTableProperties(node) {
const elements = [];

const { attrs } = node;
const { tableWidth, tableWidthType, tableStyleId, borders, tableIndent, tableLayout, tableCellSpacing } = attrs;
const {
tableWidth,
tableWidthType,
tableStyleId,
borders,
tableIndent,
tableLayout,
tableCellSpacing,
justification,
} = attrs;

if (tableStyleId) {
const tableStyleElement = {
Expand Down Expand Up @@ -1355,6 +1364,14 @@ function generateTableProperties(node) {
});
}

if (justification) {
const justificationElement = {
name: 'w:jc',
attributes: { 'w:val': justification },
};
elements.push(justificationElement);
}

return {
name: 'w:tblPr',
elements,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ export function parseMarks(property, unknownMarks = [], docx = null) {
const marks = [];
const seen = new Set();

const lang = property?.elements?.find((el) => el.name === 'w:lang');
const langAttrs = lang?.attributes || {};

property?.elements?.forEach((element) => {
const marksForType = SuperConverter.markTypes.filter((mark) => mark.name === element.name);
if (!marksForType.length) {
Expand Down Expand Up @@ -44,6 +47,11 @@ export function parseMarks(property, unknownMarks = [], docx = null) {
return;
}

// this probably requires a more thorough check.
if (['w:bCs'].includes(m.name) && langAttrs['w:eastAsia']) {
Comment thread
harbournick marked this conversation as resolved.
return;
}

// Use the parent mark (ie: textStyle) if present
if (m.mark) newMark.type = m.mark;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ const getDefaultParagraphStyle = (docx, styleId = '') => {
const pPrNormal = stylesNormal?.elements?.find((el) => el.name === 'w:pPr');
const pPrNormalSpacingTag = pPrNormal?.elements?.find((el) => el.name === 'w:spacing') || {};
const pPrNormalIndentTag = pPrNormal?.elements?.find((el) => el.name === 'w:ind') || {};
const isNormalAsDefault = stylesNormal?.attributes?.['w:default'] === '1';

// Styles based on styleId
let pPrStyleIdSpacingTag = {};
Expand Down Expand Up @@ -299,9 +300,17 @@ const getDefaultParagraphStyle = (docx, styleId = '') => {
const { attributes: pPrNormalIndentAttr } = pPrNormalIndentTag;
const { attributes: pPrByIdIndentAttr } = pPrStyleIdIndentTag;

const spacingRest = isNormalAsDefault
? (pPrNormalSpacingAttr || pPrDefaultSpacingAttr)
: (pPrDefaultSpacingAttr || pPrNormalSpacingAttr);

const indentRest = isNormalAsDefault
? (pPrNormalIndentAttr || pPrDefaultIndentAttr)
: (pPrDefaultIndentAttr || pPrNormalIndentAttr);

return {
spacing: pPrByIdSpacingAttr || pPrDefaultSpacingAttr || pPrNormalSpacingAttr,
indent: pPrByIdIndentAttr || pPrDefaultIndentAttr || pPrNormalIndentAttr,
spacing: pPrByIdSpacingAttr || spacingRest,
indent: pPrByIdIndentAttr || indentRest,
justify: pPrByIdJcAttr,
textCase,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ export function handleTableNode(node, params) {
attrs['borderCollapse'] = 'separate';
}

const tblJustification = tblPr.elements.find((el) => el.name === 'w:jc');
if (tblJustification?.attributes) {
attrs['justification'] = tblJustification.attributes['w:val'];
}

// TODO: What does this do?
// const tblLook = tblPr.elements.find((el) => el.name === 'w:tblLook');

Expand Down
16 changes: 16 additions & 0 deletions packages/super-editor/src/extensions/table/table.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,22 @@ export const Table = Node.create({
},
},

justification: {
default: null,
renderDOM: (attrs) => {
if (!attrs.justification) return {};

if (attrs.justification === 'center') {
return { style: `margin: 0 auto` };
}
if (attrs.justification === 'right') {
return { style: `margin-left: auto` };
}

return {};
},
},

tableStyleId: {
rendered: false,
},
Expand Down
Loading