landakram / remark-wiki-link

Parse and render wiki links.
MIT License
90 stars 15 forks source link

Cannot make it work #11

Closed mkrcah closed 3 years ago

mkrcah commented 3 years ago

Code:

  console.log(
    unified()
      .use(remarkParse)
      .use(remarkGfm)
      .use(remarkWikiLink)
      .use(remarkRehype)
      .use(rehypeStringify)
      .processSync("[[Test page]]").contents
  )

Versions (I'm on remark 13, using wiki-link v1):

{
  "remark": "^13.0.0",
  "remark-parse": "^9.0.0",
  "remark-gfm": "^1.0.0",
  "remark-wiki-link": "^1.0.1",
  "remark-rehype": "^8.0.0",
  "rehype-stringify": "^8.0.0",
  ...
}

outputs

<p>[[Test page]]</p>

What am I missing? Thx

landakram commented 3 years ago

What does the import for remarkWikiLink look like? Note that if you're importing like:

const remarkWikiLink = require('remark-wiki-link');

You need to pass remarkWikiLink.wikiLinkPlugin:

  console.log(
    unified()
      .use(remarkParse)
      .use(remarkGfm)
      .use(remarkWikiLink.wikiLinkPlugin) // <--
      .use(remarkRehype)
      .use(rehypeStringify)
      .processSync("[[Test page]]").contents
  )

Maybe that's your problem? If so, I might just change the import so it exports a default. I didn't because rollup was giving me a warning, but it seems too confusing right now.

mkrcah commented 3 years ago

Thanks for the quick reply. Yes, the import was indeed the problem. This fixed the issue and now it's working:

import { wikiLinkPlugin } from "remark-wiki-link"

I've noticed that unified plugins I have in the current app all using the default export:

import rehypeReact from "rehype-react"
import remarkParse from "remark-parse"
import remarkRehype from "remark-rehype"
import rehypeRaw from "rehype-raw"
import remarkGfm from "remark-gfm"
import rehypeAddClasses from "rehype-add-classes"
import remarkStringify from "remark-stringify"
import rehypeStringify from "rehype-stringify"
import remarkUnlink from "remark-unlink"
import { wikiLinkPlugin } from "remark-wiki-link"

Only the wiki-link-plug does not. Could be an opportunity to make things consistent.

BTW, cool plugin and thanks a lot for the maintenance :) I can now use Obsidian with Wiki-links to edit Markdown blog posts powered by Next.js 🔥

landakram commented 3 years ago

I'll change the import to have a default since it's what everyone expects. I opened https://github.com/landakram/remark-wiki-link/issues/12 to track.

Glad you got it working and that it's helpful for your use-case 🙂 Obsidian is great software, and I love the idea of making wiki-like knowledge graphs public. Closing this one, but do let me know if you run into any other issues.