GithubHelp home page GithubHelp logo

talentlessguy / hypermdx Goto Github PK

View Code? Open in Web Editor NEW
19.0 2.0 0.0 410 KB

⬇ Markdown enhanced with Hyperapp

License: MIT License

TypeScript 100.00%
hyperapp mdx mdx-js markdown javascript javascript-library

hypermdx's Introduction

HyperMDX

npm-badge dl-badge Coveralls

HyperMDX is an MDX-like library to enhance markdown with Hyperapp.

Features

  • Custom components for HTML elements
  • Embed Hyperapp components inside a page
  • Async and sync modes
  • Remark plugins support

Install

pnpm i hypermdx

Example

import { App } from '@tinyhttp/app'
import { h, text } from 'hyperapp'
import { renderToStream } from 'hyperapp-render'
import { hypermdx } from 'hypermdx'

const Component = (children: string) => h('h3', { style: { color: 'red' } }, text(children))

const md = hypermdx({
  components: {
    h1: (n, p, c) => h(n, { style: { color: 'blue' }, ...p }, c)
  }
})

const content = md`
# This is a custom heading defined in components

- this is a list
- yet another list

${Component('custom component')}
    `

new App().get(async (_, res) => renderToStream(content).pipe(res)).listen(3000)

Output:

<div>
  <div>
    <h1 style="color:blue">This is a custom heading defined in components</h1>
    <ul>
      <li>
        <p>this is a list</p>
      </li>
      <li>
        <p>yet another list</p>
      </li>
    </ul>
  </div>
  <h3 style="color:red">custom component</h3>
</div>

API

hypermdx(options)

Creates an function to render markdown and components.

const mdx = hypermdx()

md('Hello World', Component('hello'))

Additionally it supports template strings.

const mdx = hypermdx()

md`
# Hello World
${Component('hello')}
`

Options

components

  • Default: {}

Custom components to be used instead of default HTML tags.

const md = hypermdx({
  components: {
    h1: (name, props, children) => h(name, { style: { color: 'blue' }, ...props }, children)
  }
})

h

  • Default: hyperapp.h

Hyperscript function.

import { hyperscript2 } from 'my-own-lib'

const md = hypermdx({ h: hyperscript2 })

md`
# Hello World
`

remarkPlugins

  • Default: []

Additional Remark plugins.

import hypermdx from 'hypermdx'
import capitalize from 'remark-capitalize'
import emoji from 'remark-emoji'

const md = hypermdx({ remarkPlugins: [emoji, capitalize] })

async(options)

Same as hypermdx but instead, it returns an async function.

import { async as hypermdx } from 'hypermdx'

const md = hypermdx()

await md`
# Hello World
`

hypermdx's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.