-
-
Notifications
You must be signed in to change notification settings - Fork 125
Closed
Labels
Description
Cannot use the same plugin multiple times in a processor
I have a use case where I want to apply the same plugin twice in a processor which doesn't seem to work
Steps to reproduce
Here's a simple example that uses rehype-format twice. Only the first use seems to succeed:
const unified = require("unified");
const rehypeParse = require("rehype-parse");
const rehypeFormat = require("rehype-format");
const rehypeDocument = require("rehype-document");
const rehypeStringify = require("rehype-stringify");
const processor = unified()
.use(rehypeParse, { fragment: true })
.use(rehypeFormat)
.use(rehypeDocument)
.use(rehypeFormat)
.use(rehypeStringify);
const input = "<div><h1>hello world</h1></div>";
const output = processor.processSync(input).toString();
console.log(output);this produces the following output:
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<div>
<h1>hello world</h1>
</div>
</body>
</html>note that the original content was formatted, but the rest was not - the second pass of formatting did not occur
The same behavior occurs with other plugins
Expected behavior
Allow plugins to be used multiple times
If that's not possible, it would be nice if attempting to use a plugin more than once threw an error
Alternatively, this should at least be documented with possible workarounds (I didn't find documentation on this)
Reactions are currently unavailable