@adobe/helix-docx2md 1.4.9 → 1.4.11

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,17 @@
1
+ ## [1.4.11](https://github.com/adobe/helix-docx2md/compare/v1.4.10...v1.4.11) (2023-07-22)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * **deps:** update dependency @adobe/mdast-util-gridtables to v2.0.2 ([d6dcb60](https://github.com/adobe/helix-docx2md/commit/d6dcb60b412a81ad6f33d70729344d25652f516d))
7
+
8
+ ## [1.4.10](https://github.com/adobe/helix-docx2md/compare/v1.4.9...v1.4.10) (2023-07-18)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * improve handling of sub- and superscript ([#266](https://github.com/adobe/helix-docx2md/issues/266)) ([fd32fc8](https://github.com/adobe/helix-docx2md/commit/fd32fc8bcaabe1f591c5ba488abc7a21a37e4f1b)), closes [#262](https://github.com/adobe/helix-docx2md/issues/262)
14
+
1
15
  ## [1.4.9](https://github.com/adobe/helix-docx2md/compare/v1.4.8...v1.4.9) (2023-07-10)
2
16
 
3
17
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adobe/helix-docx2md",
3
- "version": "1.4.9",
3
+ "version": "1.4.11",
4
4
  "description": "Helix library that converts word documents to markdown",
5
5
  "type": "module",
6
6
  "main": "./src/index.js",
@@ -33,10 +33,10 @@
33
33
  },
34
34
  "homepage": "https://github.com/adobe/helix-docx2md#readme",
35
35
  "dependencies": {
36
- "@adobe/helix-markdown-support": "6.1.3",
36
+ "@adobe/helix-markdown-support": "6.2.1",
37
37
  "@adobe/helix-shared-process-queue": "3.0.0",
38
38
  "@adobe/mammoth": "1.5.1-bleeding.2",
39
- "@adobe/mdast-util-gridtables": "2.0.1",
39
+ "@adobe/mdast-util-gridtables": "2.0.2",
40
40
  "@adobe/remark-gridtables": "1.0.4",
41
41
  "dirname-filename-esm": "1.1.1",
42
42
  "github-slugger": "2.0.0",
@@ -52,13 +52,13 @@
52
52
  },
53
53
  "devDependencies": {
54
54
  "@adobe/eslint-config-helix": "2.0.2",
55
- "@adobe/helix-mediahandler": "2.2.4",
55
+ "@adobe/helix-mediahandler": "2.2.5",
56
56
  "@semantic-release/changelog": "6.0.3",
57
57
  "@semantic-release/exec": "6.0.3",
58
58
  "@semantic-release/git": "10.0.1",
59
59
  "c8": "8.0.0",
60
60
  "dotenv": "16.3.1",
61
- "eslint": "8.44.0",
61
+ "eslint": "8.45.0",
62
62
  "husky": "8.0.3",
63
63
  "junit-report-builder": "3.0.1",
64
64
  "lint-staged": "13.2.3",
@@ -63,13 +63,13 @@ export default function run(h, node, parent, siblings) {
63
63
 
64
64
  let result = nodes;
65
65
  if (node.verticalAlignment === 'superscript') {
66
- result = [h('html', { value: '<sup>' }), ...result, h('html', { value: '</sup>' })];
66
+ result = [h('superscript', result)];
67
67
  }
68
68
  if (node.verticalAlignment === 'subscript') {
69
- result = [h('html', { value: '<sub>' }), ...result, h('html', { value: '</sub>' })];
69
+ result = [h('subscript', result)];
70
70
  }
71
71
  if (node.isUnderline && node.styleId !== 'Hyperlink') {
72
- result = [h('html', { value: '<u>' }), ...result, h('html', { value: '</u>' })];
72
+ result = [h('underline', result)];
73
73
  }
74
74
  if (node.isBold) {
75
75
  result = [h('strong', result)];
@@ -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 toMarkdown from './to-markdown.js';
13
+
14
+ export default function formatPlugin(options) {
15
+ const data = this.data();
16
+
17
+ function add(field, value) {
18
+ /* c8 ignore next 2 */
19
+ if (data[field]) {
20
+ data[field].push(value);
21
+ } else {
22
+ data[field] = [value];
23
+ }
24
+ }
25
+
26
+ // add('micromarkExtensions', syntax(options));
27
+ // add('fromMarkdownExtensions', fromMarkdown(options));
28
+ add('toMarkdownExtensions', toMarkdown(options));
29
+ }
@@ -0,0 +1,51 @@
1
+ /*
2
+ * Copyright 2023 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
+ * Renders special html only format.
14
+ */
15
+ function format(tagName) {
16
+ const tagOpen = `<${tagName}>`;
17
+ const tagClose = `</${tagName}>`;
18
+
19
+ /**
20
+ * @param {Node} node
21
+ * @param {Parents | undefined} _
22
+ * @param {State} state
23
+ * @param {Info} info
24
+ * @returns {string}
25
+ */
26
+ return (node, _, state, info) => {
27
+ const exit = state.enter('html');
28
+ const tracker = state.createTracker(info);
29
+ let value = tracker.move(tagOpen);
30
+ value += tracker.move(
31
+ state.containerPhrasing(node, {
32
+ before: value,
33
+ after: tagOpen,
34
+ ...tracker.current(),
35
+ }),
36
+ );
37
+ value += tracker.move(tagClose);
38
+ exit();
39
+ return value;
40
+ };
41
+ }
42
+
43
+ export default function toMarkdown() {
44
+ return {
45
+ handlers: {
46
+ subscript: format('sub'),
47
+ superscript: format('sup'),
48
+ underline: format('u'),
49
+ },
50
+ };
51
+ }
@@ -26,7 +26,7 @@ import {
26
26
  sanitizeText,
27
27
  sanitizeTextAndFormats,
28
28
  sanitizeLinks,
29
- imageReferences,
29
+ imageReferences, renderHtmlFormats,
30
30
  } from '@adobe/helix-markdown-support';
31
31
  import { remarkMatter } from '@adobe/helix-markdown-support/matter';
32
32
  import remarkGridTable from '@adobe/remark-gridtables';
@@ -34,6 +34,7 @@ import remarkGridTable from '@adobe/remark-gridtables';
34
34
  import processImages from './mdast-process-images.js';
35
35
  import sanitizeAutoEmbeds from './mdast-sanitize-autoembeds.js';
36
36
  import orderedListPlugin from './ordered-list/index.js';
37
+ import formatPlugin from './format-plugin/index.js';
37
38
 
38
39
  /**
39
40
  * Converts the mdast to markdown using common filters suitable for helix.
@@ -61,6 +62,7 @@ export default async function mdast2md(mdast, opts = {}) {
61
62
  ruleSpaces: false,
62
63
  })
63
64
  .use(gfm)
65
+ .use(formatPlugin)
64
66
  .use(remarkMatter)
65
67
  .use(orderedListPlugin);
66
68
 
@@ -81,6 +83,7 @@ export default async function mdast2md(mdast, opts = {}) {
81
83
  await sanitizeFormats(mdast); // collapse formats once
82
84
  await sanitizeLinks(mdast);
83
85
  await sanitizeFormats(mdast); // and again for sanitized links
86
+ await renderHtmlFormats(mdast);
84
87
  await sanitizeText(mdast);
85
88
  await suppressSpaceCode(mdast);
86
89
  await sanitizeAutoEmbeds(mdast);