Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Options passed via unified-engine are not working #35

Closed
4 tasks done
akrawitz opened this issue Dec 13, 2023 · 4 comments
Closed
4 tasks done

Options passed via unified-engine are not working #35

akrawitz opened this issue Dec 13, 2023 · 4 comments
Labels
💪 phase/solved Post is done

Comments

@akrawitz
Copy link

Initial checklist

Affected packages and versions

remark-rehype: 11.0.0; unified-engine: 11.2.0

Link to runnable example

https://codesandbox.io/p/sandbox/remark-rehype-issue-jzrg2s

Steps to reproduce

(I'm running Node 21.2.0 & Yarn 4.0.2, but the sandbox is running 20.9.0 & Yarn 1.22.19 and shows the same issue).

Please use the sandbox linked above.
The markdown input is in in.md.
Run yarn example1 in the sandbox terminal. The code being executed is in example1.js.
The output is written to out1.html.

Since allowDangerousHtml: true is passed to both remark-rehype and rehype-stringify, the raw html in the markdown should appear in the resulting HTML. However, the options are not being handled properly by remark-rehype. This issue is specific to using unified-engine, because it passes an additional parameter with a FileSet to all plugins (https://github.com/unifiedjs/unified-engine/tree/main?tab=readme-ov-file#fileset). This is normally ignored, but remark-rehype has two optional parameters destination and options, so the options are assigned to destination and the FileSet is assigned to options. As a result, line 151 in remark-rehype/lib/index.js ignores the actual options (which are in destination):

return /** @type {HastRoot} */ (toHast(tree, options || destination))

A workaround is shown by yarn example2. The code being executed is in example2.js, and the output is written to out2.html.
The key to the workaround is that I've wrapped remark-rehype in a function call that reassigns the parameters:

(options, fileSet) => { return remarkRehype({}, options, fileSet); }

This works because now the empty object gets assigned to destination and the options get assigned to options. This workaround helps to confirm that the issue is with how options are handled by the combination of unified-engine and remark-rehype.

Expected behavior

In out1.html, the raw HTML from in.md should be included:

<h1>Header 1</h1>
<p>Paragraph 1.</p>
<div>Raw HTML</div>
<h2>Header 2</h2>
<p>Paragraph 2.</p>

Actual behavior

In out1.html, the raw HTML from in.md is not included:

<h1>Header 1</h1>
<p>Paragraph 1.</p>
<h2>Header 2</h2>
<p>Paragraph 2.</p>

Runtime

Other (please specify in steps to reproduce)

Package manager

Other (please specify in steps to reproduce)

OS

Windows

Build and bundle tools

Rollup

@github-actions github-actions bot added 👋 phase/new Post is being triaged automatically 🤞 phase/open Post is being triaged manually and removed 👋 phase/new Post is being triaged automatically labels Dec 13, 2023
@wooorm
Copy link
Member

wooorm commented Dec 14, 2023

Hey!

Ah, right. It could be interesting to see if the previous majors of those plugins had the same problem or not. They had more handling around the parameters.

I’d say for a solution there also needs to be better handling in this project, remark-rehype, around a given file set

@wooorm wooorm added the 👍 phase/yes Post is accepted and can be worked on label Dec 14, 2023
@github-actions github-actions bot removed the 🤞 phase/open Post is being triaged manually label Dec 14, 2023

This comment has been minimized.

@wooorm wooorm closed this as completed in f0cce2d Sep 19, 2024

This comment has been minimized.

@wooorm wooorm added the 💪 phase/solved Post is done label Sep 19, 2024
@github-actions github-actions bot removed the 👍 phase/yes Post is accepted and can be worked on label Sep 19, 2024
@wooorm
Copy link
Member

wooorm commented Sep 19, 2024

Solved in 11.1.1!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
💪 phase/solved Post is done
Development

No branches or pull requests

2 participants