eleventy-plugin-asciidoc 3.0.0 → 3.1.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/.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
@@ -33,7 +33,7 @@ module.exports = function (eleventyConfig) {
33
33
  };
34
34
  ```
35
35
 
36
- #### Customize with Options
36
+ ### Customize with Options
37
37
 
38
38
  You can pass options to `convert()` of Asciidoctor.js as second argument in `addPlugin()`. These are the [available options](https://docs.asciidoctor.org/asciidoctor.js/latest/processor/convert-options/).
39
39
 
@@ -50,10 +50,39 @@ module.exports = function (eleventyConfig) {
50
50
  };
51
51
  ```
52
52
 
53
- ##### `base_dir`
53
+ #### `base_dir`
54
54
 
55
55
  The `base_dir` of [convert options](https://docs.asciidoctor.org/asciidoctor.js/latest/processor/convert-options/) is relative to the document. This can be changed using above [options](#customize-with-options).
56
56
 
57
+ #### `extension_registry` (⚠️ deprecated)
58
+
59
+ The convert option `extension_registry` **will not work** as intended from Asciidoctor.js v3.0 onwards.
60
+ The `extension_registry` needs a newly created registry for each conversion.
61
+ Use [the `configure_extension_registry`](#configure_extension_registry) function instead.
62
+
63
+ #### `configure_extension_registry`
64
+
65
+ The `configure_extension_registry` should be a function which accepts a `registry` (instance of `Extensions.Registry`).
66
+ During each file conversion, the function will be called with a new `registry`.
67
+ This `registry` instance can be used to register extensions.
68
+
69
+ ```js
70
+ const eleventyAsciidoc = require("eleventy-plugin-asciidoc");
71
+ const myExtension = require("./my-extension.js");
72
+
73
+ module.exports = function (eleventyConfig) {
74
+ eleventyConfig.addPlugin(eleventyAsciidoc, {
75
+ configure_extension_registry(registry) {
76
+ myExtension.register(registry);
77
+ // Or, myExtension(registry) depending on how
78
+ // you have programmed your extension.
79
+ },
80
+ });
81
+ };
82
+ ```
83
+
84
+ Refer to [Asciidoctor.js documentation](https://docs.asciidoctor.org/asciidoctor.js/latest/extend/extensions/) to know more about extensions.
85
+
57
86
  ### CSS Styles
58
87
 
59
88
  The plugin does not include any CSS styles. It is up to you to style the content.
@@ -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");
@@ -11,7 +11,7 @@ const nunjucks = require("nunjucks");
11
11
  // @ts-ignore
12
12
  const processor = asciidoctor();
13
13
 
14
- /** @typedef {import('asciidoctor').ProcessorOptions} ProcessorOptions */
14
+ /** @typedef {import('@asciidoctor/core').ProcessorOptions} ProcessorOptions */
15
15
  /** @typedef {import('gray-matter').GrayMatterFile} GrayMatterFile */
16
16
 
17
17
  /**
@@ -70,13 +70,25 @@ function eleventyAsciidoctor(convertOptions = {}) {
70
70
  debug(`Reading ${inputPath}`);
71
71
  const { content } = readFileSync(inputPath);
72
72
 
73
- let { base_dir } = options;
73
+ let { base_dir, configure_extension_registry } = options;
74
74
  base_dir = base_dir === undefined ? path.dirname(inputPath) : base_dir;
75
75
 
76
76
  if (content) {
77
77
  debug(`Converting:\n ${content}`);
78
78
  debug(`base_dir: ${base_dir}`);
79
- return processor.convert(content, { ...options, base_dir });
79
+
80
+ let registry;
81
+ if (typeof configure_extension_registry === "function") {
82
+ debug(`Creating an extension registry`);
83
+ registry = processor.Extensions.create();
84
+ configure_extension_registry(registry);
85
+ }
86
+
87
+ return processor.convert(content, {
88
+ ...options,
89
+ base_dir,
90
+ extension_registry: registry,
91
+ });
80
92
  }
81
93
  };
82
94
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eleventy-plugin-asciidoc",
3
- "version": "3.0.0",
3
+ "version": "3.1.0",
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.44.0",
33
- "eslint-config-prettier": "^8.8.0",
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-alpha.1",
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": [