adobe / mdast-util-gridtables

mdast extension to parse and serialize gridtables
Apache License 2.0
2 stars 3 forks source link

The example Code is Out-of-Date / not working - Suggested update is enclosed #33

Closed smuchow1962 closed 1 year ago

smuchow1962 commented 1 year ago

The sample code has a number of issues and there have been changes to unified I reworked the example a little to achieve a working result.

import fs from "node:fs/promises"
import { fromMarkdown } from "mdast-util-from-markdown"
import { toMarkdown } from "mdast-util-to-markdown"
import { gridTables } from "@adobe/micromark-extension-gridtables"
import {toHast} from 'mdast-util-to-hast'
import {
  gridTablesToMarkdown,
  gridTablesFromMarkdown,
  mdast2hastGridTablesHandler,
  TYPE_TABLE,
} from "@adobe/mdast-util-gridtables"

// create a markdown file and load it here
const doc = await fs.readFile("./src/example.md")

// convert markdown to mdast
const options = {
  extensions: [gridTables],
  mdastExtensions: [],
}
options.mdastExtensions.push(gridTablesToMarkdown(options))
const mdastTree = fromMarkdown(doc, options)
console.log(`mdastTree`, mdastTree)
console.log(`-------`)

// convert mdast to md
const outputMarkdown = toMarkdown(mdastTree, {
  extensions: [gridTablesToMarkdown()],
})
console.log(`outputMarkdown result`, outputMarkdown)
console.log(`-------`)

// convert mdast to hast
const hast = toHast(mdastTree, {
  handlers: {
    [TYPE_TABLE]: mdast2hastGridTablesHandler(),
  },
})
console.log(`hast output`,hast)
console.log(`-------`)
tripodsan commented 1 year ago

thank you for reporting. I'll update the docs and add a working example

github-actions[bot] commented 1 year ago

:tada: This issue has been resolved in version 1.0.7 :tada:

The release is available on:

Your semantic-release bot :package::rocket: