@adobe/helix-md2jcr 1.0.0 → 1.0.3
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 +21 -0
- package/README.md +34 -5
- package/baseline-tests.sh +41 -8
- package/package.json +1 -1
- package/src/cli/convert2jcr.js +13 -6
- package/src/mdast2jcr/index.js +0 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,24 @@
|
|
|
1
|
+
## [1.0.3](https://github.com/adobe/helix-md2jcr/compare/v1.0.2...v1.0.3) (2025-01-28)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* remove private ([#39](https://github.com/adobe/helix-md2jcr/issues/39)) ([1358e6d](https://github.com/adobe/helix-md2jcr/commit/1358e6dda7950a25d4b8a99bb5e4fbbf87b4c0d5))
|
|
7
|
+
|
|
8
|
+
## [1.0.2](https://github.com/adobe/helix-md2jcr/compare/v1.0.1...v1.0.2) (2025-01-28)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Bug Fixes
|
|
12
|
+
|
|
13
|
+
* update docs for release ([#38](https://github.com/adobe/helix-md2jcr/issues/38)) ([223a94e](https://github.com/adobe/helix-md2jcr/commit/223a94e92b76eaa86d7fce670c4cec6ffed6065a))
|
|
14
|
+
|
|
15
|
+
## [1.0.1](https://github.com/adobe/helix-md2jcr/compare/v1.0.0...v1.0.1) (2025-01-28)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
### Bug Fixes
|
|
19
|
+
|
|
20
|
+
* update readme ([#37](https://github.com/adobe/helix-md2jcr/issues/37)) ([ae4ab74](https://github.com/adobe/helix-md2jcr/commit/ae4ab740a7629ad9a3c99da99ef3520304fe9032))
|
|
21
|
+
|
|
1
22
|
# 1.0.0 (2025-01-28)
|
|
2
23
|
|
|
3
24
|
|
package/README.md
CHANGED
|
@@ -8,20 +8,49 @@
|
|
|
8
8
|
[](https://github.com/adobe/helix-md2jcr/issues)
|
|
9
9
|
[](https://github.com/semantic-release/semantic-release)
|
|
10
10
|
|
|
11
|
-
##
|
|
11
|
+
## Development
|
|
12
|
+
Install all dependencies by running:
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
npm install
|
|
16
|
+
```
|
|
12
17
|
|
|
13
18
|
## Usage
|
|
19
|
+
You can install the package via npm:
|
|
14
20
|
|
|
15
21
|
```bash
|
|
16
22
|
npm install @adobe/helix-md2jcr
|
|
17
23
|
```
|
|
18
24
|
|
|
19
|
-
## Converting Markdown to JCR
|
|
25
|
+
## Converting Markdown to JCR Nodes
|
|
26
|
+
Running the following command will generate an XML file with the JCR structure alongside of the input file.
|
|
20
27
|
|
|
21
|
-
|
|
28
|
+
For example generating xml for the simple.md file, run:
|
|
29
|
+
```bash
|
|
30
|
+
node ./src/cli/convert2jcr.js test/fixtures/simple.md
|
|
31
|
+
```
|
|
32
|
+
If you wish to see the output in the console, you can run the following command with the verbose flag -v
|
|
33
|
+
```bash
|
|
34
|
+
node ./src/cli/convert2jcr.js test/fixtures/simple.md -v
|
|
35
|
+
```
|
|
22
36
|
|
|
37
|
+
If you wish to see the decoded output in the console you can run the following command with the verbose and decode flags -v and -d:
|
|
23
38
|
```bash
|
|
24
|
-
node ./src/cli/convert2jcr.js
|
|
39
|
+
node ./src/cli/convert2jcr.js test/fixtures/simple.md -v -d
|
|
25
40
|
```
|
|
26
41
|
|
|
27
|
-
The converter will produce a `.xml`
|
|
42
|
+
The converter will produce a `.xml` which is the generated document converted
|
|
43
|
+
from markdown. This can be used to check for potential content changes due to conversion.
|
|
44
|
+
|
|
45
|
+
## Baseline XML Files
|
|
46
|
+
Running the ./baseline-tests.sh script will detect any md file under test/fixtures and execute the convert2jcr node script.
|
|
47
|
+
The script will generate new xml files beside the md files it locates. This is helpful when making changes to the converter
|
|
48
|
+
and you want to see if the changes have any impact on the output. By using git diff, you will see the new changes in the xml files.
|
|
49
|
+
If you are satisfied with the changes, you can commit the new xml files.
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
## Running Tests
|
|
53
|
+
Simply execute the following command to run the tests:
|
|
54
|
+
```bash
|
|
55
|
+
npm test
|
|
56
|
+
```
|
package/baseline-tests.sh
CHANGED
|
@@ -1,5 +1,34 @@
|
|
|
1
1
|
#!/bin/bash
|
|
2
2
|
|
|
3
|
+
# create a function that prints the usage of the script
|
|
4
|
+
usage() {
|
|
5
|
+
echo "Usage: $0 [-v] [-d]"
|
|
6
|
+
echo " -v: Verbose mode"
|
|
7
|
+
echo " -d: Decode output mode"
|
|
8
|
+
exit 1
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
# verify that the command arguments are only -v or -d if any other commands are found exit with an error. If -d is present but -v is not present, exit with an error.
|
|
12
|
+
while getopts ":vd" opt; do
|
|
13
|
+
case ${opt} in
|
|
14
|
+
v )
|
|
15
|
+
VERBOSE="true"
|
|
16
|
+
;;
|
|
17
|
+
d )
|
|
18
|
+
DECODE="true"
|
|
19
|
+
;;
|
|
20
|
+
\? )
|
|
21
|
+
echo "Invalid option: $OPTARG" 1>&2
|
|
22
|
+
usage
|
|
23
|
+
;;
|
|
24
|
+
: )
|
|
25
|
+
echo "Invalid option: $OPTARG requires an argument" 1>&2
|
|
26
|
+
usage
|
|
27
|
+
;;
|
|
28
|
+
esac
|
|
29
|
+
done
|
|
30
|
+
|
|
31
|
+
|
|
3
32
|
# Set the root directory to search for .md files
|
|
4
33
|
MD_DIR="test/fixtures"
|
|
5
34
|
|
|
@@ -21,19 +50,22 @@ if [ -z "$MD_FILES" ]; then
|
|
|
21
50
|
exit 1
|
|
22
51
|
fi
|
|
23
52
|
|
|
53
|
+
ARGS=""
|
|
54
|
+
[ "$VERBOSE" = "true" ] && ARGS="$ARGS -v"
|
|
55
|
+
[ "$DECODE" = "true" ] && ARGS="$ARGS -d"
|
|
56
|
+
|
|
24
57
|
# Iterate over each .md file
|
|
25
58
|
for MD_FILE in $MD_FILES; do
|
|
59
|
+
# if VERBOSE is true then echo a new line
|
|
60
|
+
[ "$VERBOSE" = "true" ] && echo
|
|
61
|
+
|
|
26
62
|
# Execute the Node.js script with the .md file as an argument
|
|
27
|
-
echo "*******************************************************************************"
|
|
28
63
|
echo "Processing $MD_FILE..."
|
|
29
|
-
echo "*******************************************************************************"
|
|
30
|
-
echo ""
|
|
31
64
|
|
|
32
|
-
if
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
fi
|
|
65
|
+
# if VERBOSE is true then echo a new line
|
|
66
|
+
[ "$VERBOSE" = "true" ] && echo
|
|
67
|
+
|
|
68
|
+
node "$NODE_SCRIPT" "$MD_FILE" $ARGS
|
|
37
69
|
|
|
38
70
|
# Check if the Node.js script executed successfully
|
|
39
71
|
if [ $? -ne 0 ]; then
|
|
@@ -42,4 +74,5 @@ for MD_FILE in $MD_FILES; do
|
|
|
42
74
|
fi
|
|
43
75
|
done
|
|
44
76
|
|
|
77
|
+
|
|
45
78
|
echo "All .md files have been processed successfully."
|
package/package.json
CHANGED
package/src/cli/convert2jcr.js
CHANGED
|
@@ -39,11 +39,12 @@ async function readJsonFile(filePath) {
|
|
|
39
39
|
/**
|
|
40
40
|
* Convert a markdown file to JCR XML.
|
|
41
41
|
* @param mdFile {string} The path to the markdown file.
|
|
42
|
+
* @param verbose - if true the XML will be printed to the console.
|
|
42
43
|
* @param decodeXML - if true a file with the decoded XML will be created.
|
|
43
44
|
* @returns {Promise<void>} A promise that resolves when the conversion is
|
|
44
45
|
* complete, or rejects if the file is not a markdown file.
|
|
45
46
|
*/
|
|
46
|
-
async function convert(mdFile, decodeXML = false) {
|
|
47
|
+
async function convert(mdFile, verbose = false, decodeXML = false) {
|
|
47
48
|
if (!mdFile.endsWith('.md')) {
|
|
48
49
|
return Promise.reject(new Error('File must be a markdown file'));
|
|
49
50
|
}
|
|
@@ -51,7 +52,6 @@ async function convert(mdFile, decodeXML = false) {
|
|
|
51
52
|
const dir = path.dirname(mdFile);
|
|
52
53
|
const base = path.basename(mdFile, '.md');
|
|
53
54
|
const fileJcrXML = path.resolve(dir, `${base}.xml`);
|
|
54
|
-
const decodedXML = path.resolve(dir, `${base}-decoded.xml`);
|
|
55
55
|
|
|
56
56
|
let modelJson;
|
|
57
57
|
let definitionJson;
|
|
@@ -96,8 +96,12 @@ async function convert(mdFile, decodeXML = false) {
|
|
|
96
96
|
|
|
97
97
|
const xml = await md2jcr(md, opts);
|
|
98
98
|
|
|
99
|
-
if (
|
|
100
|
-
|
|
99
|
+
if (verbose) {
|
|
100
|
+
if (!decodeXML) {
|
|
101
|
+
console.log(xml);
|
|
102
|
+
} else if (decodeXML) {
|
|
103
|
+
console.log(decode(xml));
|
|
104
|
+
}
|
|
101
105
|
}
|
|
102
106
|
|
|
103
107
|
return writeFile(fileJcrXML, xml);
|
|
@@ -115,13 +119,16 @@ async function run(inPath) {
|
|
|
115
119
|
|
|
116
120
|
const files = [];
|
|
117
121
|
if ((await stat(dirOrFilePath)).isDirectory()) {
|
|
118
|
-
|
|
122
|
+
const items = await readdir(dirOrFilePath);
|
|
123
|
+
items
|
|
124
|
+
.filter((item) => item.endsWith('.md'))
|
|
125
|
+
.forEach((item) => files.push(path.resolve(dirOrFilePath, item)));
|
|
119
126
|
} else {
|
|
120
127
|
files.push(dirOrFilePath);
|
|
121
128
|
}
|
|
122
129
|
|
|
123
130
|
for (const file of files) {
|
|
124
|
-
await convert(file, process.argv.includes('-d'));
|
|
131
|
+
await convert(file, process.argv.includes('-v'), process.argv.includes('-d'));
|
|
125
132
|
}
|
|
126
133
|
}
|
|
127
134
|
|