@blocknote/xl-docx-exporter 0.22.0 → 0.23.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,6 +3,8 @@ import {
3
3
  COLORS_DEFAULT,
4
4
  DefaultBlockSchema,
5
5
  DefaultProps,
6
+ pageBreakSchema,
7
+ StyledText,
6
8
  UnreachableCaseError,
7
9
  } from "@blocknote/core";
8
10
  import {
@@ -11,6 +13,7 @@ import {
11
13
  ExternalHyperlink,
12
14
  IParagraphOptions,
13
15
  ImageRun,
16
+ PageBreak,
14
17
  Paragraph,
15
18
  ParagraphChild,
16
19
  ShadingType,
@@ -55,7 +58,7 @@ function blockPropsToStyles(
55
58
  };
56
59
  }
57
60
  export const docxBlockMappingForDefaultSchema: BlockMapping<
58
- DefaultBlockSchema,
61
+ DefaultBlockSchema & typeof pageBreakSchema.blockSchema,
59
62
  any,
60
63
  any,
61
64
  | Promise<Paragraph[] | Paragraph | DocxTable>
@@ -131,17 +134,29 @@ export const docxBlockMappingForDefaultSchema: BlockMapping<
131
134
  ...caption(block.props, exporter),
132
135
  ];
133
136
  },
134
- // TODO
135
- codeBlock: (block, exporter) => {
137
+ codeBlock: (block) => {
138
+ const textContent = (block.content as StyledText<any>[])[0]?.text || "";
139
+
136
140
  return new Paragraph({
137
- // ...blockPropsToStyles(block.props, exporter.options.colors),
138
141
  style: "Codeblock",
139
- children: exporter.transformInlineContent(block.content),
140
- // children: [
141
- // new TextRun({
142
- // text: block..type + " not implemented",
143
- // }),
144
- // ],
142
+ shading: {
143
+ type: ShadingType.SOLID,
144
+ fill: "161616",
145
+ color: "161616",
146
+ },
147
+ children: [
148
+ ...textContent.split("\n").map((line, index) => {
149
+ return new TextRun({
150
+ text: line,
151
+ break: index > 0 ? 1 : 0,
152
+ });
153
+ }),
154
+ ],
155
+ });
156
+ },
157
+ pageBreak: () => {
158
+ return new Paragraph({
159
+ children: [new PageBreak()],
145
160
  });
146
161
  },
147
162
  image: async (block, exporter) => {
@@ -67,7 +67,7 @@ export const docxStyleMappingForDefaultSchema: StyleMapping<
67
67
  return {};
68
68
  }
69
69
  return {
70
- font: "Courier New",
70
+ font: "GeistMono",
71
71
  };
72
72
  },
73
73
  };
@@ -1,4 +1,4 @@
1
- import { BlockNoteSchema } from "@blocknote/core";
1
+ import { BlockNoteSchema, defaultBlockSpecs, PageBreak } from "@blocknote/core";
2
2
  import { testDocument } from "@shared/testDocument.js";
3
3
  import AdmZip from "adm-zip";
4
4
  import { Packer, Paragraph, TextRun } from "docx";
@@ -10,7 +10,9 @@ import { DOCXExporter } from "./docxExporter.js";
10
10
  describe("exporter", () => {
11
11
  it("should export a document", { timeout: 10000 }, async () => {
12
12
  const exporter = new DOCXExporter(
13
- BlockNoteSchema.create(),
13
+ BlockNoteSchema.create({
14
+ blockSpecs: { ...defaultBlockSpecs, pageBreak: PageBreak },
15
+ }),
14
16
  docxDefaultSchemaMappings
15
17
  );
16
18
  const doc = await exporter.toDocxJsDocument(testDocument);
@@ -33,7 +35,9 @@ describe("exporter", () => {
33
35
  { timeout: 10000 },
34
36
  async () => {
35
37
  const exporter = new DOCXExporter(
36
- BlockNoteSchema.create(),
38
+ BlockNoteSchema.create({
39
+ blockSpecs: { ...defaultBlockSpecs, pageBreak: PageBreak },
40
+ }),
37
41
  docxDefaultSchemaMappings
38
42
  );
39
43
 
@@ -142,17 +142,35 @@ export class DOCXExporter<
142
142
  // Unfortunately, loading the variable font doesn't work
143
143
  // "./src/fonts/Inter-VariableFont_opsz,wght.ttf",
144
144
 
145
- let font = await loadFileBuffer(
145
+ let interFont = await loadFileBuffer(
146
146
  await import("@shared/assets/fonts/inter/Inter_18pt-Regular.ttf")
147
147
  );
148
+ let geistMonoFont = await loadFileBuffer(
149
+ await import("@shared/assets/fonts/GeistMono-Regular.ttf")
150
+ );
148
151
 
149
- if (font instanceof ArrayBuffer) {
150
- // conversionw with Polyfill needed because docxjs requires Buffer
152
+ if (
153
+ interFont instanceof ArrayBuffer ||
154
+ geistMonoFont instanceof Uint8Array
155
+ ) {
156
+ // conversion with Polyfill needed because docxjs requires Buffer
151
157
  const Buffer = (await import("buffer")).Buffer;
152
- font = Buffer.from(font);
158
+
159
+ if (interFont instanceof ArrayBuffer) {
160
+ interFont = Buffer.from(interFont);
161
+ }
162
+ if (geistMonoFont instanceof ArrayBuffer) {
163
+ geistMonoFont = Buffer.from(geistMonoFont);
164
+ }
153
165
  }
154
166
 
155
- return [{ name: "Inter", data: font as Buffer }];
167
+ return [
168
+ { name: "Inter", data: interFont as Buffer },
169
+ {
170
+ name: "GeistMono",
171
+ data: geistMonoFont as Buffer,
172
+ },
173
+ ];
156
174
  }
157
175
 
158
176
  protected async createDefaultDocumentOptions(): Promise<DocumentOptions> {
@@ -983,8 +983,8 @@
983
983
  <w:basedOn w:val="Normal" />
984
984
  <w:rPr>
985
985
  <w:noProof />
986
- <w:color w:val="e1e4e8" />
987
- <w:shd w:fill="161616" />
986
+ <w:color w:val="ffffff"/>
987
+ <w:rFonts w:ascii="GeistMono" w:cs="GeistMono" w:eastAsia="GeistMono" w:hAnsi="GeistMono"/>
988
988
  </w:rPr>
989
989
  </w:style>
990
990
  </w:styles>
@@ -1,3 +1,3 @@
1
- import { BlockMapping, DefaultBlockSchema } from "@blocknote/core";
1
+ import { BlockMapping, DefaultBlockSchema, pageBreakSchema } from "@blocknote/core";
2
2
  import { Table as DocxTable, Paragraph, ParagraphChild } from "docx";
3
- export declare const docxBlockMappingForDefaultSchema: BlockMapping<DefaultBlockSchema, any, any, Promise<Paragraph[] | Paragraph | DocxTable> | Paragraph[] | Paragraph | DocxTable, ParagraphChild>;
3
+ export declare const docxBlockMappingForDefaultSchema: BlockMapping<DefaultBlockSchema & typeof pageBreakSchema.blockSchema, any, any, Promise<Paragraph[] | Paragraph | DocxTable> | Paragraph[] | Paragraph | DocxTable, ParagraphChild>;
@@ -446,6 +446,23 @@ export declare const docxDefaultSchemaMappings: {
446
446
  fileBlockAccept: string[];
447
447
  }, any, import("@blocknote/core").InlineContentSchema, import("@blocknote/core").StyleSchema>;
448
448
  };
449
+ }> & import("@blocknote/core").BlockSchemaFromSpecs<{
450
+ pageBreak: {
451
+ config: {
452
+ type: "pageBreak";
453
+ propSchema: {};
454
+ content: "none";
455
+ isFileBlock: false;
456
+ isSelectable: false;
457
+ };
458
+ implementation: import("@blocknote/core").TiptapBlockImplementation<{
459
+ type: "pageBreak";
460
+ propSchema: {};
461
+ content: "none";
462
+ isFileBlock: false;
463
+ isSelectable: false;
464
+ }, any, import("@blocknote/core").InlineContentSchema, import("@blocknote/core").StyleSchema>;
465
+ };
449
466
  }>, any, any, import("docx").Table | import("docx").Paragraph | import("docx").Paragraph[] | Promise<import("docx").Table | import("docx").Paragraph | import("docx").Paragraph[]>, import("docx").ParagraphChild>;
450
467
  inlineContentMapping: import("@blocknote/core").InlineContentMapping<import("@blocknote/core").InlineContentSchemaFromSpecs<{
451
468
  text: {