Skip to content

Commit

Permalink
fix: MDX, esc escalation
Browse files Browse the repository at this point in the history
  • Loading branch information
areknawo committed May 9, 2024
1 parent 54edbba commit 59bfe7b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
10 changes: 8 additions & 2 deletions apps/backend/extensions/src/routes/mdx/output-transformer.ts
Expand Up @@ -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<JSONContentNode["element"]>
)
)
.split("\n")
.map((line) => ` ${line}`)
.join("\n")}${elementWalker.children.length > 1 ? "\n" : ""}\n</${attrs.type}>`;
.join("\n")}${addSpace ? "\n" : ""}\n</${attrs.type}>`;
}

return openingTag;
Expand Down
18 changes: 11 additions & 7 deletions apps/web/src/lib/editor/extensions/shortcuts.ts
Expand Up @@ -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
);
}
}
}
Expand All @@ -83,21 +87,21 @@ 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)
);

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,
Expand Down

0 comments on commit 59bfe7b

Please sign in to comment.