Skip to content

Commit

Permalink
Merge pull request #179 from haiwen/repair-long-text-hanlde
Browse files Browse the repository at this point in the history
optimize code
  • Loading branch information
shuntian authored Jun 4, 2024
2 parents 19caf9b + 0670dc9 commit 1683c6e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion src/slate-convert/slate-to-md/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,11 @@ const transformInlineChildren = (result, item) => {
return result;
}

if (item.type && item.type === 'html') {
result.push(item);
return result;
}

// text
const nodes = transformTextNode(item);
result.push(nodes);
Expand Down Expand Up @@ -164,8 +169,9 @@ const transformParagraph = (node) => {

const voidNodeTypes = ['image', 'column', 'formula'];
const hasBlock = children.some(item => voidNodeTypes.includes(item.type));
const hasHtml = children.some(item => item.type === 'html');

if (!hasBlock && Node.string(node).length === 0) {
if (!hasHtml && !hasBlock && Node.string(node).length === 0) {
return {
type: 'paragraph',
children: [
Expand Down
5 changes: 4 additions & 1 deletion src/utils/replace-slate-nodes.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ export const replaceColumnData = (mdNodes, columns, getCellValue, updateImgUrl)
const column = columns.find(column => column.key === data.key);
const value = column ? (getCellValue && getCellValue(column)) : '';
// change column node to text node
const newNode = { 'text': value, 'bold': data.bold, 'italic': data.italic };
let newNode = { 'text': value, 'bold': data.bold, 'italic': data.italic };
if (column.type === 'long-text') {
newNode = { type: 'html', value: value };
}
mdNodes.splice(i, 1, newNode);
continue;
}
Expand Down

0 comments on commit 1683c6e

Please sign in to comment.