@adobe/helix-md2jcr 1.1.37 → 1.2.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,17 @@
|
|
|
1
|
+
# [1.2.0](https://github.com/adobe/helix-md2jcr/compare/v1.1.38...v1.2.0) (2025-10-06)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Features
|
|
5
|
+
|
|
6
|
+
* add global CLI command for md2jcr ([4705024](https://github.com/adobe/helix-md2jcr/commit/47050246625b58ea93d23ac8c7fc303edc81998f))
|
|
7
|
+
|
|
8
|
+
## [1.1.38](https://github.com/adobe/helix-md2jcr/compare/v1.1.37...v1.1.38) (2025-10-06)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Bug Fixes
|
|
12
|
+
|
|
13
|
+
* table support ([#157](https://github.com/adobe/helix-md2jcr/issues/157)) ([1815a04](https://github.com/adobe/helix-md2jcr/commit/1815a043a0ed2ae8fbb8c07b007f6354e0ab9edb))
|
|
14
|
+
|
|
1
15
|
## [1.1.37](https://github.com/adobe/helix-md2jcr/compare/v1.1.36...v1.1.37) (2025-09-29)
|
|
2
16
|
|
|
3
17
|
|
package/README.md
CHANGED
|
@@ -16,31 +16,69 @@ npm install
|
|
|
16
16
|
```
|
|
17
17
|
|
|
18
18
|
## Usage
|
|
19
|
+
|
|
20
|
+
### Installation
|
|
21
|
+
|
|
19
22
|
You can install the package via npm:
|
|
20
23
|
|
|
21
24
|
```bash
|
|
22
25
|
npm install @adobe/helix-md2jcr
|
|
23
26
|
```
|
|
24
27
|
|
|
25
|
-
|
|
26
|
-
|
|
28
|
+
Or use it directly with `npx` without installing:
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
npx @adobe/helix-md2jcr path/to/content.md
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
### Converting Markdown to JCR Nodes
|
|
35
|
+
|
|
36
|
+
The package includes a CLI tool `md2jcr` that converts markdown files to JCR XML format.
|
|
37
|
+
|
|
38
|
+
**Basic usage:**
|
|
39
|
+
```bash
|
|
40
|
+
npx @adobe/helix-md2jcr path/to/content.md
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
**Convert a single file:**
|
|
44
|
+
```bash
|
|
45
|
+
md2jcr test/fixtures/simple.md
|
|
46
|
+
```
|
|
27
47
|
|
|
28
|
-
|
|
48
|
+
**Convert all markdown files in a directory:**
|
|
29
49
|
```bash
|
|
30
|
-
|
|
50
|
+
md2jcr test/fixtures/
|
|
31
51
|
```
|
|
32
|
-
|
|
52
|
+
|
|
53
|
+
**View output in console with verbose flag `-v`:**
|
|
33
54
|
```bash
|
|
34
|
-
|
|
55
|
+
md2jcr test/fixtures/simple.md -v
|
|
35
56
|
```
|
|
36
57
|
|
|
37
|
-
|
|
58
|
+
**View decoded XML output with `-v` and `-d` flags:**
|
|
38
59
|
```bash
|
|
39
|
-
|
|
60
|
+
md2jcr test/fixtures/simple.md -v -d
|
|
40
61
|
```
|
|
41
62
|
|
|
42
|
-
The converter will
|
|
43
|
-
|
|
63
|
+
The converter will generate a `.xml` file alongside the markdown file containing the JCR structure. This can be used to check for potential content changes due to conversion.
|
|
64
|
+
|
|
65
|
+
### Programmatic Usage
|
|
66
|
+
|
|
67
|
+
You can also use the library programmatically in your Node.js code:
|
|
68
|
+
|
|
69
|
+
```javascript
|
|
70
|
+
import { md2jcr } from '@adobe/helix-md2jcr';
|
|
71
|
+
|
|
72
|
+
const markdown = '# Hello World\n\nThis is a test.';
|
|
73
|
+
const options = {
|
|
74
|
+
models: [...],
|
|
75
|
+
definition: {...},
|
|
76
|
+
filters: [...]
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
const xml = await md2jcr(markdown, options);
|
|
80
|
+
console.log(xml);
|
|
81
|
+
```
|
|
44
82
|
|
|
45
83
|
## Baseline XML Files
|
|
46
84
|
Running the ./baseline-tests.sh script will detect any md file under test/fixtures and execute the convert2jcr node script.
|
package/baseline-tests.sh
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
1
3
|
/*
|
|
2
|
-
* Copyright
|
|
4
|
+
* Copyright 2024 Adobe. All rights reserved.
|
|
3
5
|
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
6
|
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
7
|
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
@@ -16,7 +18,7 @@ import {
|
|
|
16
18
|
} from 'fs/promises';
|
|
17
19
|
import path from 'path';
|
|
18
20
|
import { decode } from 'entities';
|
|
19
|
-
import { md2jcr } from '../index.js';
|
|
21
|
+
import { md2jcr } from '../src/index.js';
|
|
20
22
|
|
|
21
23
|
/**
|
|
22
24
|
* Read a JSON file. If the file does not exist, return an empty object.
|
package/package.json
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adobe/helix-md2jcr",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "Helix Service that converts markdown to JCR content structure",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"type": "module",
|
|
7
|
+
"bin": {
|
|
8
|
+
"md2jcr": "./bin/md2jcr.js"
|
|
9
|
+
},
|
|
7
10
|
"scripts": {
|
|
8
11
|
"test": "c8 mocha 'test/*.tests.js'",
|
|
9
12
|
"lint": "eslint .",
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
* governing permissions and limitations under the License.
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
|
-
import { getComponentById, getComponentByTitle } from './Definitions.js';
|
|
13
|
+
import { getComponentById, getComponentByTitle, getAllComponents } from './Definitions.js';
|
|
14
14
|
import FieldGroup from './FieldGroup.js';
|
|
15
15
|
|
|
16
16
|
/**
|
|
@@ -99,6 +99,18 @@ class ModelHelper {
|
|
|
99
99
|
this.groups.push({ modelId: filtersModel.id, fieldGroup: new FieldGroup(filtersModel) });
|
|
100
100
|
});
|
|
101
101
|
}
|
|
102
|
+
|
|
103
|
+
// // special case for the table component where the component is dynamically selected
|
|
104
|
+
// // therefore we are going to add all the models that start with 'table-col-'
|
|
105
|
+
// // so that we can find the associated model for each column.
|
|
106
|
+
if (component.name.toLowerCase() === 'table') {
|
|
107
|
+
// add all the models that start with 'table-col-'
|
|
108
|
+
this.models.forEach((m) => {
|
|
109
|
+
if (m.id.startsWith('table-col-')) {
|
|
110
|
+
this.groups.push({ modelId: m.id, fieldGroup: new FieldGroup(m) });
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
}
|
|
102
114
|
}
|
|
103
115
|
|
|
104
116
|
/**
|
|
@@ -112,6 +124,27 @@ class ModelHelper {
|
|
|
112
124
|
// no need to pass the fieldGroup just return the fields in the group
|
|
113
125
|
return (result) ? result.fieldGroup : null;
|
|
114
126
|
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Return the allowed components for the component.
|
|
130
|
+
* @param {Component} component The component.
|
|
131
|
+
* @return {Array<string>} The allowed components.
|
|
132
|
+
*/
|
|
133
|
+
getAllowedComponents(component) {
|
|
134
|
+
const base = this.filters.find((f) => f.id === component.filterId)?.components || [];
|
|
135
|
+
|
|
136
|
+
// special case for the table component where the component is dynamically selected
|
|
137
|
+
// therefore we are going to add all the models that start with 'table-col-'
|
|
138
|
+
// so that we can find the associated model for each column.
|
|
139
|
+
if (component.name.toLowerCase() === 'table') {
|
|
140
|
+
const components = getAllComponents(this.definition);
|
|
141
|
+
components
|
|
142
|
+
.filter((c) => c.id.startsWith('table-col-'))
|
|
143
|
+
.forEach((c) => base.push(c.id));
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
return base;
|
|
147
|
+
}
|
|
115
148
|
}
|
|
116
149
|
|
|
117
150
|
export default ModelHelper;
|
|
@@ -549,7 +549,8 @@ function gridTablePartial(context) {
|
|
|
549
549
|
// 1. In this section attempt to locate the associated model for the block.
|
|
550
550
|
// 2. Trim the mdast nodes to only be relevant for the child block.
|
|
551
551
|
// 3. Then getBlockitems will process the mdast nodes and return the block items.
|
|
552
|
-
const allowedComponents =
|
|
552
|
+
const allowedComponents = modelHelper.getAllowedComponents(component);
|
|
553
|
+
|
|
553
554
|
// collect all rows
|
|
554
555
|
const blockRows = findAll(mdast, (node) => node.type === 'gtRow', true);
|
|
555
556
|
// the fieldGroup (parent model) determines the expected number of rows in the table
|