@adobe/helix-md2docx 1.0.1

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.
Files changed (58) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/CODE_OF_CONDUCT.md +74 -0
  3. package/CONTRIBUTING.md +74 -0
  4. package/LICENSE.txt +264 -0
  5. package/README.md +33 -0
  6. package/package.json +70 -0
  7. package/src/cli/convert2docx.js +96 -0
  8. package/src/index.d.ts +13 -0
  9. package/src/index.js +13 -0
  10. package/src/mdast2docx/all.js +31 -0
  11. package/src/mdast2docx/default-numbering.js +79 -0
  12. package/src/mdast2docx/handlers/break.js +22 -0
  13. package/src/mdast2docx/handlers/characterStyle.js +29 -0
  14. package/src/mdast2docx/handlers/code.js +27 -0
  15. package/src/mdast2docx/handlers/heading.js +32 -0
  16. package/src/mdast2docx/handlers/html.js +35 -0
  17. package/src/mdast2docx/handlers/image.js +90 -0
  18. package/src/mdast2docx/handlers/index.js +56 -0
  19. package/src/mdast2docx/handlers/inlineCode.js +21 -0
  20. package/src/mdast2docx/handlers/link.js +63 -0
  21. package/src/mdast2docx/handlers/list.js +39 -0
  22. package/src/mdast2docx/handlers/listItem.js +16 -0
  23. package/src/mdast2docx/handlers/paragraph.js +52 -0
  24. package/src/mdast2docx/handlers/paragraphStyle.js +21 -0
  25. package/src/mdast2docx/handlers/root.js +16 -0
  26. package/src/mdast2docx/handlers/table.js +54 -0
  27. package/src/mdast2docx/handlers/tableCell.js +51 -0
  28. package/src/mdast2docx/handlers/tableRow.js +28 -0
  29. package/src/mdast2docx/handlers/text.js +24 -0
  30. package/src/mdast2docx/handlers/thematicBreak.js +24 -0
  31. package/src/mdast2docx/hast-table-handler.js +145 -0
  32. package/src/mdast2docx/index.d.ts +21 -0
  33. package/src/mdast2docx/index.js +88 -0
  34. package/src/mdast2docx/mdast-download-images.js +92 -0
  35. package/src/mdast2docx/mdast-sanitize-html.js +112 -0
  36. package/src/mdast2docx/template/[Content_Types].xml +41 -0
  37. package/src/mdast2docx/template/docProps/app.xml +20 -0
  38. package/src/mdast2docx/template/docProps/core.xml +12 -0
  39. package/src/mdast2docx/template/word/_rels/document.xml.rels +51 -0
  40. package/src/mdast2docx/template/word/_rels/settings.xml.rels +7 -0
  41. package/src/mdast2docx/template/word/document.xml +1116 -0
  42. package/src/mdast2docx/template/word/endnotes.xml +56 -0
  43. package/src/mdast2docx/template/word/fontTable.xml +58 -0
  44. package/src/mdast2docx/template/word/footer1.xml +39 -0
  45. package/src/mdast2docx/template/word/footer2.xml +39 -0
  46. package/src/mdast2docx/template/word/footer3.xml +39 -0
  47. package/src/mdast2docx/template/word/footnotes.xml +56 -0
  48. package/src/mdast2docx/template/word/header1.xml +39 -0
  49. package/src/mdast2docx/template/word/header2.xml +39 -0
  50. package/src/mdast2docx/template/word/header3.xml +39 -0
  51. package/src/mdast2docx/template/word/media/image1.png +0 -0
  52. package/src/mdast2docx/template/word/numbering.xml +277 -0
  53. package/src/mdast2docx/template/word/settings.xml +91 -0
  54. package/src/mdast2docx/template/word/styles.xml +1084 -0
  55. package/src/mdast2docx/template/word/theme/theme1.xml +296 -0
  56. package/src/mdast2docx/template/word/webSettings.xml +40 -0
  57. package/src/mdast2docx/template.docx +0 -0
  58. package/src/mdast2docx/utils.js +22 -0
@@ -0,0 +1,31 @@
1
+ /*
2
+ * Copyright 2021 Adobe. All rights reserved.
3
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
+ * you may not use this file except in compliance with the License. You may obtain a copy
5
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
6
+ *
7
+ * Unless required by applicable law or agreed to in writing, software distributed under
8
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
+ * OF ANY KIND, either express or implied. See the License for the specific language
10
+ * governing permissions and limitations under the License.
11
+ */
12
+
13
+ function unknown() {
14
+ return undefined;
15
+ }
16
+
17
+ export default async function all(ctx, parent) {
18
+ const nodes = parent.children || [];
19
+ let values = [];
20
+
21
+ for (const node of nodes) {
22
+ const fn = ctx.handlers[node.type] || unknown;
23
+
24
+ // eslint-disable-next-line no-await-in-loop
25
+ const result = await fn(ctx, node, parent, values);
26
+ if (result) {
27
+ values = values.concat(result);
28
+ }
29
+ }
30
+ return values;
31
+ }
@@ -0,0 +1,79 @@
1
+ /*
2
+ * Copyright 2021 Adobe. All rights reserved.
3
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
+ * you may not use this file except in compliance with the License. You may obtain a copy
5
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
6
+ *
7
+ * Unless required by applicable law or agreed to in writing, software distributed under
8
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
+ * OF ANY KIND, either express or implied. See the License for the specific language
10
+ * governing permissions and limitations under the License.
11
+ */
12
+ import docx from 'docx';
13
+
14
+ const { AlignmentType, convertMillimetersToTwip, LevelFormat } = docx;
15
+
16
+ function createLevels() {
17
+ const levels = [];
18
+ const formats = [
19
+ LevelFormat.DECIMAL,
20
+ LevelFormat.LOWER_LETTER,
21
+ LevelFormat.LOWER_ROMAN,
22
+ ];
23
+ const sfx = [
24
+ '.',
25
+ '',
26
+ '',
27
+ ];
28
+ for (let level = 0; level < 6; level += 1) {
29
+ levels.push({
30
+ level,
31
+ format: formats[level % 3],
32
+ text: `%${level + 1}${sfx[level % 3]}`,
33
+ alignment: AlignmentType.START,
34
+ style: {
35
+ paragraph: {
36
+ indent: {
37
+ left: convertMillimetersToTwip(10 * (level + 1)),
38
+ hanging: convertMillimetersToTwip(5),
39
+ },
40
+ },
41
+ },
42
+ });
43
+ }
44
+ return levels;
45
+ }
46
+
47
+ function createBulletLevels() {
48
+ const levels = [];
49
+ for (let level = 0; level < 6; level += 1) {
50
+ levels.push({
51
+ level,
52
+ format: LevelFormat.BULLET,
53
+ text: '-',
54
+ alignment: AlignmentType.START,
55
+ style: {
56
+ paragraph: {
57
+ indent: {
58
+ left: convertMillimetersToTwip(5 * (level + 1)),
59
+ hanging: convertMillimetersToTwip(5),
60
+ },
61
+ },
62
+ },
63
+ });
64
+ }
65
+ return levels;
66
+ }
67
+
68
+ export default {
69
+ config: [
70
+ {
71
+ reference: 'default-numbering',
72
+ levels: createLevels(),
73
+ },
74
+ {
75
+ reference: 'default-bullets',
76
+ levels: createBulletLevels(),
77
+ },
78
+ ],
79
+ };
@@ -0,0 +1,22 @@
1
+ /*
2
+ * Copyright 2021 Adobe. All rights reserved.
3
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
+ * you may not use this file except in compliance with the License. You may obtain a copy
5
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
6
+ *
7
+ * Unless required by applicable law or agreed to in writing, software distributed under
8
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
+ * OF ANY KIND, either express or implied. See the License for the specific language
10
+ * governing permissions and limitations under the License.
11
+ */
12
+ import docx from 'docx';
13
+
14
+ const { TextRun } = docx;
15
+
16
+ export default function brk() {
17
+ return new TextRun({
18
+ // could probably be optimized....
19
+ text: '',
20
+ break: 1,
21
+ });
22
+ }
@@ -0,0 +1,29 @@
1
+ /*
2
+ * Copyright 2021 Adobe. All rights reserved.
3
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
+ * you may not use this file except in compliance with the License. You may obtain a copy
5
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
6
+ *
7
+ * Unless required by applicable law or agreed to in writing, software distributed under
8
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
+ * OF ANY KIND, either express or implied. See the License for the specific language
10
+ * governing permissions and limitations under the License.
11
+ */
12
+ import all from '../all.js';
13
+
14
+ export default function characterStyle(opts) {
15
+ return async (ctx, node) => {
16
+ if (typeof opts === 'string') {
17
+ // eslint-disable-next-line no-param-reassign
18
+ opts = {
19
+ [opts]: true,
20
+ };
21
+ }
22
+ Object.assign(ctx.style, opts);
23
+ const result = await all(ctx, node);
24
+ Object.keys(opts).forEach((key) => {
25
+ delete ctx.style[key];
26
+ });
27
+ return result;
28
+ };
29
+ }
@@ -0,0 +1,27 @@
1
+ /*
2
+ * Copyright 2021 Adobe. All rights reserved.
3
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
+ * you may not use this file except in compliance with the License. You may obtain a copy
5
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
6
+ *
7
+ * Unless required by applicable law or agreed to in writing, software distributed under
8
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
+ * OF ANY KIND, either express or implied. See the License for the specific language
10
+ * governing permissions and limitations under the License.
11
+ */
12
+ import docx from 'docx';
13
+
14
+ const { Paragraph, TextRun } = docx;
15
+
16
+ export default function code(ctx, node) {
17
+ const children = node.value.split('\n').map((text, idx) => (
18
+ new TextRun({
19
+ text,
20
+ break: idx > 0 ? 1 : 0,
21
+ })
22
+ ));
23
+ return new Paragraph({
24
+ children,
25
+ style: 'CodeBlock',
26
+ });
27
+ }
@@ -0,0 +1,32 @@
1
+ /*
2
+ * Copyright 2021 Adobe. All rights reserved.
3
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
+ * you may not use this file except in compliance with the License. You may obtain a copy
5
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
6
+ *
7
+ * Unless required by applicable law or agreed to in writing, software distributed under
8
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
+ * OF ANY KIND, either express or implied. See the License for the specific language
10
+ * governing permissions and limitations under the License.
11
+ */
12
+ import docx from 'docx';
13
+ import all from '../all.js';
14
+
15
+ const { HeadingLevel, Paragraph } = docx;
16
+
17
+ const DEPTHS = [
18
+ HeadingLevel.HEADING_1,
19
+ HeadingLevel.HEADING_2,
20
+ HeadingLevel.HEADING_3,
21
+ HeadingLevel.HEADING_4,
22
+ HeadingLevel.HEADING_5,
23
+ HeadingLevel.HEADING_6,
24
+ ];
25
+
26
+ export default async function heading(ctx, node) {
27
+ const children = await all(ctx, node);
28
+ return new Paragraph({
29
+ heading: DEPTHS[node.depth - 1],
30
+ children,
31
+ });
32
+ }
@@ -0,0 +1,35 @@
1
+ /*
2
+ * Copyright 2021 Adobe. All rights reserved.
3
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
+ * you may not use this file except in compliance with the License. You may obtain a copy
5
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
6
+ *
7
+ * Unless required by applicable law or agreed to in writing, software distributed under
8
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
+ * OF ANY KIND, either express or implied. See the License for the specific language
10
+ * governing permissions and limitations under the License.
11
+ */
12
+ import docx from 'docx';
13
+
14
+ const { Paragraph, TextRun } = docx;
15
+
16
+ export default function html(ctx, node, parent) {
17
+ if (node.value === '<!---->') {
18
+ // ignore
19
+ return undefined;
20
+ }
21
+ // should not occur...just create text
22
+ const text = new TextRun({
23
+ color: 'ff0000',
24
+ text: node.value,
25
+ });
26
+
27
+ if (parent.type === 'paragraph') {
28
+ return text;
29
+ }
30
+ return new Paragraph({
31
+ children: [
32
+ text,
33
+ ],
34
+ });
35
+ }
@@ -0,0 +1,90 @@
1
+ /*
2
+ * Copyright 2021 Adobe. All rights reserved.
3
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
+ * you may not use this file except in compliance with the License. You may obtain a copy
5
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
6
+ *
7
+ * Unless required by applicable law or agreed to in writing, software distributed under
8
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
+ * OF ANY KIND, either express or implied. See the License for the specific language
10
+ * governing permissions and limitations under the License.
11
+ */
12
+ import docx from 'docx';
13
+ import { findXMLComponent } from '../utils.js';
14
+
15
+ const { Drawing, ImageRun } = docx;
16
+
17
+ // max image width (6.5") and height (2")
18
+ const LIMITS = {
19
+ width: 914400 * 6.5,
20
+ height: 914400 * 2.0,
21
+ };
22
+
23
+ // max image width (2") and height (1") in tables
24
+ const LIMITS_TABLE = {
25
+ width: 914400 * 2.0,
26
+ height: 914400,
27
+ };
28
+
29
+ export default async function image(ctx, node) {
30
+ const { data } = node;
31
+ if (!data) {
32
+ return undefined;
33
+ }
34
+ let x = data.dimensions.width * 9525;
35
+ let y = data.dimensions.height * 9525;
36
+ const limits = ctx.tableAlign ? LIMITS_TABLE : LIMITS;
37
+ if (x > limits.width) {
38
+ y = Math.round((limits.width * y) / x);
39
+ x = limits.width;
40
+ }
41
+ if (y > limits.height) {
42
+ x = Math.round((limits.height * x) / y);
43
+ y = limits.height;
44
+ }
45
+
46
+ const imageData = {
47
+ stream: data.buffer,
48
+ fileName: data.key,
49
+ transformation: {
50
+ pixels: {
51
+ x: Math.round(data.dimensions.width),
52
+ y: Math.round(data.dimensions.height),
53
+ },
54
+ emus: {
55
+ x,
56
+ y,
57
+ },
58
+ },
59
+ };
60
+
61
+ const drawing = new Drawing(imageData, { floating: false });
62
+ // hack to get document properties to set alt text
63
+ if (node.title || node.alt) {
64
+ const docProps = findXMLComponent(drawing, 'wp:inline/wp:docPr/_attr');
65
+ if (docProps && docProps.root) {
66
+ if (node.title) {
67
+ docProps.root.title = node.title;
68
+ }
69
+ if (node.alt) {
70
+ docProps.root.descr = node.alt;
71
+ }
72
+ }
73
+ }
74
+
75
+ // create picture
76
+ const pic = new ImageRun({
77
+ data: data.buffer,
78
+ transformation: data.dimensions,
79
+ });
80
+ // replace drawing
81
+ const oldDrawing = findXMLComponent(pic, 'w:drawing');
82
+ const idx = pic.root.indexOf(oldDrawing);
83
+ if (idx >= 0) {
84
+ pic.root.splice(idx, 1);
85
+ }
86
+ pic.root.push(drawing);
87
+ pic.key = data.key;
88
+ pic.imageData = imageData;
89
+ return pic;
90
+ }
@@ -0,0 +1,56 @@
1
+ /*
2
+ * Copyright 2021 Adobe. All rights reserved.
3
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
+ * you may not use this file except in compliance with the License. You may obtain a copy
5
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
6
+ *
7
+ * Unless required by applicable law or agreed to in writing, software distributed under
8
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
+ * OF ANY KIND, either express or implied. See the License for the specific language
10
+ * governing permissions and limitations under the License.
11
+ */
12
+
13
+ import brk from './break.js';
14
+ import characterStyle from './characterStyle.js';
15
+ import code from './code.js';
16
+ import heading from './heading.js';
17
+ import html from './html.js';
18
+ import image from './image.js';
19
+ import inlineCode from './inlineCode.js';
20
+ import link from './link.js';
21
+ import list from './list.js';
22
+ import listItem from './listItem.js';
23
+ import paragraph from './paragraph.js';
24
+ import paragraphStyle from './paragraphStyle.js';
25
+ import root from './root.js';
26
+ import table from './table.js';
27
+ import tableRow from './tableRow.js';
28
+ import tableCell from './tableCell.js';
29
+ import text from './text.js';
30
+ import thematicBreak from './thematicBreak.js';
31
+
32
+ export default {
33
+ blockquote: paragraphStyle('Quote'),
34
+ break: brk,
35
+ code,
36
+ delete: characterStyle('strike'),
37
+ emphasis: characterStyle('italics'),
38
+ strong: characterStyle('bold'),
39
+ underline: characterStyle('underline'),
40
+ subScript: characterStyle('subScript'),
41
+ superScript: characterStyle('superScript'),
42
+ heading,
43
+ html,
44
+ image,
45
+ inlineCode,
46
+ link,
47
+ list,
48
+ listItem,
49
+ paragraph,
50
+ root,
51
+ table,
52
+ tableRow,
53
+ tableCell,
54
+ text,
55
+ thematicBreak,
56
+ };
@@ -0,0 +1,21 @@
1
+ /*
2
+ * Copyright 2021 Adobe. All rights reserved.
3
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
+ * you may not use this file except in compliance with the License. You may obtain a copy
5
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
6
+ *
7
+ * Unless required by applicable law or agreed to in writing, software distributed under
8
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
+ * OF ANY KIND, either express or implied. See the License for the specific language
10
+ * governing permissions and limitations under the License.
11
+ */
12
+ import docx from 'docx';
13
+
14
+ const { TextRun } = docx;
15
+
16
+ export default function inlineCode(ctx, node) {
17
+ return new TextRun({
18
+ text: node.value,
19
+ style: 'InlineCode',
20
+ });
21
+ }
@@ -0,0 +1,63 @@
1
+ /*
2
+ * Copyright 2021 Adobe. All rights reserved.
3
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
+ * you may not use this file except in compliance with the License. You may obtain a copy
5
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
6
+ *
7
+ * Unless required by applicable law or agreed to in writing, software distributed under
8
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
+ * OF ANY KIND, either express or implied. See the License for the specific language
10
+ * governing permissions and limitations under the License.
11
+ */
12
+ import docx from 'docx';
13
+ import all from '../all.js';
14
+
15
+ const { ExternalHyperlink, ImageRun, TextRun } = docx;
16
+
17
+ /**
18
+ * Handles links.
19
+ *
20
+ * @param ctx
21
+ * @param node
22
+ * @returns {Promise<[]>}
23
+ */
24
+ export default async function link(ctx, node) {
25
+ const result = [];
26
+ ctx.style.style = 'Hyperlink';
27
+
28
+ const children = await all(ctx, node);
29
+ // check if one of the children is an image
30
+ if (children.findIndex((child) => child instanceof ImageRun) >= 0) {
31
+ for (const child of await all(ctx, node)) {
32
+ // links on images can't be edited in word. so create a link below the image
33
+ if (child instanceof ImageRun) {
34
+ result.push(
35
+ child,
36
+ new TextRun({ text: '', break: 1 }),
37
+ new ExternalHyperlink({
38
+ children: [
39
+ new TextRun({ text: node.url, style: 'Hyperlink' }),
40
+ ],
41
+ link: node.url,
42
+ }),
43
+ new TextRun({ text: '', break: 1 }),
44
+ );
45
+ } else {
46
+ result.push(new ExternalHyperlink({
47
+ children: [
48
+ child,
49
+ ],
50
+ link: node.url,
51
+ }));
52
+ }
53
+ }
54
+ } else {
55
+ result.push(new ExternalHyperlink({
56
+ children,
57
+ link: node.url,
58
+ }));
59
+ }
60
+
61
+ delete ctx.style.style;
62
+ return result;
63
+ }
@@ -0,0 +1,39 @@
1
+ /*
2
+ * Copyright 2021 Adobe. All rights reserved.
3
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
+ * you may not use this file except in compliance with the License. You may obtain a copy
5
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
6
+ *
7
+ * Unless required by applicable law or agreed to in writing, software distributed under
8
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
+ * OF ANY KIND, either express or implied. See the License for the specific language
10
+ * governing permissions and limitations under the License.
11
+ */
12
+ import all from '../all.js';
13
+
14
+ export default async function list(ctx, node) {
15
+ const { ordered, start } = node;
16
+ ctx.listLevel += 1;
17
+ let lst = ctx.lists[ctx.listLevel];
18
+ if (!lst) {
19
+ lst = {
20
+ level: ctx.listLevel,
21
+ number: start || 1,
22
+ instance: 1,
23
+ };
24
+ ctx.lists[ctx.listLevel] = lst;
25
+ }
26
+ if (start && start < lst.number) {
27
+ lst.number = start;
28
+ lst.instance += 1;
29
+ }
30
+ if (ordered) {
31
+ lst.numbering = 'default-numbering';
32
+ } else {
33
+ lst.numbering = 'default-bullets';
34
+ }
35
+
36
+ const children = await all(ctx, node);
37
+ ctx.listLevel -= 1;
38
+ return children;
39
+ }
@@ -0,0 +1,16 @@
1
+ /*
2
+ * Copyright 2021 Adobe. All rights reserved.
3
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
+ * you may not use this file except in compliance with the License. You may obtain a copy
5
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
6
+ *
7
+ * Unless required by applicable law or agreed to in writing, software distributed under
8
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
+ * OF ANY KIND, either express or implied. See the License for the specific language
10
+ * governing permissions and limitations under the License.
11
+ */
12
+ import all from '../all.js';
13
+
14
+ export default function listItem(ctx, node) {
15
+ return all(ctx, node);
16
+ }
@@ -0,0 +1,52 @@
1
+ /*
2
+ * Copyright 2021 Adobe. All rights reserved.
3
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
+ * you may not use this file except in compliance with the License. You may obtain a copy
5
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
6
+ *
7
+ * Unless required by applicable law or agreed to in writing, software distributed under
8
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
+ * OF ANY KIND, either express or implied. See the License for the specific language
10
+ * governing permissions and limitations under the License.
11
+ */
12
+ import docx from 'docx';
13
+ import all from '../all.js';
14
+
15
+ const { Paragraph } = docx;
16
+
17
+ export default async function paragraph(ctx, node) {
18
+ // clear style
19
+ ctx.style = {};
20
+
21
+ // fix wrong children (todo: do in preprocessor)
22
+ for (let i = 0; i < node.children.length; i += 1) {
23
+ const child = node.children[i];
24
+ if (child.type === 'paragraph') {
25
+ node.children.splice(i, 1, ...child.children);
26
+ }
27
+ }
28
+
29
+ const children = await all(ctx, node);
30
+ const opts = {
31
+ children,
32
+ };
33
+
34
+ if (ctx.listLevel >= 0) {
35
+ const list = ctx.lists[ctx.listLevel];
36
+ if (list.numbering) {
37
+ opts.numbering = {
38
+ reference: list.numbering,
39
+ level: list.level,
40
+ instance: list.instance,
41
+ };
42
+ list.number += 1;
43
+ } else {
44
+ opts.bullet = {
45
+ level: list.level,
46
+ };
47
+ }
48
+ } else if (ctx.paragraphStyle) {
49
+ opts.style = ctx.paragraphStyle;
50
+ }
51
+ return new Paragraph(opts);
52
+ }
@@ -0,0 +1,21 @@
1
+ /*
2
+ * Copyright 2021 Adobe. All rights reserved.
3
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
+ * you may not use this file except in compliance with the License. You may obtain a copy
5
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
6
+ *
7
+ * Unless required by applicable law or agreed to in writing, software distributed under
8
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
+ * OF ANY KIND, either express or implied. See the License for the specific language
10
+ * governing permissions and limitations under the License.
11
+ */
12
+ import all from '../all.js';
13
+
14
+ export default function paragraphStyle(style) {
15
+ return async (ctx, node) => {
16
+ ctx.paragraphStyle = style;
17
+ const result = await all(ctx, node);
18
+ delete ctx.paragraphStyle;
19
+ return result;
20
+ };
21
+ }
@@ -0,0 +1,16 @@
1
+ /*
2
+ * Copyright 2021 Adobe. All rights reserved.
3
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
+ * you may not use this file except in compliance with the License. You may obtain a copy
5
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
6
+ *
7
+ * Unless required by applicable law or agreed to in writing, software distributed under
8
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
+ * OF ANY KIND, either express or implied. See the License for the specific language
10
+ * governing permissions and limitations under the License.
11
+ */
12
+ import all from '../all.js';
13
+
14
+ export default function root(ctx, node) {
15
+ return all(ctx, node);
16
+ }