diff --git a/apps/backend/extensions/src/routes/mdx/output-transformer.ts b/apps/backend/extensions/src/routes/mdx/output-transformer.ts index 0c0a5c91..42014831 100644 --- a/apps/backend/extensions/src/routes/mdx/output-transformer.ts +++ b/apps/backend/extensions/src/routes/mdx/output-transformer.ts @@ -157,14 +157,20 @@ const mdxAsyncOutputTransformer = async ( ); if (elementWalker.children.length > 0) { - return `${openingTag}\n${elementWalker.children.length > 1 ? "\n" : ""}${( + const addSpace = + elementWalker.children.length > 1 || + ["orderedList", "bulletList", "taskList", "table"].includes( + elementWalker.children[0].node.type + ); + + return `${openingTag}\n${addSpace ? "\n" : ""}${( await transformContentNode( elementWalker as JSONContentNodeWalker ) ) .split("\n") .map((line) => ` ${line}`) - .join("\n")}${elementWalker.children.length > 1 ? "\n" : ""}\n`; + .join("\n")}${addSpace ? "\n" : ""}\n`; } return openingTag; diff --git a/apps/web/src/lib/editor/extensions/shortcuts.ts b/apps/web/src/lib/editor/extensions/shortcuts.ts index 0d72a4a9..178844b2 100644 --- a/apps/web/src/lib/editor/extensions/shortcuts.ts +++ b/apps/web/src/lib/editor/extensions/shortcuts.ts @@ -70,7 +70,11 @@ const Shortcuts = Extension.create({ parent.type.name === "element" && parent.attrs.type.toLowerCase() === customView.type ) { - return ElementSelection.create(doc, selection.$from.before(depth), false); + return ElementSelection.create( + doc, + selection.$from.before(Math.max(depth, 1)), + false + ); } } } @@ -83,7 +87,7 @@ const Shortcuts = Extension.create({ const currentDepth = selection.$from.depth; if (isElementSelection(selection) && selection.node.type.name === "element") { - const newDepth = currentDepth; + const newDepth = Math.max(currentDepth, 1); const newSelection = getProperElementSelection( newDepth, ElementSelection.create(doc, selection.$from.before(newDepth), false) @@ -91,13 +95,13 @@ const Shortcuts = Extension.create({ dispatch(tr.setSelection(newSelection)); } else { - const newDepth = currentDepth - (selection instanceof CellSelection ? 2 : 1); - - let newSelection = NodeSelection.create( - doc, - selection.$from.before(Math.max(newDepth, 1)) + const newDepth = Math.max( + currentDepth - (selection instanceof CellSelection ? 2 : 1), + 1 ); + let newSelection = NodeSelection.create(doc, selection.$from.before(newDepth)); + if (newSelection.node.type.name === "element") { newSelection = getProperElementSelection( newDepth,