-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Adds new option, configure_extension_registry
This can be use instead of Asciidoctor's 'extension_registry' option. 'configure_extension_registry' will create new registry for each file conversion. Fixes #10
- Loading branch information
Showing
8 changed files
with
101 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
const test = require("ava").default; | ||
const Eleventy = require("@11ty/eleventy"); | ||
|
||
test("Render with shout extension", async (t) => { | ||
const elev = new Eleventy( | ||
"./tests/fixtures/extensions/src", | ||
"./tests/fixtures/extensions/_site", | ||
{ | ||
configPath: "./tests/fixtures/extensions/.eleventy.js", | ||
}, | ||
); | ||
const json = await elev.toJSON(); | ||
|
||
// Here two pages are checked because, from asciidoctor.js v3 | ||
// onwards registry can only be used on one convert. Unless, | ||
// a fresh registry is passed, in the subsequent convert call | ||
// the content won't be processed with the extensions. | ||
// See: https://github.com/asciidoctor/asciidoctor.js/issues/1709 | ||
t.is(json.length, 2); | ||
|
||
const page1 = json.find((d) => d.inputPath.endsWith("index.adoc")); | ||
t.is( | ||
page1.content.trim(), | ||
`<div class="paragraph"> | ||
<p>IF IT ALL WORKS, THIS TEXT SHOULD BE IN UPPER CASE.</p> | ||
</div>`, | ||
); | ||
|
||
const page2 = json.find((d) => d.inputPath.endsWith("another-page.adoc")); | ||
t.is( | ||
page2.content.trim(), | ||
`<div class="paragraph"> | ||
<p>IF IT ALL WORKS, THIS TEXT SHOULD ALSO BE IN UPPER CASE.</p> | ||
</div>`, | ||
); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/* eslint camelcase: ["error", {allow: ["configure_extension_registry"]}] */ | ||
|
||
const eleventyAsciidoc = require("../../../"); | ||
const shout = require("./shout.js"); | ||
|
||
module.exports = function (eleventyConfig) { | ||
eleventyConfig.addPlugin(eleventyAsciidoc, { | ||
configure_extension_registry(registry) { | ||
shout.register(registry); | ||
}, | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
function shout() { | ||
const self = this; | ||
self.named("shout"); | ||
self.onContext("paragraph"); | ||
self.process(function (parent, reader) { | ||
const lines = reader.getLines().map((l) => l.toUpperCase()); | ||
return self.createBlock(parent, "paragraph", lines); | ||
}); | ||
} | ||
|
||
function register(registry) { | ||
if (typeof registry.register === "function") { | ||
registry.register(function () { | ||
this.block(shout); | ||
}); | ||
} else if (typeof registry.block === "function") { | ||
registry.block(shout); | ||
} | ||
|
||
return registry; | ||
} | ||
|
||
module.exports = { register }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
= A Second Test Document for Asciidoc Extensions | ||
|
||
[shout] | ||
If it all works, this text should also be in upper case. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
= Test Document for Asciidoc Extensions | ||
|
||
[shout] | ||
If it all works, this text should be in upper case. |