Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Custom start index for ordered lists (#1299), improved support for copy/pasting tables into speadsheets (#1298) #1311

Closed
wants to merge 7 commits into from
Closed
6 changes: 5 additions & 1 deletion packages/core/src/api/clipboard/toClipboard/copyExtension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,11 @@ function fragmentToExternalHTML<
editor.schema.styleSchema
);

externalHTML = externalHTMLExporter.exportInlineContent(ic as any, {});
// Wrap in table to ensure correct parsing by spreadsheet applications
externalHTML = `<table>${externalHTMLExporter.exportInlineContent(
ic as any,
{}
)}</table>`;
} else if (isWithinBlockContent) {
// first convert selection to blocknote-style inline content, and then
// pass this to the exporter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,14 @@ function serializeBlock<
if (listType) {
if (fragment.lastChild?.nodeName !== listType) {
const list = doc.createElement(listType);

if (listType === "OL") {
const index = block.props?.index;

if (index !== undefined) {
areknawo marked this conversation as resolved.
Show resolved Hide resolved
list.setAttribute("start", index.toString());
}
}
fragment.append(list);
}
const li = doc.createElement("li");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const NumberedListIndexingPlugin = () => {
node.type.name === "blockContainer" &&
node.firstChild!.type.name === "numberedListItem"
) {
let newIndex = "1";
let newIndex = `${node.firstChild!.attrs["index"] || 1}`;

const blockInfo = getBlockInfo({
posBeforeNode: pos,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { NumberedListIndexingPlugin } from "./NumberedListIndexingPlugin.js";

export const numberedListItemPropSchema = {
...defaultProps,
index: { default: 1 },
} satisfies PropSchema;

const NumberedListItemBlockContent = createStronglyTypedTiptapNode({
Expand All @@ -38,8 +39,8 @@ const NumberedListItemBlockContent = createStronglyTypedTiptapNode({
return [
// Creates an ordered list when starting with "1.".
new InputRule({
find: new RegExp(`^1\\.\\s$`),
handler: ({ state, chain, range }) => {
find: new RegExp(`^(\\d+)\\.\\s$`),
handler: ({ state, chain, range, match }) => {
const blockInfo = getBlockInfoFromSelection(state);
if (
!blockInfo.isBlockContainer ||
Expand All @@ -55,7 +56,9 @@ const NumberedListItemBlockContent = createStronglyTypedTiptapNode({
blockInfo.bnBlock.beforePos,
{
type: "numberedListItem",
props: {},
props: {
index: parseInt(match[1]) as any,
},
}
)
)
Expand Down Expand Up @@ -116,7 +119,9 @@ const NumberedListItemBlockContent = createStronglyTypedTiptapNode({
parent.tagName === "OL" ||
(parent.tagName === "DIV" && parent.parentElement!.tagName === "OL")
) {
return {};
return {
index: parseInt(parent.getAttribute("start") || "1") || 1,
};
}

return false;
Expand Down
Loading