Package

purescript-markdown-it-js

Repository
philippedev101/purescript-markdown-it-js
License
Apache-2.0
Uploaded by
pacchettibotti
Published on
2026-03-14T08:52:27Z

Thin PureScript FFI binding for markdown-it. Parses CommonMark (+ collapsible plugin) and exposes the token stream as a PureScript record type. No rendering opinion — consumers walk the tokens however they want.

Installation

# PureScript dependency
spago install markdown-it-js

# npm dependency (required — provides the JS runtime)
bun add markdown-it markdown-it-collapsible

Usage

import MarkdownIt (MdToken(..), parse)

tokens :: Array MdToken
tokens = parse "# Hello **world**"

parse returns a flat array of tokens with open/close pairs. Inline content (text, bold, links, etc.) lives in the children array of inline tokens.

type MdAttr = { key :: String, value :: String }

newtype MdToken = MdToken
  { type     :: String          -- "paragraph_open", "inline", "fence", etc.
  , tag      :: String          -- "p", "h1", "code", "a", etc.
  , nesting  :: Int             -- 1 (open), 0 (self-close), -1 (close)
  , content  :: String          -- text content (inline/text/code/fence tokens)
  , children :: Array MdToken   -- child tokens (non-empty for type="inline")
  , markup   :: String          -- delimiter, e.g. "**", "```", "+++"
  , info     :: String          -- fence info string, e.g. "js"
  , attrs    :: Array MdAttr    -- HTML attributes, e.g. {key:"href", value:"url"}
  , hidden   :: Boolean         -- true on tight list paragraphs
  }

Development

bun install
spago build
spago test

License

Apache-2.0

Modules
MarkdownIt
Dependencies
No dependencies