remarkjs / remark-unwrap-images

Deprecated: use `rehype-unwrap-images` instead
73 stars 5 forks source link

The plugin produces invalid AST #9

Closed marekdedic closed 1 year ago

marekdedic commented 1 year ago

Initial checklist

Affected packages and versions

3.0.1

Link to runnable example

No response

Steps to reproduce

import { unified } from "https://cdn.jsdelivr.net/npm/unified@10.1.2/+esm";
import remarkParse from "https://cdn.jsdelivr.net/npm/remark-parse@10.0.1/+esm";
import remarkUnwrapImages from "https://cdn.jsdelivr.net/npm/remark-unwrap-images@3.0.1/+esm";

const sourceMarkdown =
  '![Minion](https://octodex.github.com/images/minion.png)\n![Stormtroopocat](https://octodex.github.com/images/stormtroopocat.jpg "The Stormtroopocat")\n\n';

async function main() {
  document.querySelector("#source").textContent = sourceMarkdown;

  const remark = unified().use(remarkParse).use(remarkUnwrapImages)

  const file = remark.runSync(remark.parse(sourceMarkdown));

  document.querySelector("#result").textContent = JSON.stringify(file, undefined, 2);
  document.querySelector("#error").textContent = "";
}

main().catch((error) => {
  document.querySelector("#error").textContent = error;
});

I would link a codesandbox, but I couldn't figure out how to actually run the code I put in - there is no "run" button anywhere :shrug:

Expected behavior

The AST should be something like

or

Actual behavior

The ASP look like

i.e., it places Text directly in Root, which is prohibited in mdast as per the content model

Runtime

Other (please specify in steps to reproduce)

Package manager

npm 8

OS

Linux

Build and bundle tools

Webpack

wooorm commented 1 year ago

Why do you believe image can be there? And text can't?

Yes: the entire project produces "invalid" ASTs. Images are not supposed to be next to paragraphs.

This project is very old. It's probably better to make a rehype version of this and depreciate it.

marekdedic commented 1 year ago

Hmm, that's actually an excellent point, thanks. I solve the issue by not using this plugin at all :D

github-actions[bot] commented 1 year ago

Hi! This was closed. Team: If this was fixed, please add phase/solved. Otherwise, please add one of the no/* labels.

github-actions[bot] commented 1 year ago

Hi team! Could you describe why this has been marked as wontfix?

Thanks, — bb