@kerebron/extension-odt 0.4.20 → 0.4.22

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.
@@ -1,10 +1,15 @@
1
1
  import type { Schema } from 'prosemirror-model';
2
- import { type Converter, type CoreEditor, Extension } from '@kerebron/editor';
3
- export interface OdtConfig {
4
- linkFromRewriter?(href: string): string;
2
+ import { type Converter, type CoreEditor, Extension, type UrlRewriter } from '@kerebron/editor';
3
+ import { OdtParserConfig } from './OdtParser.js';
4
+ import { Command } from '@kerebron/editor/commands';
5
+ export interface OdtConfig extends OdtParserConfig {
6
+ debug?: boolean;
7
+ postProcessCommands?: Command[];
5
8
  }
6
9
  export declare class ExtensionOdt extends Extension {
10
+ config: OdtConfig;
7
11
  name: string;
12
+ urlFromRewriter?: UrlRewriter;
8
13
  constructor(config?: OdtConfig);
9
14
  getConverters(editor: CoreEditor, schema: Schema): Record<string, Converter>;
10
15
  }
@@ -1 +1 @@
1
- {"version":3,"file":"ExtensionOdt.d.ts","sourceRoot":"","sources":["../src/ExtensionOdt.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAQ,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAEtD,OAAO,EAAE,KAAK,SAAS,EAAE,KAAK,UAAU,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAM9E,MAAM,WAAW,SAAS;IACxB,gBAAgB,CAAC,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC;CACzC;AAED,qBAAa,YAAa,SAAQ,SAAS;IACzC,IAAI,SAAS;gBAED,MAAM,GAAE,SAAc;IAIzB,aAAa,CACpB,MAAM,EAAE,UAAU,EAClB,MAAM,EAAE,MAAM,GACb,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC;CAiD7B"}
1
+ {"version":3,"file":"ExtensionOdt.d.ts","sourceRoot":"","sources":["../src/ExtensionOdt.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAQ,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAEtD,OAAO,EACL,KAAK,SAAS,EACd,KAAK,UAAU,EACf,SAAS,EACT,KAAK,WAAW,EACjB,MAAM,kBAAkB,CAAC;AAG1B,OAAO,EAAa,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAE5D,OAAO,EAAE,OAAO,EAAE,MAAM,2BAA2B,CAAC;AAEpD,MAAM,WAAW,SAAU,SAAQ,eAAe;IAChD,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,mBAAmB,CAAC,EAAE,OAAO,EAAE,CAAC;CACjC;AAED,qBAAa,YAAa,SAAQ,SAAS;IAIb,MAAM,EAAE,SAAS;IAH7C,IAAI,SAAS;IACN,eAAe,CAAC,EAAE,WAAW,CAAC;gBAET,MAAM,GAAE,SAAc;IAIzC,aAAa,CACpB,MAAM,EAAE,UAAU,EAClB,MAAM,EAAE,MAAM,GACb,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC;CAmE7B"}
@@ -1,11 +1,14 @@
1
- import { Extension } from '@kerebron/editor';
1
+ import { Extension, } from '@kerebron/editor';
2
2
  import { parse_content, parse_styles, unzip } from '@kerebron/odt-wasm';
3
3
  import { OdtParser } from './OdtParser.js';
4
4
  import { getDefaultsPostProcessFilters } from './postprocess/postProcess.js';
5
5
  export class ExtensionOdt extends Extension {
6
+ config;
6
7
  name = 'odt';
8
+ urlFromRewriter;
7
9
  constructor(config = {}) {
8
10
  super(config);
11
+ this.config = config;
9
12
  }
10
13
  getConverters(editor, schema) {
11
14
  const config = this.config;
@@ -14,8 +17,11 @@ export class ExtensionOdt extends Extension {
14
17
  throw new Error('Not implemented');
15
18
  },
16
19
  toDoc: async (buffer) => {
17
- const doc = await odtConverter.odtToJson(buffer);
18
- const filterCommands = getDefaultsPostProcessFilters();
20
+ const { doc, filesMap } = await odtConverter.odtToJson(buffer);
21
+ const filterCommands = getDefaultsPostProcessFilters({
22
+ doc,
23
+ filesMap,
24
+ }).concat(this.config.postProcessCommands || []);
19
25
  if (filterCommands.length > 0) {
20
26
  const subEditor = editor.clone();
21
27
  subEditor.setDocument(doc.toJSON());
@@ -34,9 +40,21 @@ export class ExtensionOdt extends Extension {
34
40
  }
35
41
  const stylesTree = parse_styles(files.get('styles.xml'));
36
42
  const contentTree = parse_content(files.get('content.xml'));
37
- const parser = new OdtParser(editor.schema, config);
43
+ if (this.config.debug) {
44
+ const event = new CustomEvent('odt:parsed', {
45
+ detail: {
46
+ stylesTree,
47
+ contentTree,
48
+ filesMap,
49
+ },
50
+ });
51
+ this.editor.dispatchEvent(event);
52
+ }
53
+ const parser = new OdtParser(editor.schema, this.config);
54
+ parser.urlRewriter = this.urlFromRewriter;
55
+ parser.filesMap = filesMap;
38
56
  const doc = parser.parse({ ...filesMap, contentTree, stylesTree });
39
- return doc;
57
+ return { doc, stylesTree, contentTree, filesMap };
40
58
  },
41
59
  };
42
60
  return {
@@ -1,5 +1,6 @@
1
1
  import { Mark, Node, Schema } from 'prosemirror-model';
2
2
  import { ListTracker } from './lists.js';
3
+ import { type UrlRewriter } from '@kerebron/editor';
3
4
  export interface OdtElement {
4
5
  $value: 'TODO';
5
6
  }
@@ -32,8 +33,7 @@ export declare function tagEnum(item: any): {
32
33
  };
33
34
  export declare function iterateChildren(nodes: unknown[], callback: (item: TaggedEnum) => void): void;
34
35
  export declare function iterateEnum($value: unknown[]): Array<TaggedEnum>;
35
- interface Config {
36
- linkFromRewriter?(href: string): string;
36
+ export interface OdtParserConfig {
37
37
  }
38
38
  export interface OdtContext {
39
39
  handlers: Record<string, NodeHandler>;
@@ -48,6 +48,7 @@ export declare class OdtStashContext {
48
48
  private ctxStash;
49
49
  private currentCtx;
50
50
  listTracker: ListTracker;
51
+ urlRewriter?: UrlRewriter;
51
52
  constructor(schema: Schema, handlers: Record<string, NodeHandler>, stylesTree: StylesTree, automaticStyles: AutomaticStyles);
52
53
  stash(): number;
53
54
  unstash(): void;
@@ -63,7 +64,9 @@ export declare class OdtStashContext {
63
64
  export declare class OdtParser {
64
65
  private readonly schema;
65
66
  private readonly config;
66
- constructor(schema: Schema, config?: Config);
67
+ constructor(schema: Schema, config?: OdtParserConfig);
68
+ filesMap?: Record<string, Uint8Array<ArrayBufferLike>>;
69
+ urlRewriter?: UrlRewriter;
67
70
  parse(files: any): Node;
68
71
  }
69
72
  export {};
@@ -1 +1 @@
1
- {"version":3,"file":"OdtParser.d.ts","sourceRoot":"","sources":["../src/OdtParser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAOvD,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAIzC,MAAM,WAAW,UAAU;IACzB,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,MAAM,WAAW,GAAG,CAAC,GAAG,EAAE,eAAe,EAAE,KAAK,EAAE,GAAG,KAAK,IAAI,CAAC;AAErE,UAAU,SAAS;IACjB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,UAAU,KAAK;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,MAAM,EAAE,MAAM,EAAE,CAAC;CAClB;AAED,UAAU,UAAU;IAClB,MAAM,EAAE;QACN,YAAY,EAAE,KAAK,CAAC,SAAS,CAAC,CAAC;QAC/B,OAAO,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC;KACvB,CAAC;CACH;AAED,UAAU,eAAe;IACvB,OAAO,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC;CACvB;AAED,wBAAgB,YAAY,CAC1B,UAAU,EAAE,UAAU,EACtB,eAAe,EAAE,eAAe,EAChC,IAAI,EAAE,MAAM,GACX,KAAK,CA4CP;AAED,MAAM,WAAW,UAAU;IACzB,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,GAAG,CAAC;CACZ;AAED,wBAAgB,OAAO,CAAC,IAAI,EAAE,GAAG;;;EAkBhC;AAED,wBAAgB,e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;CACF;AAED,qBAAa,SAAS;IAElB,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,MAAM;gBADN,MAAM,EAAE,MAAM,EACd,MAAM,GAAE,eAAoB;IAGxC,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,eAAe,CAAC,CAAC,CAAC;IACvD,WAAW,CAAC,EAAE,WAAW,CAAC;IAEjC,KAAK,CAAC,KAAK,EAAE,GAAG;CA6EjB"}
package/esm/OdtParser.js CHANGED
@@ -79,6 +79,7 @@ export class OdtStashContext {
79
79
  ctxStash = [];
80
80
  currentCtx;
81
81
  listTracker = new ListTracker();
82
+ urlRewriter;
82
83
  constructor(schema, handlers, stylesTree, automaticStyles) {
83
84
  this.schema = schema;
84
85
  this.stylesTree = stylesTree;
@@ -189,6 +190,8 @@ export class OdtParser {
189
190
  this.schema = schema;
190
191
  this.config = config;
191
192
  }
193
+ filesMap;
194
+ urlRewriter;
192
195
  parse(files) {
193
196
  const contentTree = files.contentTree;
194
197
  const stylesTree = files.stylesTree;
@@ -220,7 +223,7 @@ export class OdtParser {
220
223
  const content = new TextDecoder().decode(files[fullPath]);
221
224
  ctx.openNode();
222
225
  ctx.closeNode('math', {
223
- type: 'mathml',
226
+ lang: 'mathml',
224
227
  content,
225
228
  });
226
229
  return;
@@ -228,21 +231,27 @@ export class OdtParser {
228
231
  }
229
232
  if (odtElement.image && odtElement.image['@href']) { // TODO links rewrite
230
233
  const alt = odtElement.description?.value || '';
234
+ let src = odtElement.image['@href'];
235
+ if (ctx.urlRewriter) {
236
+ src = ctx.urlRewriter(src, {
237
+ type: 'IMG',
238
+ dest: 'kerebron',
239
+ filesMap: this.filesMap,
240
+ });
241
+ }
231
242
  ctx.openNode();
232
243
  ctx.closeNode('image', {
233
- src: odtElement.image['@href'],
244
+ src,
234
245
  alt,
235
246
  });
236
247
  }
237
248
  },
238
- 'rect': () => {
239
- // ignore: true,
240
- },
241
249
  'annotation': () => {
242
250
  // ignore: true,
243
251
  },
244
252
  };
245
253
  const ctx = new OdtStashContext(this.schema, handlers, stylesTree, contentTree['automatic-styles']);
254
+ ctx.urlRewriter = this.urlRewriter;
246
255
  ctx.openNode();
247
256
  ctx.handle('body', contentTree.body);
248
257
  return ctx.closeNode('doc');
@@ -1 +1 @@
1
- {"version":3,"file":"basic_node_handlers.d.ts","sourceRoot":"","sources":["../../src/node_handlers/basic_node_handlers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmB,WAAW,EAAmB,MAAM,iBAAiB,CAAC;AAEhF,wBAAgB,sBAAsB,IAAI,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,CAiEpE;AAED,wBAAgB,qBAAqB,IAAI,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,CA2FnE"}
1
+ {"version":3,"file":"basic_node_handlers.d.ts","sourceRoot":"","sources":["../../src/node_handlers/basic_node_handlers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmB,WAAW,EAAmB,MAAM,iBAAiB,CAAC;AAEhF,wBAAgB,sBAAsB,IAAI,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,CA4DpE;AAED,wBAAgB,qBAAqB,IAAI,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,CA+FnE"}
@@ -9,7 +9,7 @@ export function getInlineNodesHandlers() {
9
9
  },
10
10
  's': (ctx, odtElement) => {
11
11
  const chars = odtElement['@c'] || 1;
12
- const text = ' '.substring(0, chars);
12
+ const text = ' '.repeat(chars);
13
13
  const node = ctx.createText(text);
14
14
  if (node) {
15
15
  ctx.current.content.push(node);
@@ -21,6 +21,12 @@ export function getInlineNodesHandlers() {
21
21
  ctx.current.content.push(node);
22
22
  }
23
23
  },
24
+ 'rect': (ctx, odtElement) => {
25
+ // if (odtElement['@rel-width'] === '100%') {
26
+ // ctx.openNode();
27
+ // ctx.closeNode('hr');
28
+ // }
29
+ },
24
30
  'line-break': (ctx, odtElement) => {
25
31
  ctx.openNode();
26
32
  ctx.closeNode('br');
@@ -29,38 +35,28 @@ export function getInlineNodesHandlers() {
29
35
  ctx.openNode();
30
36
  ctx.closeNode('br');
31
37
  },
32
- 'bookmark': (ctx, value) => {
33
- // ctx.current.marks = [ ...ctx.current.marks, ...marks ];
38
+ 'bookmark': (ctx, element) => {
39
+ ctx.openNode();
40
+ ctx.closeNode('bookmark-node', {
41
+ id: element['@name'],
42
+ });
43
+ },
44
+ 'bookmark-start': (ctx, element) => {
45
+ // state.textMarks.add({
46
+ // markName: 'bookmark',
47
+ // markAttributes: {
48
+ // id: element['@name'],
49
+ // },
50
+ // });
51
+ },
52
+ 'bookmark-end': (ctx, element) => {
53
+ // state.textMarks.forEach((x) =>
54
+ // x.markName === 'bookmark' &&
55
+ // x.markAttributes.id === element['@name']
56
+ // ? state.textMarks.delete(x)
57
+ // : x
58
+ // );
34
59
  },
35
- // custom(state, element) {
36
- // state.nextTextMarks.add({
37
- // markName: 'bookmark',
38
- // markAttributes: {
39
- // id: element['@name'],
40
- // },
41
- // });
42
- // },
43
- // },
44
- // 'bookmark-start': {
45
- // custom(state, element) {
46
- // state.textMarks.add({
47
- // markName: 'bookmark',
48
- // markAttributes: {
49
- // id: element['@name'],
50
- // },
51
- // });
52
- // },
53
- // },
54
- // 'bookmark-end': {
55
- // custom(state, element) {
56
- // state.textMarks.forEach((x) =>
57
- // x.markName === 'bookmark' &&
58
- // x.markAttributes.id === element['@name']
59
- // ? state.textMarks.delete(x)
60
- // : x
61
- // );
62
- // },
63
- // },
64
60
  };
65
61
  }
66
62
  export function getBasicNodesHandlers() {
@@ -117,6 +113,9 @@ export function getBasicNodesHandlers() {
117
113
  },
118
114
  'a': (ctx, value) => {
119
115
  let href = value['@href'];
116
+ if (ctx.urlRewriter) {
117
+ href = ctx.urlRewriter(href, { type: 'A', dest: 'kerebron' });
118
+ }
120
119
  const attrs = {
121
120
  href,
122
121
  // title: tok.attrGet('title') || null,
@@ -1,3 +1,3 @@
1
- import { ParseSpec } from '../OdtParser.js';
2
- export declare function getListNodesHandlers(): Record<string, ParseSpec>;
1
+ import { NodeHandler } from '../OdtParser.js';
2
+ export declare function getListNodesHandlers(): Record<string, NodeHandler>;
3
3
  //# sourceMappingURL=list_node_handlers.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"list_node_handlers.d.ts","sourceRoot":"","sources":["../../src/node_handlers/list_node_handlers.ts"],"names":[],"mappings":"AACA,OAAO,EAGL,SAAS,EAEV,MAAM,iBAAiB,CAAC;AAEzB,wBAAgB,oBAAoB,IAAI,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,CA0HhE"}
1
+ {"version":3,"file":"list_node_handlers.d.ts","sourceRoot":"","sources":["../../src/node_handlers/list_node_handlers.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,WAAW,EAGZ,MAAM,iBAAiB,CAAC;AAEzB,wBAAgB,oBAAoB,IAAI,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,CA0HlE"}
@@ -0,0 +1,3 @@
1
+ import { Command } from 'prosemirror-state';
2
+ export declare const convertMathMl: Command;
3
+ //# sourceMappingURL=convertMathMl.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"convertMathMl.d.ts","sourceRoot":"","sources":["../../src/postprocess/convertMathMl.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAI5C,eAAO,MAAM,aAAa,EAAE,OAiD3B,CAAC"}
@@ -0,0 +1,35 @@
1
+ // Related tests:
2
+ // test ./example-document.md
3
+ export const convertMathMl = (state, dispatch) => {
4
+ const doc = state.doc;
5
+ const schema = state.schema;
6
+ const mathType = schema.nodes.math;
7
+ const codeBlockType = schema.nodes.code_block;
8
+ if (!mathType || !codeBlockType) {
9
+ return false;
10
+ }
11
+ let modified = false;
12
+ const tr = state.tr;
13
+ doc.forEach((parentNode, offset, index) => {
14
+ if (parentNode.childCount !== 1) {
15
+ return;
16
+ }
17
+ const parentPos = offset;
18
+ const node = parentNode.child(0);
19
+ if (node.type !== mathType)
20
+ return;
21
+ if (node.attrs.content.length === 0)
22
+ return;
23
+ const codeBlock = codeBlockType.create({
24
+ lang: node.attrs.lang,
25
+ }, schema.text(node.attrs.content));
26
+ tr.replaceWith(tr.mapping.map(parentPos), tr.mapping.map(parentPos + parentNode.nodeSize), codeBlock);
27
+ modified = true;
28
+ });
29
+ if (!modified)
30
+ return false;
31
+ if (dispatch) {
32
+ dispatch(tr);
33
+ }
34
+ return true;
35
+ };
@@ -1,3 +1,8 @@
1
+ import type { Node } from 'prosemirror-model';
1
2
  import { Command } from 'prosemirror-state';
2
- export declare function getDefaultsPostProcessFilters(): Array<Command>;
3
+ export interface PostProcessConfig {
4
+ doc: Node;
5
+ filesMap: Record<string, Uint8Array>;
6
+ }
7
+ export declare function getDefaultsPostProcessFilters({ doc, filesMap }: PostProcessConfig): Array<Command>;
3
8
  //# sourceMappingURL=postProcess.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"postProcess.d.ts","sourceRoot":"","sources":["../../src/postprocess/postProcess.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAM5C,wBAAgB,6BAA6B,IAAI,KAAK,CAAC,OAAO,CAAC,CAM9D"}
1
+ {"version":3,"file":"postProcess.d.ts","sourceRoot":"","sources":["../../src/postprocess/postProcess.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AAC9C,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAO5C,MAAM,WAAW,iBAAiB;IAChC,GAAG,EAAE,IAAI,CAAC;IACV,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;CACtC;AAED,wBAAgB,6BAA6B,CAC3C,EAAE,GAAG,EAAE,QAAQ,EAAE,EAAE,iBAAiB,GACnC,KAAK,CAAC,OAAO,CAAC,CAOhB"}
@@ -1,10 +1,12 @@
1
1
  import { convertCodeParagraphsToCodeBlocks } from './convertCodeParagraphsToCodeBlocks.js';
2
2
  import { removeUnusedBookmarks } from './removeUnusedBookmarks.js';
3
3
  import { fixContinuedLists } from './fixContinuedLists.js';
4
- export function getDefaultsPostProcessFilters() {
4
+ import { convertMathMl } from './convertMathMl.js';
5
+ export function getDefaultsPostProcessFilters({ doc, filesMap }) {
5
6
  return [
6
7
  convertCodeParagraphsToCodeBlocks,
7
8
  removeUnusedBookmarks,
8
9
  fixContinuedLists,
10
+ convertMathMl,
9
11
  ];
10
12
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kerebron/extension-odt",
3
- "version": "0.4.20",
3
+ "version": "0.4.22",
4
4
  "license": "MIT",
5
5
  "module": "./esm/ExtensionOdt.js",
6
6
  "exports": {
@@ -10,8 +10,8 @@
10
10
  },
11
11
  "scripts": {},
12
12
  "dependencies": {
13
- "@kerebron/editor": "0.4.20",
14
- "@kerebron/odt-wasm": "0.4.20",
13
+ "@kerebron/editor": "0.4.22",
14
+ "@kerebron/odt-wasm": "0.4.22",
15
15
  "prosemirror-model": "1.25.3",
16
16
  "prosemirror-state": "1.4.3"
17
17
  },