Coder Social home page Coder Social logo

mdxx's Introduction

MDXX

MDX eXtended

Spec

  • Parse to JSON for WebWorker
  • Compile to react component (TODO: support other compiler like preact or vue)

packages

  • mdxx-loader: webpack-loader
  • rollup-plugin-mdxx: rollup plugin
  • mdxx-parser: parser by remark
  • mdxx-compiler: runner for parsed json
  • mdxx-cli: mdxx cli tools
  • mdxx-ssg: static site generator by mdxx on minimum next.js

CLI

# install
$ npm install mdxx-cli -g

webpack loader

module.exports = {
  module: {
    rules: [
      // add this rule
      {
        test: /\.mdx?/,
        loader: "mdxx-loader",
      },
    ],
  },
};

for AMP (transform img to amp-img)

module.exports = {
  module: {
    rules: [
      // add this rule
      {
        test: /\.mdx?/,
        loader: "mdxx-loader/lib/amp",
      },
    ],
  },
};

rollup

// rollup.config.js
import { mdxx } from "rollup-plugin-mdxx";
export default {
  // ...
  plugins: [mdxx()],
};

SSG

# install
$ npm install mdxx-cli -g

Example

<!-- bar.mdx -->

import Bar from "./bar"

# Bar
<!-- foo.mdx -->

import Bar from "./bar"

# Hello from Foo

<Bar />
import React from "react";
import ReactDOM from "react-dom/server";
import Foo from "./foo.mdx";

const str = ReactDOMServer.renderToString(<Foo />);
console.log(str);
# run with js
$ mdxx foo.md # output as html

# Write js
$ mdxx index.tsx --mode js --out out.js
$ node out.js # dump js

# Write with chunk
$ mdxx index.tsx --mode js --outdir out
$ node out/index.js

API

import React from "react";
import ReactDOM from "react-dom";

import { compile } from "mdxx-compiler";
import { parse } from "mdxx-parser";

const ast = parse(`# hello`);

function App(props) {
  return const el = compile(ast, {
    props,
    components: {},
    h: React.createElement,
    Fragment: React.Fragment
  });
}

ReactDOM.render(<App />, document.querySelector("#main"));

As rollup plugin

rollup-mdxx-plugin makes .md and .mdx loadable as react component.

// rollup.config.js
import { rollup } from "rollup";
import { mdxx } from "rollup-plugin-mdxx";

export default {
  input: "index.mdx",
  output: {
    format: 'esm'
    file: "out.js"
  },
  plugins: [
    // your plugin...
    mdxx()
  ]
};

index.mdx

# Hello mdxx

import Foo from "./foo.mdx" //

<Foo />

rollup -c rollup.config.js

TODO

  • title
  • amp-img
  • Social Share button
  • CLI Scaffolding
  • Google Analytics
  • Header
  • Fix css on export
  • mdxx-compiler: amp option
  • ssg: Support styled-components
  • ssg: AMP Install Service Worker
  • ssg: Refactor layout css
  • ssg: amp-img fixed height
  • compiler: heading slug
  • compiler: toc
  • ssg: Fix css
  • compiler: Support amp-mathml
  • ssg: clickable anchor
  • ssg: Gen git history
  • ssg: Link to GitHub PR
  • ssg: Render mdx on pages/*.mdx
  • ssg: amp-script

LICENSE

MIT

mdxx's People

Contributors

mizchi avatar sadnessojisan avatar

Watchers

James Cloos 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.