eleventy-plugin-asciidoc 3.0.1 → 3.1.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/.eleventy.js +16 -0
- package/README.md +45 -6
- package/lib/eleventy-asciidoc.js +33 -4
- package/lib/utils.js +25 -0
- package/package.json +11 -6
package/.eleventy.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
// @ts-check
|
|
1
2
|
const eleventyAsciidoc = require("./lib/eleventy-asciidoc.js");
|
|
3
|
+
const pkg = require("./package.json");
|
|
2
4
|
|
|
3
5
|
/** @typedef {import('./lib/eleventy-asciidoc.js').ProcessorOptions} ProcessorOptions} */
|
|
4
6
|
|
|
@@ -10,6 +12,20 @@ module.exports = {
|
|
|
10
12
|
* @param {ProcessorOptions} converterOptions Options for Asciidoctor.converter()
|
|
11
13
|
*/
|
|
12
14
|
configFunction(eleventyConfig, converterOptions) {
|
|
15
|
+
try {
|
|
16
|
+
eleventyConfig.versionCheck(pkg["11ty"].compatibility);
|
|
17
|
+
} catch (e) {
|
|
18
|
+
console.log(
|
|
19
|
+
`WARN: Eleventy Plugin (${pkg.name}) Compatibility: ${e.message}`,
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
if (converterOptions?.extension_registry !== undefined) {
|
|
24
|
+
console.log(
|
|
25
|
+
`WARN: 'extension_registry' doesn't work well with Asciidoctor.js v3+. Use 'configure_extension_registry'.`,
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
|
|
13
29
|
eleventyConfig.addTemplateFormats("adoc");
|
|
14
30
|
eleventyConfig.addExtension("adoc", eleventyAsciidoc(converterOptions));
|
|
15
31
|
},
|
package/README.md
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
# eleventy-plugin-asciidoc
|
|
2
2
|
|
|
3
|
-
Eleventy plugin to add support for [AsciiDoc](https://asciidoc.org/).
|
|
3
|
+
Eleventy plugin to add support for [AsciiDoc](https://asciidoc.org/).
|
|
4
|
+
You don't need to use to shortcodes.
|
|
5
|
+
You can directly use AsciiDoc files (`.adoc`), just like Markdown (`.md`).
|
|
4
6
|
|
|
5
7
|
The plugin uses [Asciidoctor.js](https://docs.asciidoctor.org/asciidoctor.js) under the hood.
|
|
6
8
|
|
|
@@ -33,9 +35,10 @@ module.exports = function (eleventyConfig) {
|
|
|
33
35
|
};
|
|
34
36
|
```
|
|
35
37
|
|
|
36
|
-
|
|
38
|
+
### Customize with Options
|
|
37
39
|
|
|
38
|
-
You can pass options to `convert()` of Asciidoctor.js as second argument in `addPlugin()`.
|
|
40
|
+
You can pass options to `convert()` of Asciidoctor.js as second argument in `addPlugin()`.
|
|
41
|
+
These are the [available options](https://docs.asciidoctor.org/asciidoctor.js/latest/processor/convert-options/).
|
|
39
42
|
|
|
40
43
|
```js
|
|
41
44
|
const eleventyAsciidoc = require("eleventy-plugin-asciidoc");
|
|
@@ -50,15 +53,51 @@ module.exports = function (eleventyConfig) {
|
|
|
50
53
|
};
|
|
51
54
|
```
|
|
52
55
|
|
|
53
|
-
|
|
56
|
+
#### `base_dir`
|
|
54
57
|
|
|
55
|
-
The `base_dir` of [convert options](https://docs.asciidoctor.org/asciidoctor.js/latest/processor/convert-options/) is relative to the document.
|
|
58
|
+
The `base_dir` of [convert options](https://docs.asciidoctor.org/asciidoctor.js/latest/processor/convert-options/) is relative to the document.
|
|
59
|
+
This can be changed using above [options](#customize-with-options).
|
|
60
|
+
|
|
61
|
+
#### `attributes.outdir`
|
|
62
|
+
|
|
63
|
+
By default, [`attributes.outdir`](https://docs.asciidoctor.org/asciidoc/latest/attributes/document-attributes-ref/#intrinsic-attributes) will output directory (`permalink`) of the document.
|
|
64
|
+
This can be changed using above [options](#customize-with-options).
|
|
65
|
+
|
|
66
|
+
#### `extension_registry` (⚠️ deprecated)
|
|
67
|
+
|
|
68
|
+
The convert option `extension_registry` **will not work** as intended from Asciidoctor.js v3.0 onwards.
|
|
69
|
+
The `extension_registry` needs a newly created registry for each conversion.
|
|
70
|
+
Use [the `configure_extension_registry`](#configure_extension_registry) function instead.
|
|
71
|
+
|
|
72
|
+
#### `configure_extension_registry`
|
|
73
|
+
|
|
74
|
+
The `configure_extension_registry` should be a function which accepts a `registry` (instance of `Extensions.Registry`).
|
|
75
|
+
During each file conversion, the function will be called with a new `registry`.
|
|
76
|
+
This `registry` instance can be used to register extensions.
|
|
77
|
+
|
|
78
|
+
```js
|
|
79
|
+
const eleventyAsciidoc = require("eleventy-plugin-asciidoc");
|
|
80
|
+
const myExtension = require("./my-extension.js");
|
|
81
|
+
|
|
82
|
+
module.exports = function (eleventyConfig) {
|
|
83
|
+
eleventyConfig.addPlugin(eleventyAsciidoc, {
|
|
84
|
+
configure_extension_registry(registry) {
|
|
85
|
+
myExtension.register(registry);
|
|
86
|
+
// Or, myExtension(registry) depending on how
|
|
87
|
+
// you have programmed your extension.
|
|
88
|
+
},
|
|
89
|
+
});
|
|
90
|
+
};
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
Refer to [Asciidoctor.js documentation](https://docs.asciidoctor.org/asciidoctor.js/latest/extend/extensions/) to know more about extensions.
|
|
56
94
|
|
|
57
95
|
### CSS Styles
|
|
58
96
|
|
|
59
97
|
The plugin does not include any CSS styles. It is up to you to style the content.
|
|
60
98
|
|
|
61
|
-
The
|
|
99
|
+
The quickest way to style the content is to use the CSS file from Asciidoctor.js.
|
|
100
|
+
The CSS file is [available on cdnjs](https://cdnjs.com/libraries/asciidoctor.js).
|
|
62
101
|
|
|
63
102
|
## Enhancements
|
|
64
103
|
|
package/lib/eleventy-asciidoc.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// @ts-check
|
|
2
|
-
/* eslint camelcase: ["error", {allow: ["base_dir"]}] */
|
|
2
|
+
/* eslint camelcase: ["error", {allow: ["base_dir", "extension_registry", "configure_extension_registry"]}] */
|
|
3
3
|
|
|
4
4
|
const asciidoctor = require("@asciidoctor/core");
|
|
5
5
|
const debug = require("debug")("eleventy-plugin-asciidoc");
|
|
@@ -7,11 +7,12 @@ const fs = require("fs");
|
|
|
7
7
|
const matter = require("gray-matter");
|
|
8
8
|
const path = require("path");
|
|
9
9
|
const nunjucks = require("nunjucks");
|
|
10
|
+
const { parseDocumentAttributes } = require("./utils.js");
|
|
10
11
|
|
|
11
12
|
// @ts-ignore
|
|
12
13
|
const processor = asciidoctor();
|
|
13
14
|
|
|
14
|
-
/** @typedef {import('asciidoctor').ProcessorOptions} ProcessorOptions */
|
|
15
|
+
/** @typedef {import('@asciidoctor/core').ProcessorOptions} ProcessorOptions */
|
|
15
16
|
/** @typedef {import('gray-matter').GrayMatterFile} GrayMatterFile */
|
|
16
17
|
|
|
17
18
|
/**
|
|
@@ -70,13 +71,41 @@ function eleventyAsciidoctor(convertOptions = {}) {
|
|
|
70
71
|
debug(`Reading ${inputPath}`);
|
|
71
72
|
const { content } = readFileSync(inputPath);
|
|
72
73
|
|
|
73
|
-
let { base_dir } = options;
|
|
74
|
+
let { base_dir, configure_extension_registry } = options;
|
|
75
|
+
const attributes = parseDocumentAttributes(options.attributes ?? {});
|
|
76
|
+
let { outdir } = attributes;
|
|
77
|
+
|
|
74
78
|
base_dir = base_dir === undefined ? path.dirname(inputPath) : base_dir;
|
|
75
79
|
|
|
80
|
+
if (outdir === undefined) {
|
|
81
|
+
const { page } = data ?? {};
|
|
82
|
+
const { outputPath } = page ?? {};
|
|
83
|
+
if (outputPath !== undefined) {
|
|
84
|
+
outdir = path.dirname(outputPath);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
76
88
|
if (content) {
|
|
77
89
|
debug(`Converting:\n ${content}`);
|
|
78
90
|
debug(`base_dir: ${base_dir}`);
|
|
79
|
-
|
|
91
|
+
debug(`attributes:\n ${JSON.stringify(attributes)}`);
|
|
92
|
+
|
|
93
|
+
let registry;
|
|
94
|
+
if (typeof configure_extension_registry === "function") {
|
|
95
|
+
debug(`Creating an extension registry`);
|
|
96
|
+
registry = processor.Extensions.create();
|
|
97
|
+
configure_extension_registry(registry);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
return processor.convert(content, {
|
|
101
|
+
...options,
|
|
102
|
+
attributes: {
|
|
103
|
+
...attributes,
|
|
104
|
+
outdir,
|
|
105
|
+
},
|
|
106
|
+
base_dir,
|
|
107
|
+
extension_registry: registry,
|
|
108
|
+
});
|
|
80
109
|
}
|
|
81
110
|
};
|
|
82
111
|
|
package/lib/utils.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
3
|
+
/** @typedef {import('@asciidoctor/core').Attributes} Attributes */
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Parses AsciiDoc Document attributes into object
|
|
7
|
+
*
|
|
8
|
+
* @param {Attributes | string[] | string} attrs AsciiDoc Document Attributes
|
|
9
|
+
* @return {Attributes} Attributes as Object
|
|
10
|
+
*/
|
|
11
|
+
function parseDocumentAttributes(attrs) {
|
|
12
|
+
if (Array.isArray(attrs)) {
|
|
13
|
+
return Object.fromEntries(attrs.map((a) => a.split("=")));
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
if (typeof attrs === "string") {
|
|
17
|
+
return Object.fromEntries([attrs.split("=")]);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
return attrs;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
module.exports = {
|
|
24
|
+
parseDocumentAttributes,
|
|
25
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eleventy-plugin-asciidoc",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.1.1",
|
|
4
4
|
"description": "Adds support for AsciiDoc to Eleventy",
|
|
5
5
|
"main": ".eleventy.js",
|
|
6
6
|
"repository": {
|
|
@@ -21,18 +21,22 @@
|
|
|
21
21
|
],
|
|
22
22
|
"author": "Saneef Ansari <hello@saneef.com> (https://saneef.com/)",
|
|
23
23
|
"license": "MIT",
|
|
24
|
+
"11ty": {
|
|
25
|
+
"compatibility": ">=1.0.0"
|
|
26
|
+
},
|
|
24
27
|
"dependencies": {
|
|
25
|
-
"asciidoctor": "^3.0.2",
|
|
28
|
+
"@asciidoctor/core": "^3.0.2",
|
|
26
29
|
"debug": "^4.3.4",
|
|
27
30
|
"gray-matter": "^4.0.3",
|
|
28
31
|
"nunjucks": "^3.2.4"
|
|
29
32
|
},
|
|
30
33
|
"devDependencies": {
|
|
34
|
+
"@11ty/eleventy": "^2.0.1",
|
|
31
35
|
"ava": "^5.3.1",
|
|
32
|
-
"eslint": "^8.
|
|
33
|
-
"eslint-config-prettier": "^8.
|
|
36
|
+
"eslint": "^8.45.0",
|
|
37
|
+
"eslint-config-prettier": "^8.9.0",
|
|
34
38
|
"eslint-config-xo-space": "^0.34.0",
|
|
35
|
-
"eslint-plugin-prettier": "^5.0.0
|
|
39
|
+
"eslint-plugin-prettier": "^5.0.0",
|
|
36
40
|
"husky": "^8.0.3",
|
|
37
41
|
"lint-staged": "^13.2.3",
|
|
38
42
|
"nyc": "^15.1.0",
|
|
@@ -40,12 +44,13 @@
|
|
|
40
44
|
"rimraf": "^5.0.1"
|
|
41
45
|
},
|
|
42
46
|
"lint-staged": {
|
|
43
|
-
"*.js": "eslint --cache --fix",
|
|
47
|
+
"*.js": "eslint --cache --fix --ignore-pattern \"!.eleventy.js\"",
|
|
44
48
|
"*.{js,md,json}": "prettier --write"
|
|
45
49
|
},
|
|
46
50
|
"ava": {
|
|
47
51
|
"files": [
|
|
48
52
|
"tests/**/*",
|
|
53
|
+
"!tests/fixtures/",
|
|
49
54
|
"!tests/utils.js"
|
|
50
55
|
],
|
|
51
56
|
"ignoredByWatcher": [
|