laysent / remark-ruby

Custom syntax for remarkjs, adding ruby (furigana) to markdown.
MIT License
25 stars 7 forks source link

Assertion: expected last token to be open #25

Open jakehwll opened 2 years ago

jakehwll commented 2 years ago

Hi there!

I was looking to use this in my latest project, however I can't seem to get around an issue and wondering perhaps if its because this library is out of date for remark?

See my example code below, using react component all I can seem to get the result to be is Assertion: expected last token to be open. The following only happens upon using the {test}^(test) syntax, else-wise all content renders fine out of unified, remark, rehype.

Am I perhaps calling something wrong?

import { createElement, Fragment } from 'react'

import { unified } from 'unified'
import remarkParse from 'remark-parse'
import remarkRuby from 'remark-ruby'
import remarkStringify from 'remark-stringify'
import remarkRehype from 'remark-rehype'
import rehypeReact from 'rehype-react'

const processor = unified()
  .use(remarkParse)
  .use(remarkRuby)
  .use(remarkRehype)
  .use(remarkStringify)
  .use(rehypeReact, {
    createElement: createElement,
    Fragment: Fragment,
  })

const Markdown = ({ content }: { content: string }) => {
  console.log(processor.parse(content))
  return <></>
}

const Page = ({}: any) => {
  return (
    <article className="mx-5 w-6/12">
      <Markdown content={`test {test}^(test)`} />
    </article>
  )
}
laysent commented 2 years ago

@jakehwll Do you have a demo project for this? Or which remark do you use. I think this plugin is out of date and perhaps need some rewrite to make it work with new version of remark.

jakehwll commented 2 years ago

Found it!

Seems to be an issue between remark-parse at ver. ^10.0.0 rather than ^9.0.0, downgrading this library for the time being has solved the issue. Was good to hear it wasn't me going crazy trying to learn remark 🙂

(Photo evidence).

image

Time to investigate the breaking changes between them!