markup-it icon indicating copy to clipboard operation
markup-it copied to clipboard

Example from documentation crashes with TypeError

Open tolmasky opened this issue 6 years ago • 4 comments

This example currently breaks with

TypeError: Expected Array or iterable object of values: [object Object]

RunKit Link showing full stack trace

const { State } = require('markup-it');
const markdown = require('markup-it/lib/markdown');

const state = State.create(markdown);
const document = state.deserializeToDocument('Hello **World**');

I've tried with [email protected] and [email protected], and @gitbook/[email protected] and @gitbook/[email protected].

tolmasky avatar Dec 01 '18 21:12 tolmasky

the same to me, any updates? @tolmasky

tageecc avatar Dec 11 '18 11:12 tageecc

I've not gotten it to work. Sticking with remark for now, but want to eventually switch to markup-it for template support.

tolmasky avatar Dec 12 '18 20:12 tolmasky

Hi, I would like to try this compiler (and then add support for textile (JIRA format)). But I got stuck on this error. Is there any progress? @Soreine

MartinSadovy avatar Mar 01 '19 16:03 MartinSadovy

@tolmasky Indeed, it doesn't work.

markup-it/lib/markdown is using ES6 Modules:

import block from './blocks';
import inline from './inlines';
import document from './document';

export default {
    document: [document],
    inline,
    block
};

Once converted by Babel into CommonJS, the exported object becomes:

{
   "default": {
      "document": ...,
      "inline": ...,
      "block": ...
   }
}

So, in order to make it works you can either replace State.create(markdown) by State.create(markdown.default) or use ES6 modules:

import { State } from 'markup-it'
import markdown from 'markup-it/lib/markdown'
import { Map, List } from 'immutable'

const state = State.create(markdown);
const doc = state.deserializeToDocument('Hello **World**');

jspdown avatar Apr 24 '19 13:04 jspdown