@adobe/helix-importer 2.0.0 → 2.1.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.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ # [2.1.0](https://github.com/adobe/helix-importer/compare/v2.0.0...v2.1.0) (2022-09-28)
2
+
3
+
4
+ ### Features
5
+
6
+ * use gridtables for markdown ([#31](https://github.com/adobe/helix-importer/issues/31)) ([b0c8922](https://github.com/adobe/helix-importer/commit/b0c8922c3b7d06d5f5ff2be2ef881e52b0f84fed)), closes [#30](https://github.com/adobe/helix-importer/issues/30)
7
+
1
8
  # [2.0.0](https://github.com/adobe/helix-importer/compare/v1.16.1...v2.0.0) (2022-09-23)
2
9
 
3
10
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adobe/helix-importer",
3
- "version": "2.0.0",
3
+ "version": "2.1.0",
4
4
  "description": "Helix Importer tool: create md / docx from html",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
@@ -34,6 +34,7 @@
34
34
  "c8": "7.12.0",
35
35
  "dirname-filename-esm": "1.1.1",
36
36
  "eslint": "8.7.0",
37
+ "eslint-import-resolver-exports": "1.0.0-beta.3",
37
38
  "eslint-plugin-header": "3.1.1",
38
39
  "eslint-plugin-import": "2.25.4",
39
40
  "husky": "8.0.1",
@@ -45,7 +46,8 @@
45
46
  },
46
47
  "license": "Apache-2.0",
47
48
  "dependencies": {
48
- "@adobe/helix-md2docx": "2.0.1",
49
+ "@adobe/helix-markdown-support": "5.0.7",
50
+ "@adobe/helix-md2docx": "2.0.4",
49
51
  "form-data": "4.0.0",
50
52
  "fs-extra": "10.1.0",
51
53
  "hast-util-to-html": "8.0.3",
@@ -22,11 +22,18 @@ import rehype2remark from 'rehype-remark';
22
22
  import stringify from 'remark-stringify';
23
23
  import fs from 'fs-extra';
24
24
  import { md2docx } from '@adobe/helix-md2docx';
25
+ import { remarkGridTable } from '@adobe/helix-markdown-support/gridtable';
26
+ import { imageReferences } from '@adobe/helix-markdown-support';
27
+ import gridtableHandlers from './hast-to-mdast-gridtable-handlers.js';
25
28
  import Utils from '../utils/Utils.js';
26
29
  import DOMUtils from '../utils/DOMUtils.js';
27
30
  import FileUtils from '../utils/FileUtils.js';
28
31
  import MDUtils from '../utils/MDUtils.js';
29
32
 
33
+ function remarkImageReferences() {
34
+ return imageReferences;
35
+ }
36
+
30
37
  export default class PageImporter {
31
38
  params;
32
39
 
@@ -61,7 +68,7 @@ export default class PageImporter {
61
68
  handlers: {
62
69
  hlxembed: (h, node) => {
63
70
  const children = node.children.map((child) => processor.stringify(child).trim());
64
- return h(node, 'text', `${children.join()}\n`);
71
+ return h(node, 'paragraph', [h(node, 'text', children.join())]);
65
72
  },
66
73
  u: (h, node) => {
67
74
  if (node.children && node.children.length > 0) {
@@ -81,9 +88,11 @@ export default class PageImporter {
81
88
  }
82
89
  return '';
83
90
  },
84
- table: (h, node) => h(node, 'html', toHtml(node)),
91
+ ...gridtableHandlers,
85
92
  },
86
93
  })
94
+ .use(remarkImageReferences)
95
+ .use(remarkGridTable)
87
96
  .use(stringify, {
88
97
  bullet: '-',
89
98
  fence: '`',
@@ -0,0 +1,101 @@
1
+ /*
2
+ * Copyright 2022 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 'hast-util-to-mdast';
13
+ import {
14
+ TYPE_BODY,
15
+ TYPE_CELL,
16
+ TYPE_FOOTER,
17
+ TYPE_HEADER,
18
+ TYPE_ROW,
19
+ TYPE_TABLE,
20
+ } from '@adobe/helix-markdown-support/gridtable';
21
+
22
+ function convert(type) {
23
+ return (h, node) => h(node, type, all(h, node));
24
+ }
25
+
26
+ function table(h, node) {
27
+ let children = all(h, node);
28
+
29
+ // people never create <thead> or <tbody>, but only use a <th> to mark the cell (row) as header
30
+ // which is technically wrong, since also a column can be a header. however the default sanitized
31
+ // dom will always have a <tbody> so we need move rows that have a <th> cell into the table head.
32
+ if (!children.find(({ type }) => type === TYPE_HEADER)) {
33
+ const head = [];
34
+ const body = [];
35
+
36
+ const shove = (r) => {
37
+ if (r.hasHeaderCell) {
38
+ head.push(r);
39
+ } else {
40
+ body.push(r);
41
+ }
42
+ // eslint-disable-next-line no-param-reassign
43
+ delete r.hasHeaderCell;
44
+ };
45
+
46
+ for (const child of children) {
47
+ if (child.type === TYPE_ROW) {
48
+ shove(child);
49
+ } else {
50
+ child.children.forEach(shove);
51
+ }
52
+ }
53
+ children = [];
54
+ if (head.length) {
55
+ children.push(h(node, TYPE_HEADER, head));
56
+ }
57
+ if (body.length) {
58
+ children.push(h(node, TYPE_BODY, body));
59
+ }
60
+ }
61
+ return h(node, TYPE_TABLE, children);
62
+ }
63
+
64
+ function row(h, node) {
65
+ const mdast = h(node, TYPE_ROW, all(h, node));
66
+ mdast.hasHeaderCell = node.hasHeaderCell;
67
+ return mdast;
68
+ }
69
+
70
+ function cell(h, node, parent) {
71
+ const ATTR_MAP = {
72
+ align: 'align',
73
+ valign: 'valign',
74
+ rowspan: 'rowSpan',
75
+ colspan: 'colSpan',
76
+ };
77
+ if (node.tagName === 'th') {
78
+ // eslint-disable-next-line no-param-reassign
79
+ parent.hasHeaderCell = true;
80
+ }
81
+ const props = {};
82
+ if (node.properties) {
83
+ for (const [key, value] of Object.entries(node.properties)) {
84
+ const lKey = key.toLowerCase();
85
+ if (lKey in ATTR_MAP) {
86
+ props[ATTR_MAP[lKey]] = value;
87
+ }
88
+ }
89
+ }
90
+ return h(node, TYPE_CELL, props, all(h, node));
91
+ }
92
+
93
+ export default {
94
+ table,
95
+ thead: convert(TYPE_HEADER),
96
+ tbody: convert(TYPE_BODY),
97
+ tfoot: convert(TYPE_FOOTER),
98
+ tr: row,
99
+ td: cell,
100
+ th: cell,
101
+ };
@@ -1,6 +1,6 @@
1
1
  # How Sample Performance Management Improved in 2021
2
2
 
3
- ![](https://www.sample.com/blog/wp-content/uploads/How-Sample-Performance-Management-Improved-in-2021_1920x733-scaled.jpg)
3
+ ![][image0]
4
4
 
5
5
  Over the course of 2021, we've improved Sample® Performance Management with more flexibility and greater depth, giving you more choice for the when, who, and how of the performance management process at your organization. Here's a quick summary to let you know how to take advantage of these updates.
6
6
 
@@ -8,7 +8,7 @@ Over the course of 2021, we've improved Sample® Performance Management with mor
8
8
 
9
9
  These updates give greater flexibility in the cadence and dates you administer assessments and feedback. We separated scheduling for assessments and feedback, so each process can operate on separate timelines depending on your needs. For example, you might choose to have feedback sessions every four months while keeping formal assessments on a six-month schedule.
10
10
 
11
- ![Screen\_Shot\_2022-01-05\_at\_9.26.41\_AM](https://www.sample.com/blog/wp-content/uploads/Screen_Shot_2022-01-05_at_9.26.41_AM.png)
11
+ ![Screen\_Shot\_2022-01-05\_at\_9.26.41\_AM][image1]
12
12
 
13
13
  We also made performance reports searchable by date range instead of tying them to individual Performance Management events.
14
14
 
@@ -16,7 +16,7 @@ We also made performance reports searchable by date range instead of tying them
16
16
 
17
17
  When an employee moves to a new team right before their scheduled assessment, their new manager might not have what they need to make accurate observations. To resolve this issue, you now have the option to [skip a regularly-scheduled assessment](https://help.sample.com/hc/en-us/articles/360060935131-skip-assessments).
18
18
 
19
- ![a66eddc3-4e16-49a9-b597-1151e233790d](https://www.sample.com/blog/wp-content/uploads/a66eddc3-4e16-49a9-b597-1151e233790d.png)
19
+ ![a66eddc3-4e16-49a9-b597-1151e233790d][image2]
20
20
 
21
21
  This doesn't mean someone who skips an assessment has to go without feedback for months. Scheduling [impromptu assessments](https://help.sample.com/hc/en-us/articles/360060531312-impromptu-assessments) helps you keep employees informed during off-cycle evaluations, such as:
22
22
 
@@ -25,7 +25,7 @@ This doesn't mean someone who skips an assessment has to go without feedback for
25
25
  - On their anniversary
26
26
  - As part of their onboarding process
27
27
 
28
- ![Impromptu Assessment (1)](https://www.sample.com/blog/wp-content/uploads/Impromptu-Assessment-1.png)
28
+ ![Impromptu Assessment (1)][image3]
29
29
 
30
30
  ## Expanded Feedback
31
31
 
@@ -49,6 +49,43 @@ These updates help expand Performance Management's reach and help your managers
49
49
 
50
50
  [Performance Settings Updates](https://help.sample.com/hc/en-us/articles/360057083332-Performance-Management-Settings-Update-2-25-2021-)
51
51
 
52
- <table><tbody><tr><th>Related Posts</th></tr><tr><td><a class="blogPostsBlock__titleLink" href="https://www.sample.com/blog/how-sample-performance-management-improved-in-2021/" aria-label="How Sample Performance Management Improved in 2021">https://www.sample.com/blog/how-sample-performance-management-improved-in-2021/</a></td></tr><tr><td><a class="blogPostsBlock__titleLink" href="https://www.sample.com/blog/announcing-the-product-updates-webpage/" aria-label="Announcing the Product Updates Webpage">https://www.sample.com/blog/announcing-the-product-updates-webpage/</a></td></tr><tr><td><a class="blogPostsBlock__titleLink" href="https://www.sample.com/blog/take-a-look-back-at-2021/" aria-label="Take a Look Back at 2021">https://www.sample.com/blog/take-a-look-back-at-2021/</a></td></tr><tr><td><a class="blogPostsBlock__titleLink" href="https://www.sample.com/blog/whats-new-in-sample-vaccination-tracking-feature/" aria-label="What&#x27;s New in Sample: Vaccination Tracking Feature">https://www.sample.com/blog/whats-new-in-sample-vaccination-tracking-feature/</a></td></tr></tbody></table>
53
-
54
- <table><tbody><tr><th colspan="2">Metadata</th></tr><tr><td>Title</td><td>How Sample Performance Management Improved in 2021 - Sample Blog</td></tr><tr><td>Description</td><td>In 2021, we improved Sample® Performance Management with more flexibility and greater depth, giving you finer control of your performance management.</td></tr><tr><td>Category</td><td>Product Announcements</td></tr><tr><td>Author</td><td><a href="https://www.sample.com/blog/author/eserdar/" rel="author" class="fn" style="color: #1d9336;">Eric Serdar</a></td></tr><tr><td>Read Time</td><td>8 min</td></tr><tr><td>Image</td><td><img src="https://www.sample.com/blog/wp-content/uploads/How-Sample-Performance-Management-Improved-in-2021_1200x628-1024x536.jpg"></td></tr></tbody></table>
52
+ +-----------------------------------------------------------------------------------+
53
+ | Related Posts |
54
+ +===================================================================================+
55
+ | <https://www.sample.com/blog/how-sample-performance-management-improved-in-2021/> |
56
+ +-----------------------------------------------------------------------------------+
57
+ | <https://www.sample.com/blog/announcing-the-product-updates-webpage/> |
58
+ +-----------------------------------------------------------------------------------+
59
+ | <https://www.sample.com/blog/take-a-look-back-at-2021/> |
60
+ +-----------------------------------------------------------------------------------+
61
+ | <https://www.sample.com/blog/whats-new-in-sample-vaccination-tracking-feature/> |
62
+ +-----------------------------------------------------------------------------------+
63
+
64
+ +--------------------------------------------------------------------------+
65
+ | Metadata |
66
+ +=============+============================================================+
67
+ | Title | How Sample Performance Management Improved in 2021 - |
68
+ | | Sample Blog |
69
+ +-------------+------------------------------------------------------------+
70
+ | Description | In 2021, we improved Sample® Performance Management with |
71
+ | | more flexibility and greater depth, giving you finer |
72
+ | | control of your performance management. |
73
+ +-------------+------------------------------------------------------------+
74
+ | Category | Product Announcements |
75
+ +-------------+------------------------------------------------------------+
76
+ | Author | [Eric Serdar](https://www.sample.com/blog/author/eserdar/) |
77
+ +-------------+------------------------------------------------------------+
78
+ | Read Time | 8 min |
79
+ +-------------+------------------------------------------------------------+
80
+ | Image | ![][image4] |
81
+ +-------------+------------------------------------------------------------+
82
+
83
+ [image0]: https://www.sample.com/blog/wp-content/uploads/How-Sample-Performance-Management-Improved-in-2021_1920x733-scaled.jpg
84
+
85
+ [image1]: https://www.sample.com/blog/wp-content/uploads/Screen_Shot_2022-01-05_at_9.26.41_AM.png
86
+
87
+ [image2]: https://www.sample.com/blog/wp-content/uploads/a66eddc3-4e16-49a9-b597-1151e233790d.png
88
+
89
+ [image3]: https://www.sample.com/blog/wp-content/uploads/Impromptu-Assessment-1.png
90
+
91
+ [image4]: https://www.sample.com/blog/wp-content/uploads/How-Sample-Performance-Management-Improved-in-2021_1200x628-1024x536.jpg
@@ -1,5 +1,29 @@
1
1
  # Table sample
2
2
 
3
- <table><tbody><tr><td colspan="2">Metadata</td></tr><tr><td>Title</td><td>This is the title of the page</td></tr><tr><td>Link</td><td><span></span><a href="https://www.sample.com">A link</a></td></tr><tr><td>List</td><td><ul><li>Value 1</li><li>Value 2</li><li>Another value...</li></ul></td></tr><tr><td>Paragraphs</td><td><p>Paragraph 1 with some text</p><p>Paragraph 2 with some text too!</p></td></tr></tbody></table>
3
+ +-----------------------------------------------+
4
+ | Metadata |
5
+ +------------+----------------------------------+
6
+ | Title | This is the title of the page |
7
+ +------------+----------------------------------+
8
+ | Link | [A link](https://www.sample.com) |
9
+ +------------+----------------------------------+
10
+ | List | - Value 1 |
11
+ | | - Value 2 |
12
+ | | - Another value... |
13
+ +------------+----------------------------------+
14
+ | Paragraphs | Paragraph 1 with some text |
15
+ | | |
16
+ | | Paragraph 2 with some text too! |
17
+ +------------+----------------------------------+
4
18
 
5
- <table><tbody><tr><th colspan="2">Metadata</th></tr><tr><td>title</td><td>Some title</td></tr><tr><td>Tags</td><td><p>Creative</p><p>Experience Cloud</p><p>Photography</p></td></tr></tbody></table>
19
+ +--------------------------+
20
+ | Metadata |
21
+ +=======+==================+
22
+ | title | Some title |
23
+ +-------+------------------+
24
+ | Tags | Creative |
25
+ | | |
26
+ | | Experience Cloud |
27
+ | | |
28
+ | | Photography |
29
+ +-------+------------------+