@kerebron/extension-odt 0.5.3 → 0.5.4
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.
- package/esm/ExtensionOdt.d.ts.map +1 -1
- package/esm/ExtensionOdt.js +12 -7
- package/esm/ExtensionOdt.js.map +1 -1
- package/esm/OdtParser.d.ts +36 -2
- package/esm/OdtParser.d.ts.map +1 -1
- package/esm/OdtParser.js +20 -20
- package/esm/OdtParser.js.map +1 -1
- package/esm/node_handlers/basic_node_handlers.d.ts +1 -0
- package/esm/node_handlers/basic_node_handlers.d.ts.map +1 -1
- package/esm/node_handlers/basic_node_handlers.js +76 -6
- package/esm/node_handlers/basic_node_handlers.js.map +1 -1
- package/esm/node_handlers/list_node_handlers.d.ts.map +1 -1
- package/esm/node_handlers/list_node_handlers.js +21 -11
- package/esm/node_handlers/list_node_handlers.js.map +1 -1
- package/esm/postprocess/convertCodeParagraphsToCodeBlocks.d.ts.map +1 -1
- package/esm/postprocess/convertCodeParagraphsToCodeBlocks.js +19 -8
- package/esm/postprocess/convertCodeParagraphsToCodeBlocks.js.map +1 -1
- package/esm/postprocess/convertMathMl.js +1 -1
- package/esm/postprocess/convertMathMl.js.map +1 -1
- package/esm/postprocess/fixListsLevels.d.ts +3 -0
- package/esm/postprocess/fixListsLevels.d.ts.map +1 -0
- package/esm/postprocess/fixListsLevels.js +62 -0
- package/esm/postprocess/fixListsLevels.js.map +1 -0
- package/esm/postprocess/mergeCodeBlocks.d.ts.map +1 -1
- package/esm/postprocess/mergeCodeBlocks.js +15 -4
- package/esm/postprocess/mergeCodeBlocks.js.map +1 -1
- package/esm/postprocess/postProcess.d.ts.map +1 -1
- package/esm/postprocess/postProcess.js +3 -2
- package/esm/postprocess/postProcess.js.map +1 -1
- package/esm/postprocess/removeUnusedBookmarks.d.ts.map +1 -1
- package/esm/postprocess/removeUnusedBookmarks.js +0 -1
- package/esm/postprocess/removeUnusedBookmarks.js.map +1 -1
- package/package.json +3 -3
- package/src/ExtensionOdt.ts +13 -12
- package/src/OdtParser.ts +74 -26
- package/src/node_handlers/basic_node_handlers.ts +80 -6
- package/src/node_handlers/list_node_handlers.ts +42 -18
- package/src/postprocess/convertCodeParagraphsToCodeBlocks.ts +21 -8
- package/src/postprocess/convertMathMl.ts +1 -1
- package/src/postprocess/fixListsLevels.ts +93 -0
- package/src/postprocess/mergeCodeBlocks.ts +20 -4
- package/src/postprocess/postProcess.ts +3 -1
- package/src/postprocess/removeUnusedBookmarks.ts +0 -1
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { Fragment } from 'prosemirror-model';
|
|
2
|
+
const ANY_LIST = ['ordered_list', 'bullet_list'];
|
|
3
|
+
// Related tests:
|
|
4
|
+
// test ./example-document.md
|
|
5
|
+
export const fixListsLevels = (state, dispatch) => {
|
|
6
|
+
const doc = state.doc;
|
|
7
|
+
const schema = state.schema;
|
|
8
|
+
const bulletListType = schema.nodes.bullet_list;
|
|
9
|
+
const listItemType = schema.nodes.list_item;
|
|
10
|
+
const paragraphType = schema.nodes.paragraph;
|
|
11
|
+
const tr = state.tr;
|
|
12
|
+
let level = 0;
|
|
13
|
+
let prevList = [];
|
|
14
|
+
let curList = [];
|
|
15
|
+
let fakeLevelGenerated = 0;
|
|
16
|
+
function walk(node, pos = 0, depth = 0) {
|
|
17
|
+
if (!ANY_LIST.includes(node.type.name)) {
|
|
18
|
+
node.forEach((child, offset) => {
|
|
19
|
+
walk(child, pos + offset + 1, depth + 1);
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
const marginLeft = node.attrs['odtMarginLeft'] || 0;
|
|
24
|
+
if (level === 0) {
|
|
25
|
+
curList = [];
|
|
26
|
+
fakeLevelGenerated = 0;
|
|
27
|
+
if (prevList.length >= level) {
|
|
28
|
+
for (let i = 0; i < prevList.length; i++) {
|
|
29
|
+
if (fakeLevelGenerated < prevList.length &&
|
|
30
|
+
marginLeft > prevList[fakeLevelGenerated]) {
|
|
31
|
+
curList[level + fakeLevelGenerated] =
|
|
32
|
+
prevList[fakeLevelGenerated];
|
|
33
|
+
fakeLevelGenerated++;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
curList[level + fakeLevelGenerated] = marginLeft;
|
|
39
|
+
level++;
|
|
40
|
+
node.forEach((child, offset) => {
|
|
41
|
+
walk(child, pos + offset + 1, depth + 1);
|
|
42
|
+
});
|
|
43
|
+
level--;
|
|
44
|
+
if (level === 0 && !node.attrs.toc) {
|
|
45
|
+
prevList = curList;
|
|
46
|
+
for (let i = 0; i < fakeLevelGenerated; i++) {
|
|
47
|
+
const wrapper = bulletListType.create({ type: 'none' }, listItemType.create(null, Fragment.from([
|
|
48
|
+
paragraphType.create(),
|
|
49
|
+
node,
|
|
50
|
+
])));
|
|
51
|
+
tr.replaceWith(tr.mapping.map(pos), tr.mapping.map(pos + node.nodeSize), wrapper);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
walk(doc);
|
|
57
|
+
if (dispatch) {
|
|
58
|
+
dispatch(tr);
|
|
59
|
+
}
|
|
60
|
+
return tr.docChanged;
|
|
61
|
+
};
|
|
62
|
+
//# sourceMappingURL=fixListsLevels.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fixListsLevels.js","sourceRoot":"","sources":["../../src/postprocess/fixListsLevels.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAQ,MAAM,mBAAmB,CAAC;AAGnD,MAAM,QAAQ,GAAG,CAAC,cAAc,EAAE,aAAa,CAAC,CAAC;AAIjD,iBAAiB;AACjB,6BAA6B;AAC7B,MAAM,CAAC,MAAM,cAAc,GAAY,CAAC,KAAK,EAAE,QAAQ,EAAW,EAAE;IAClE,MAAM,GAAG,GAAS,KAAK,CAAC,GAAG,CAAC;IAC5B,MAAM,MAAM,GAAG,KAAK,CAAC,MAAM,C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AE,CAAC,UAAU,CAAC;AACvB,CAAC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mergeCodeBlocks.d.ts","sourceRoot":"","sources":["../../src/postprocess/mergeCodeBlocks.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAO5C,eAAO,MAAM,eAAe,EAAE,
|
|
1
|
+
{"version":3,"file":"mergeCodeBlocks.d.ts","sourceRoot":"","sources":["../../src/postprocess/mergeCodeBlocks.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAO5C,eAAO,MAAM,eAAe,EAAE,OA0G7B,CAAC"}
|
|
@@ -31,14 +31,14 @@ export const mergeCodeBlocks = (state, dispatch) => {
|
|
|
31
31
|
if (!next) {
|
|
32
32
|
break;
|
|
33
33
|
}
|
|
34
|
-
const currentPos = nextPos;
|
|
35
34
|
nextPos += next.nodeSize;
|
|
36
35
|
if (next.type === paraBlockType && next.childCount === 0) {
|
|
37
36
|
codeTexts.push('\n');
|
|
38
37
|
codeSize += next.nodeSize;
|
|
39
38
|
continue;
|
|
40
39
|
}
|
|
41
|
-
if (next.type === codeBlockType && node.attrs.lang === next.attrs.lang
|
|
40
|
+
if (next.type === codeBlockType && node.attrs.lang === next.attrs.lang &&
|
|
41
|
+
node.attrs.lang !== 'mathml') {
|
|
42
42
|
const text = next.text || next.textBetween(0, next.content.size);
|
|
43
43
|
codeTexts.push(text.endsWith('\n') ? text : text + '\n');
|
|
44
44
|
codeSize += next.nodeSize;
|
|
@@ -49,9 +49,20 @@ export const mergeCodeBlocks = (state, dispatch) => {
|
|
|
49
49
|
if (codeTexts.length > 1) {
|
|
50
50
|
const startPos = tr.mapping.map(offset);
|
|
51
51
|
const endPos = tr.mapping.map(offset + codeSize);
|
|
52
|
-
|
|
52
|
+
let codeText = codeTexts.join('').replace(/\n+$/gm, '\n');
|
|
53
|
+
const lines = codeText.split('\n');
|
|
54
|
+
let emptyCount = 0;
|
|
55
|
+
for (emptyCount = 0; emptyCount < lines.length; emptyCount++) {
|
|
56
|
+
if (lines[emptyCount].trim()) {
|
|
57
|
+
break;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
lines.splice(0, emptyCount);
|
|
61
|
+
codeText = lines.join('\n');
|
|
53
62
|
const textNode = schema.text(codeText);
|
|
54
|
-
const codeBlock = schema.nodes.code_block.createAndFill(
|
|
63
|
+
const codeBlock = schema.nodes.code_block.createAndFill({
|
|
64
|
+
lang: node.attrs.lang,
|
|
65
|
+
}, [textNode]);
|
|
55
66
|
if (codeBlock) {
|
|
56
67
|
tr = tr.replaceRangeWith(startPos, endPos, codeBlock);
|
|
57
68
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mergeCodeBlocks.js","sourceRoot":"","sources":["../../src/postprocess/mergeCodeBlocks.ts"],"names":[],"mappings":"AAEA,MAAM,eAAe,GAAG,GAAG,CAAC,CAAC,QAAQ;AACrC,MAAM,aAAa,GAAG,GAAG,CAAC;AAE1B,iBAAiB;AACjB,wBAAwB;AACxB,MAAM,CAAC,MAAM,eAAe,GAAY,CAAC,KAAK,EAAE,QAAQ,EAAW,EAAE;IACnE,MAAM,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC;IAC5B,IAAI,EAAE,GAAG,KAAK,CAAC,EAAE,CAAC;IAElB,MAAM,aAAa,GAAG,MAAM,CAAC,KAAK,CAAC,UAAU,CAAC;IAC9C,MAAM,aAAa,GAAG,MAAM,CAAC,KAAK,CAAC,SAAS,CAAC;IAE7C,MAAM,MAAM,GAAG,KAAK,CAAC,GAAG,CAAC;IACzB,IAAI,MAAM,GAAG,CAAC,CAAC;IACf,KAAK,IAAI,MAAM,GAAG,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,EAAE,CAAC;QAC1D,MAAM,IAAI,GAAG,MAAM,CAAC,MAAM,CAAC,MAAM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AC;IAED,OAAO,EAAE,CAAC,UAAU,CAAC;AACvB,CAAC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
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;
|
|
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;AAS5C,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,CAShB"}
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { convertCodeParagraphsToCodeBlocks } from './convertCodeParagraphsToCodeBlocks.js';
|
|
2
|
-
import { removeUnusedBookmarks } from './removeUnusedBookmarks.js';
|
|
3
2
|
import { fixContinuedLists } from './fixContinuedLists.js';
|
|
4
3
|
import { convertMathMl } from './convertMathMl.js';
|
|
5
4
|
import { mergeCodeBlocks } from './mergeCodeBlocks.js';
|
|
5
|
+
import { fixListsLevels } from './fixListsLevels.js';
|
|
6
6
|
export function getDefaultsPostProcessFilters({ doc, filesMap }) {
|
|
7
7
|
return [
|
|
8
|
-
removeUnusedBookmarks,
|
|
8
|
+
// removeUnusedBookmarks,
|
|
9
9
|
convertCodeParagraphsToCodeBlocks,
|
|
10
|
+
fixListsLevels,
|
|
10
11
|
fixContinuedLists,
|
|
11
12
|
convertMathMl,
|
|
12
13
|
mergeCodeBlocks,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"postProcess.js","sourceRoot":"","sources":["../../src/postprocess/postProcess.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,iCAAiC,EAAE,MAAM,wCAAwC,CAAC;
|
|
1
|
+
{"version":3,"file":"postProcess.js","sourceRoot":"","sources":["../../src/postprocess/postProcess.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,iCAAiC,EAAE,MAAM,wCAAwC,CAAC;AAE3F,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAOrD,MAAM,UAAU,6BAA6B,CAC3C,EAAE,GAAG,EAAE,QAAQ,EAAqB;IAEpC,OAAO;QACL,yBAAyB;QACzB,iCAAiC;QACjC,cAAc;QACd,iBAAiB;QACjB,aAAa;QACb,eAAe;KAChB,CAAC;AACJ,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"removeUnusedBookmarks.d.ts","sourceRoot":"","sources":["../../src/postprocess/removeUnusedBookmarks.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAEjD,eAAO,MAAM,qBAAqB,EAAE,
|
|
1
|
+
{"version":3,"file":"removeUnusedBookmarks.d.ts","sourceRoot":"","sources":["../../src/postprocess/removeUnusedBookmarks.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAEjD,eAAO,MAAM,qBAAqB,EAAE,OA4CnC,CAAC"}
|
|
@@ -5,7 +5,6 @@ export const removeUnusedBookmarks = (state, dispatch) => {
|
|
|
5
5
|
const bookmarkMarkType = schema.marks.bookmark;
|
|
6
6
|
function walk(node, pos = 0, depth = 0) {
|
|
7
7
|
if (node.type === bookmarkNodeType) {
|
|
8
|
-
console.log('del');
|
|
9
8
|
tr = tr.delete(tr.mapping.map(pos - 1), tr.mapping.map(pos + node.nodeSize - 1));
|
|
10
9
|
return;
|
|
11
10
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"removeUnusedBookmarks.js","sourceRoot":"","sources":["../../src/postprocess/removeUnusedBookmarks.ts"],"names":[],"mappings":"AAGA,MAAM,CAAC,MAAM,qBAAqB,GAAY,CAAC,KAAK,EAAE,QAAQ,EAAW,EAAE;IACzE,MAAM,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC;IAC5B,IAAI,EAAE,GAAG,KAAK,CAAC,EAAE,CAAC;IAElB,MAAM,gBAAgB,GAAG,MAAM,CAAC,KAAK,CAAC,aAAa,CAAC;IACpD,MAAM,gBAAgB,GAAG,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC;IAE/C,SAAS,IAAI,CACX,IAAU,EACV,GAAG,GAAG,CAAC,EACP,KAAK,GAAG,CAAC;QAET,IAAI,IAAI,CAAC,IAAI,KAAK,gBAAgB,EAAE,CAAC;YACnC,
|
|
1
|
+
{"version":3,"file":"removeUnusedBookmarks.js","sourceRoot":"","sources":["../../src/postprocess/removeUnusedBookmarks.ts"],"names":[],"mappings":"AAGA,MAAM,CAAC,MAAM,qBAAqB,GAAY,CAAC,KAAK,EAAE,QAAQ,EAAW,EAAE;IACzE,MAAM,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC;IAC5B,IAAI,EAAE,GAAG,KAAK,CAAC,EAAE,CAAC;IAElB,MAAM,gBAAgB,GAAG,MAAM,CAAC,KAAK,CAAC,aAAa,CAAC;IACpD,MAAM,gBAAgB,GAAG,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC;IAE/C,SAAS,IAAI,CACX,IAAU,EACV,GAAG,GAAG,CAAC,EACP,KAAK,GAAG,CAAC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.js",
|
|
6
6
|
"exports": {
|
|
@@ -14,8 +14,8 @@
|
|
|
14
14
|
"src"
|
|
15
15
|
],
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@kerebron/editor": "0.5.
|
|
18
|
-
"@kerebron/odt-wasm": "0.5.
|
|
17
|
+
"@kerebron/editor": "0.5.4",
|
|
18
|
+
"@kerebron/odt-wasm": "0.5.4",
|
|
19
19
|
"prosemirror-model": "1.25.3",
|
|
20
20
|
"prosemirror-state": "1.4.3"
|
|
21
21
|
},
|
package/src/ExtensionOdt.ts
CHANGED
|
@@ -6,12 +6,6 @@ import {
|
|
|
6
6
|
Extension,
|
|
7
7
|
type UrlRewriter,
|
|
8
8
|
} from '@kerebron/editor';
|
|
9
|
-
import {
|
|
10
|
-
init_debug,
|
|
11
|
-
parse_content,
|
|
12
|
-
parse_styles,
|
|
13
|
-
unzip,
|
|
14
|
-
} from '@kerebron/odt-wasm';
|
|
15
9
|
|
|
16
10
|
import { OdtParser, OdtParserConfig } from './OdtParser.js';
|
|
17
11
|
import { getDefaultsPostProcessFilters } from './postprocess/postProcess.js';
|
|
@@ -24,7 +18,7 @@ export interface OdtConfig extends OdtParserConfig {
|
|
|
24
18
|
postProcessCommands?: Command[];
|
|
25
19
|
}
|
|
26
20
|
|
|
27
|
-
|
|
21
|
+
let odtWasm: Record<string, any> | undefined = undefined;
|
|
28
22
|
|
|
29
23
|
export class ExtensionOdt extends Extension {
|
|
30
24
|
name = 'odt';
|
|
@@ -43,7 +37,14 @@ export class ExtensionOdt extends Extension {
|
|
|
43
37
|
throw new Error('Not implemented');
|
|
44
38
|
},
|
|
45
39
|
toDoc: async (buffer: Uint8Array): Promise<Node> => {
|
|
46
|
-
|
|
40
|
+
if (!odtWasm) {
|
|
41
|
+
odtWasm = this.config.debug
|
|
42
|
+
? await import('@kerebron/odt-wasm/debug')
|
|
43
|
+
: await import('@kerebron/odt-wasm');
|
|
44
|
+
odtWasm = await odtWasm.init();
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const { doc, filesMap } = odtConverter.odtToJson(buffer, odtWasm);
|
|
47
48
|
|
|
48
49
|
const filterCommands = getDefaultsPostProcessFilters({
|
|
49
50
|
doc,
|
|
@@ -81,15 +82,15 @@ export class ExtensionOdt extends Extension {
|
|
|
81
82
|
|
|
82
83
|
return state.doc;
|
|
83
84
|
},
|
|
84
|
-
odtToJson: (buffer: Uint8Array) => {
|
|
85
|
-
const files = unzip(buffer);
|
|
85
|
+
odtToJson: (buffer: Uint8Array, odtWasm: any) => {
|
|
86
|
+
const files = odtWasm.unzip(buffer);
|
|
86
87
|
const filesMap: Record<string, Uint8Array> = {};
|
|
87
88
|
for (const k of files.keys()) {
|
|
88
89
|
filesMap[k] = Uint8Array.from(files.get(k));
|
|
89
90
|
}
|
|
90
91
|
|
|
91
|
-
const stylesTree = parse_styles(files.get('styles.xml'));
|
|
92
|
-
const contentTree = parse_content(files.get('content.xml'));
|
|
92
|
+
const stylesTree = odtWasm.parse_styles(files.get('styles.xml'));
|
|
93
|
+
const contentTree = odtWasm.parse_content(files.get('content.xml'));
|
|
93
94
|
|
|
94
95
|
if (this.config.debug) {
|
|
95
96
|
const event = new CustomEvent('odt:parsed', {
|
package/src/OdtParser.ts
CHANGED
|
@@ -15,14 +15,53 @@ export interface OdtElement {
|
|
|
15
15
|
|
|
16
16
|
export type NodeHandler = (ctx: OdtStashContext, value: any) => void;
|
|
17
17
|
|
|
18
|
+
export interface ListLLevelLabelAlignment {
|
|
19
|
+
'@margin-left'?: string;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface ListLevelProperties {
|
|
23
|
+
'list-level-label-alignment': ListLLevelLabelAlignment;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface ListLevelStyleBullet {
|
|
27
|
+
'@level': number;
|
|
28
|
+
'list-level-properties': ListLevelProperties;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface ListLevelStyleNumber {
|
|
32
|
+
'@level': number;
|
|
33
|
+
'@start-value'?: number;
|
|
34
|
+
'@num-format': string;
|
|
35
|
+
'list-level-properties': ListLevelProperties;
|
|
36
|
+
}
|
|
37
|
+
|
|
18
38
|
export interface ListStyle {
|
|
19
|
-
'@name'
|
|
39
|
+
'@name'?: string;
|
|
40
|
+
'list-level-style-bullet': ListLevelStyleBullet[];
|
|
41
|
+
'list-level-style-number': ListLevelStyleNumber[];
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export interface TextProperty {
|
|
45
|
+
'@font-name'?: string;
|
|
46
|
+
'@font-weight'?: string;
|
|
47
|
+
'@font-style'?: string;
|
|
48
|
+
'@font-size'?: string;
|
|
49
|
+
'@text-underline-style'?: string;
|
|
50
|
+
'@color'?: string;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export interface ParagraphProperty {
|
|
54
|
+
'@break-before'?: string;
|
|
55
|
+
'@break-after'?: string;
|
|
56
|
+
'@margin-left'?: string;
|
|
20
57
|
}
|
|
21
58
|
|
|
22
59
|
export interface Style {
|
|
23
|
-
'@name'
|
|
60
|
+
'@name'?: string;
|
|
24
61
|
'@parent-style-name'?: string;
|
|
25
62
|
styles: string[];
|
|
63
|
+
'text-properties'?: TextProperty;
|
|
64
|
+
'paragraph-properties'?: TextProperty;
|
|
26
65
|
}
|
|
27
66
|
|
|
28
67
|
export interface StylesTree {
|
|
@@ -36,6 +75,28 @@ export interface AutomaticStyles {
|
|
|
36
75
|
'style': Array<Style>;
|
|
37
76
|
}
|
|
38
77
|
|
|
78
|
+
export function resolveListStyle(
|
|
79
|
+
stylesTree: StylesTree,
|
|
80
|
+
automaticStyles: AutomaticStyles,
|
|
81
|
+
name: string,
|
|
82
|
+
): ListStyle {
|
|
83
|
+
let style: ListStyle | undefined;
|
|
84
|
+
|
|
85
|
+
style = stylesTree.styles['list-style'].find((item) =>
|
|
86
|
+
item['@name'] === name
|
|
87
|
+
);
|
|
88
|
+
|
|
89
|
+
if (!style) {
|
|
90
|
+
style = {
|
|
91
|
+
'@name': name,
|
|
92
|
+
'list-level-style-number': [],
|
|
93
|
+
'list-level-style-bullet': [],
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
return style;
|
|
98
|
+
}
|
|
99
|
+
|
|
39
100
|
export function resolveStyle(
|
|
40
101
|
stylesTree: StylesTree,
|
|
41
102
|
automaticStyles: AutomaticStyles,
|
|
@@ -43,11 +104,6 @@ export function resolveStyle(
|
|
|
43
104
|
): Style {
|
|
44
105
|
let style: Style | undefined;
|
|
45
106
|
|
|
46
|
-
if (!style) {
|
|
47
|
-
style = stylesTree.styles['list-style'].find((item) =>
|
|
48
|
-
item['@name'] === name
|
|
49
|
-
);
|
|
50
|
-
}
|
|
51
107
|
if (!style) {
|
|
52
108
|
style = stylesTree.styles['style'].find((item) => item['@name'] === name);
|
|
53
109
|
}
|
|
@@ -72,7 +128,7 @@ export function resolveStyle(
|
|
|
72
128
|
);
|
|
73
129
|
if (parentStyle) {
|
|
74
130
|
const styles = [...style['styles'], ...parentStyle['styles']];
|
|
75
|
-
for (const key
|
|
131
|
+
for (const key of Object.keys(style) as (keyof Style)[]) {
|
|
76
132
|
if (typeof style[key] === 'undefined') {
|
|
77
133
|
delete style[key];
|
|
78
134
|
}
|
|
@@ -268,7 +324,9 @@ export class OdtStashContext {
|
|
|
268
324
|
this.automaticStyles,
|
|
269
325
|
element['@style-name'],
|
|
270
326
|
)
|
|
271
|
-
: {
|
|
327
|
+
: {
|
|
328
|
+
styles: [],
|
|
329
|
+
};
|
|
272
330
|
|
|
273
331
|
return style;
|
|
274
332
|
}
|
|
@@ -295,24 +353,14 @@ export class OdtParser {
|
|
|
295
353
|
...getBasicNodesHandlers(),
|
|
296
354
|
...getListNodesHandlers(),
|
|
297
355
|
...getTableNodesHandlers(),
|
|
298
|
-
|
|
299
|
-
'change-start': () => {
|
|
300
|
-
// custom(state) {
|
|
301
|
-
// state.textMarks.add({
|
|
302
|
-
// markName: 'change',
|
|
303
|
-
// markAttributes: {},
|
|
304
|
-
// });
|
|
305
|
-
// },
|
|
306
|
-
},
|
|
307
|
-
'change-end': () => {
|
|
308
|
-
// custom(state) {
|
|
309
|
-
// state.textMarks.forEach((x) =>
|
|
310
|
-
// x.markName === 'change' ? state.textMarks.delete(x) : x
|
|
311
|
-
// );
|
|
312
|
-
// },
|
|
313
|
-
},
|
|
314
356
|
'g': () => { // Test is: embedded-diagram-example.odt
|
|
315
357
|
// DrawG draw:g
|
|
358
|
+
const node = ctx.createText(
|
|
359
|
+
'INSTEAD OF EMBEDDED DIAGRAM ABOVE USE EMBEDDED DIAGRAM FROM DRIVE AND PUT LINK TO IT IN THE DESCRIPTION. See: https://github.com/mieweb/wikiGDrive/issues/353',
|
|
360
|
+
);
|
|
361
|
+
if (node) {
|
|
362
|
+
ctx.current.content.push(node);
|
|
363
|
+
}
|
|
316
364
|
},
|
|
317
365
|
'frame': (ctx: OdtStashContext, odtElement: any) => {
|
|
318
366
|
if (odtElement.object && odtElement.object['@href']) {
|
|
@@ -329,7 +377,7 @@ export class OdtParser {
|
|
|
329
377
|
}
|
|
330
378
|
}
|
|
331
379
|
if (odtElement.image && odtElement.image['@href']) { // TODO links rewrite
|
|
332
|
-
const alt = odtElement.
|
|
380
|
+
const alt = odtElement.desc?.['$value'] || '';
|
|
333
381
|
const src = odtElement.image['@href'];
|
|
334
382
|
ctx.openNode();
|
|
335
383
|
ctx.closeNode('image', {
|
|
@@ -1,5 +1,22 @@
|
|
|
1
|
+
import { NESTING_CLOSING, NESTING_OPENING } from '@kerebron/editor';
|
|
1
2
|
import { iterateChildren, NodeHandler, OdtStashContext } from '../OdtParser.js';
|
|
2
3
|
|
|
4
|
+
export function inchesToMm(value: string): number {
|
|
5
|
+
if (!value) {
|
|
6
|
+
return 0;
|
|
7
|
+
}
|
|
8
|
+
if (value.endsWith('pt')) {
|
|
9
|
+
return parseFloat(value.substring(0, value.length - 2)) * 0.3528;
|
|
10
|
+
}
|
|
11
|
+
if (value.endsWith('in')) {
|
|
12
|
+
return parseFloat(value.substring(0, value.length - 2)) * 25.4;
|
|
13
|
+
}
|
|
14
|
+
if (value.endsWith('em')) {
|
|
15
|
+
return parseFloat(value.substring(0, value.length - 2)) / 0.125 * 25.4;
|
|
16
|
+
}
|
|
17
|
+
return 0;
|
|
18
|
+
}
|
|
19
|
+
|
|
3
20
|
export function getInlineNodesHandlers(): Record<string, NodeHandler> {
|
|
4
21
|
return {
|
|
5
22
|
'$text': (ctx: OdtStashContext, value: any) => {
|
|
@@ -23,10 +40,10 @@ export function getInlineNodesHandlers(): Record<string, NodeHandler> {
|
|
|
23
40
|
}
|
|
24
41
|
},
|
|
25
42
|
'rect': (ctx: OdtStashContext, odtElement: any) => {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
43
|
+
if (odtElement['@rel-width'] === '100%') {
|
|
44
|
+
ctx.openNode();
|
|
45
|
+
ctx.closeNode('hr');
|
|
46
|
+
}
|
|
30
47
|
},
|
|
31
48
|
'line-break': (ctx: OdtStashContext, odtElement: any) => {
|
|
32
49
|
ctx.openNode();
|
|
@@ -57,6 +74,20 @@ export function getInlineNodesHandlers(): Record<string, NodeHandler> {
|
|
|
57
74
|
// : x
|
|
58
75
|
// );
|
|
59
76
|
},
|
|
77
|
+
'change-start': (ctx: OdtStashContext, element: any) => {
|
|
78
|
+
ctx.openNode();
|
|
79
|
+
ctx.closeNode('comment', {
|
|
80
|
+
id: element['@change-id'],
|
|
81
|
+
nesting: NESTING_OPENING,
|
|
82
|
+
});
|
|
83
|
+
},
|
|
84
|
+
'change-end': (ctx: OdtStashContext, element: any) => {
|
|
85
|
+
ctx.openNode();
|
|
86
|
+
ctx.closeNode('comment', {
|
|
87
|
+
id: element['@change-id'],
|
|
88
|
+
nesting: NESTING_CLOSING,
|
|
89
|
+
});
|
|
90
|
+
},
|
|
60
91
|
};
|
|
61
92
|
}
|
|
62
93
|
|
|
@@ -101,13 +132,56 @@ export function getBasicNodesHandlers(): Record<string, NodeHandler> {
|
|
|
101
132
|
},
|
|
102
133
|
|
|
103
134
|
'table-of-content': (ctx: OdtStashContext, value: any) => {
|
|
104
|
-
|
|
135
|
+
const levels: number[] = [];
|
|
136
|
+
|
|
137
|
+
let prevMarginLeft = -1;
|
|
105
138
|
for (const pElem of value['index-body']['p']) {
|
|
139
|
+
const style = ctx.getElementStyle(pElem) as any;
|
|
140
|
+
let marginLeft = 0;
|
|
141
|
+
if ('paragraph-properties' in style) {
|
|
142
|
+
marginLeft = inchesToMm(
|
|
143
|
+
style['paragraph-properties']['@margin-left'],
|
|
144
|
+
);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
if (prevMarginLeft < marginLeft) {
|
|
148
|
+
if (levels.length > 0) {
|
|
149
|
+
ctx.openNode(); // list_item
|
|
150
|
+
}
|
|
151
|
+
ctx.openNode(); // bullet_list
|
|
152
|
+
levels.push(marginLeft);
|
|
153
|
+
} else {
|
|
154
|
+
for (let i = levels.length - 1; i >= 0; i--) {
|
|
155
|
+
if (levels[i] > marginLeft) {
|
|
156
|
+
ctx.closeNode('bullet_list', { odtMarginLeft: marginLeft });
|
|
157
|
+
if (i > 0) {
|
|
158
|
+
ctx.closeNode('list_item');
|
|
159
|
+
}
|
|
160
|
+
levels.pop();
|
|
161
|
+
} else {
|
|
162
|
+
break;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
106
166
|
ctx.openNode();
|
|
107
167
|
ctx.handle('p', pElem);
|
|
108
168
|
ctx.closeNode('list_item');
|
|
169
|
+
|
|
170
|
+
prevMarginLeft = marginLeft;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
for (let i = levels.length - 1; i >= 0; i--) {
|
|
174
|
+
const marginLeft = levels.pop();
|
|
175
|
+
if (i > 0) {
|
|
176
|
+
ctx.closeNode('bullet_list', { odtMarginLeft: marginLeft });
|
|
177
|
+
ctx.closeNode('list_item');
|
|
178
|
+
} else {
|
|
179
|
+
ctx.closeNode('bullet_list', {
|
|
180
|
+
odtMarginLeft: marginLeft,
|
|
181
|
+
toc: true,
|
|
182
|
+
});
|
|
183
|
+
}
|
|
109
184
|
}
|
|
110
|
-
ctx.closeNode('bullet_list');
|
|
111
185
|
},
|
|
112
186
|
|
|
113
187
|
'span': (ctx: OdtStashContext, value: any) => {
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import {
|
|
2
2
|
iterateChildren,
|
|
3
|
+
ListStyle,
|
|
3
4
|
NodeHandler,
|
|
4
5
|
OdtStashContext,
|
|
5
|
-
|
|
6
|
+
resolveListStyle,
|
|
6
7
|
} from '../OdtParser.js';
|
|
8
|
+
import { inchesToMm } from './basic_node_handlers.js';
|
|
7
9
|
|
|
8
10
|
// https://docs.oasis-open.org/office/OpenDocument/v1.4/OpenDocument-v1.4-part3-schema.html#a_19_880_22__text_list_
|
|
9
11
|
// The text:style-name attribute specifies the name of a list style that is applied to a list.
|
|
@@ -14,33 +16,55 @@ import {
|
|
|
14
16
|
// To determine which formatting properties are applied to a list, the list level and list style name are taken into account.
|
|
15
17
|
function processListStyle(ctx: OdtStashContext, level: number) {
|
|
16
18
|
const listTracker = ctx.listTracker;
|
|
17
|
-
const attrs: Record<string, string> = {};
|
|
19
|
+
const attrs: Record<string, string | number> = {};
|
|
20
|
+
|
|
21
|
+
let style: ListStyle = resolveListStyle(
|
|
22
|
+
ctx.stylesTree,
|
|
23
|
+
ctx.automaticStyles,
|
|
24
|
+
'',
|
|
25
|
+
);
|
|
18
26
|
|
|
19
|
-
let style = {};
|
|
20
27
|
for (let i = listTracker.listStack.length - 1; i >= 0; i--) {
|
|
21
28
|
const list = listTracker.listStack[i];
|
|
22
|
-
if (!style['@
|
|
23
|
-
style = (
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
)
|
|
29
|
-
: {};
|
|
29
|
+
if (!style['@name']) {
|
|
30
|
+
style = resolveListStyle(
|
|
31
|
+
ctx.stylesTree,
|
|
32
|
+
ctx.automaticStyles,
|
|
33
|
+
list.styleName,
|
|
34
|
+
);
|
|
30
35
|
}
|
|
31
36
|
}
|
|
32
37
|
|
|
33
38
|
let nodeTypeName = 'bullet_list';
|
|
34
39
|
if (style) {
|
|
35
40
|
const numLevelStyle = style['list-level-style-number'].find(
|
|
36
|
-
(levelStyle) => parseInt(levelStyle['@level']) === level,
|
|
41
|
+
(levelStyle) => parseInt(String(levelStyle['@level'])) === level,
|
|
37
42
|
);
|
|
38
43
|
if (numLevelStyle) {
|
|
39
44
|
attrs['type'] = numLevelStyle['@num-format'] || '1';
|
|
40
45
|
if (numLevelStyle['@start-value']) {
|
|
41
|
-
attrs['start'] = numLevelStyle['@start-value'];
|
|
46
|
+
attrs['start'] = String(numLevelStyle['@start-value']);
|
|
42
47
|
}
|
|
43
48
|
nodeTypeName = 'ordered_list';
|
|
49
|
+
const marginLeft =
|
|
50
|
+
numLevelStyle['list-level-properties']['list-level-label-alignment'][
|
|
51
|
+
'@margin-left'
|
|
52
|
+
];
|
|
53
|
+
if (marginLeft) {
|
|
54
|
+
attrs['odtMarginLeft'] = inchesToMm(marginLeft);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
const bulletLevelStyle = style['list-level-style-bullet'].find(
|
|
58
|
+
(levelStyle) => parseInt(String(levelStyle['@level'])) === level,
|
|
59
|
+
);
|
|
60
|
+
if (bulletLevelStyle) {
|
|
61
|
+
const marginLeft =
|
|
62
|
+
bulletLevelStyle['list-level-properties']['list-level-label-alignment'][
|
|
63
|
+
'@margin-left'
|
|
64
|
+
];
|
|
65
|
+
if (marginLeft) {
|
|
66
|
+
attrs['odtMarginLeft'] = inchesToMm(marginLeft);
|
|
67
|
+
}
|
|
44
68
|
}
|
|
45
69
|
}
|
|
46
70
|
|
|
@@ -53,9 +77,9 @@ function processListStyle(ctx: OdtStashContext, level: number) {
|
|
|
53
77
|
// https://docs.oasis-open.org/office/OpenDocument/v1.4/OpenDocument-v1.4-part3-schema.html#element-text_list
|
|
54
78
|
export function getListNodesHandlers(): Record<string, NodeHandler> {
|
|
55
79
|
return {
|
|
56
|
-
'list': (ctx: OdtStashContext, odtElement
|
|
80
|
+
'list': (ctx: OdtStashContext, odtElement) => {
|
|
57
81
|
const listTracker = ctx.listTracker;
|
|
58
|
-
listTracker.pushList(odtElement['@id'], odtElement['@style-name']);
|
|
82
|
+
listTracker.pushList(odtElement['@xml:id'], odtElement['@style-name']);
|
|
59
83
|
|
|
60
84
|
const { nodeTypeName, attrs } = processListStyle(
|
|
61
85
|
ctx,
|
|
@@ -64,8 +88,8 @@ export function getListNodesHandlers(): Record<string, NodeHandler> {
|
|
|
64
88
|
|
|
65
89
|
ctx.current.meta['list_type'] = nodeTypeName;
|
|
66
90
|
|
|
67
|
-
if (odtElement['@id']) {
|
|
68
|
-
attrs['id'] = odtElement['@id'];
|
|
91
|
+
if (odtElement['@xml:id']) {
|
|
92
|
+
attrs['id'] = odtElement['@xml:id'];
|
|
69
93
|
}
|
|
70
94
|
if (odtElement['@continue-list']) {
|
|
71
95
|
attrs['continue'] = odtElement['@continue-list'];
|
|
@@ -76,7 +100,7 @@ export function getListNodesHandlers(): Record<string, NodeHandler> {
|
|
|
76
100
|
|
|
77
101
|
ctx.openNode();
|
|
78
102
|
|
|
79
|
-
const children = odtElement['list-item'].map((item) => ({
|
|
103
|
+
const children = odtElement['list-item'].map((item: any) => ({
|
|
80
104
|
'list-item': item,
|
|
81
105
|
}));
|
|
82
106
|
|