@adobe/helix-docx2md 1.2.0 → 1.3.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.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,17 @@
1
+ ## [1.3.1](https://github.com/adobe/helix-docx2md/compare/v1.3.0...v1.3.1) (2022-10-29)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * **deps:** update dependency github-slugger to v1.5.0 ([a843e04](https://github.com/adobe/helix-docx2md/commit/a843e04c5b76e141f8f31f56ef1c92f9d8b7fba9))
7
+
8
+ # [1.3.0](https://github.com/adobe/helix-docx2md/compare/v1.2.0...v1.3.0) (2022-10-25)
9
+
10
+
11
+ ### Features
12
+
13
+ * improve bookmark tests ([#141](https://github.com/adobe/helix-docx2md/issues/141)) ([424a5f3](https://github.com/adobe/helix-docx2md/commit/424a5f311f33d2ad3f414ffe204c0b3747d085a5))
14
+
1
15
  # [1.2.0](https://github.com/adobe/helix-docx2md/compare/v1.1.4...v1.2.0) (2022-10-25)
2
16
 
3
17
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adobe/helix-docx2md",
3
- "version": "1.2.0",
3
+ "version": "1.3.1",
4
4
  "description": "Helix library that converts word documents to markdown",
5
5
  "type": "module",
6
6
  "main": "./src/index.js",
@@ -37,7 +37,7 @@
37
37
  "@adobe/helix-shared-process-queue": "1.1.5",
38
38
  "@adobe/mammoth": "1.5.1-bleeding.1",
39
39
  "dirname-filename-esm": "1.1.1",
40
- "github-slugger": "1.4.0",
40
+ "github-slugger": "1.5.0",
41
41
  "mdast-util-to-markdown": "1.3.0",
42
42
  "mdast-util-to-string": "3.1.0",
43
43
  "remark-gfm": "3.0.1",
@@ -50,7 +50,7 @@
50
50
  },
51
51
  "devDependencies": {
52
52
  "@adobe/eslint-config-helix": "1.3.2",
53
- "@adobe/helix-mediahandler": "1.2.12",
53
+ "@adobe/helix-mediahandler": "1.2.13",
54
54
  "@semantic-release/changelog": "6.0.1",
55
55
  "@semantic-release/exec": "6.0.3",
56
56
  "@semantic-release/git": "10.0.1",
@@ -96,25 +96,31 @@ export default async function dast2mdast(tree, opts = {}) {
96
96
  // process bookmarks. note that we _should_ re-slug them after the headings are sanitized in
97
97
  // mdast2md. another option would be to keep the `bookmark` nodes in the mdast and only
98
98
  // process them in mdast2md. but then, the dast2mdast would produce non standard mdast.
99
- let slugger;
100
- for (const bm of Object.values(h.bookmarks)) {
99
+ const bookmarks = Object.values(h.bookmarks);
100
+ if (!bookmarks.length) {
101
+ return mdast;
102
+ }
103
+
104
+ const slugger = new IDSlugger();
105
+ for (const bm of bookmarks) {
101
106
  if (!bm.target) {
102
107
  // eslint-disable-next-line no-continue
103
108
  continue;
104
109
  }
105
- if (!slugger) {
106
- slugger = new IDSlugger();
107
- }
108
110
  // if heading, create an ID from its text
109
111
  if (bm.target.type === 'heading') {
110
112
  const text = toString(bm.target).trim();
111
113
  bm.id = slugger.slug(text || 'heading');
112
114
  bm.target.id = bm.id;
113
- } else {
115
+ } else if (bm.links.length) {
114
116
  // create an anchor node for non-heading bookmarks
115
117
  bm.id = slugger.slug('bookmark');
116
118
  bm.target.type = 'html';
117
119
  bm.target.value = `<a id="${bm.id}"></a>`;
120
+ } else {
121
+ // remove bookmark node if no link is pointing to it
122
+ bm.target.type = 'text';
123
+ bm.target.value = '';
118
124
  }
119
125
  // adjust all links uris to the id
120
126
  for (const link of bm.links) {