Giter Club home page Giter Club logo

ok-mdx's Introduction

ok-mdx

Browser-based MDX editor

npm i -g ok-mdx
mkdir docs
touch docs/hello.mdx
mdx docs --open
  • Quickly prototype with React components
  • Zero configuration
  • Mix markdown with JSX
  • Live edit and autosave

What is this for?

MDX is great for documentation, building demos, or quickly prototyping with React components, without the need to set up a full-blown React application. Similar to Compositor x0, ok-mdx is meant to be installed as a global command line utility that you can use alongside your application setup or in isolated sandbox environments. ok-mdx works well as a local alternative to tools like CodeSandbox when working with React components.

Getting Started

ok-mdx needs a directory of .mdx or .md files to work.

After installing ok-mdx, create a folder and an empty .mdx file with the following command:

mkdir docs && touch docs/hello.mdx

Start the ok-mdx app:

mdx docs --open

This will open the application in your default browser, showing a list of the MDX files. Click on a filename to open the editor view. In the right panel, add some text to see the preview on the left.

MDX Format

MDX is a superset of markdown, which can also render JSX instead of HTML.

# Markdown Heading

<button className='blue'>JSX button</button>

Importing Components

In order to import components, be sure they're installed locally. This requires a package.json file in your current directory.

To create a package.json file, run npm init -y.

To install a component, use npm install. The following will install grid-styled and styled-components as a local dependency.

npm i grid-styled styled-components

To use components, import them at the top of your MDX file:

import { Flex, Box } from 'grid-styled'

# Hello

<Flex alignItems='center'>
  <Box p={3} width={1/2} bg='blue'>
    Flex
  </Box>
  <Box p={3} width={1/2}>
    Box
  </Box>
</Flex>

Options

-o --open     Opens development server in default browser
-p --port     Port for development server
--vim         Enable editor Vim mode

Exporting

ok-mdx is only meant to be used for development. To export your MDX files, consider one of the following tools:

  • Compositor x0: great for creating documentation, blogs, static sites, or other small demos
  • Next.js: great for creating production-ready, server-side rendered React applications

Related

ok-mdx's People

Stargazers

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

Watchers

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

ok-mdx's Issues

Error: Cannot find module './lib/websocket'

Followed the setup guide in the README, tried to run mdx docs --open, and received: Error: Cannot find module './lib/websocket'.

Full error:

$ mdx docs --open

----
internal/modules/cjs/loader.js:596
    throw err;
    ^

Error: Cannot find module './lib/websocket'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:594:15)
    at Function.Module._load (internal/modules/cjs/loader.js:520:25)
    at Module.require (internal/modules/cjs/loader.js:650:17)
    at require (internal/modules/cjs/helpers.js:20:18)
    at Object.<anonymous> (/Users/Dylan/.config/yarn/global/node_modules/ws/index.js:3:19)
    at Module._compile (internal/modules/cjs/loader.js:702:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:713:10)
    at Module.load (internal/modules/cjs/loader.js:612:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:551:12)
    at Function.Module._load (internal/modules/cjs/loader.js:543:3)

Feature: Editing js files?

Would you consider allowing for a mode that allows editing of .js files too?

This way I could write my content and edit my blog components in the same interface.

Unable to install package - Unexpected end of JSON input

Hey, I've been trying to install this on my machine like so:

➜ npm i -g ok-mdx                                              
npm ERR! Unexpected end of JSON input while parsing near '...um":"0f1c547514263f77'

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/karan/.npm/_logs/2018-08-30T02_08_36_277Z-debug.log

and I get the following error:

➜ cat /home/karan/.npm/_logs/2018-08-30T01_39_56_152Z-debug.log
0 info it worked if it ends with ok
1 verbose cli [ '/home/karan/.nvm/versions/node/v8.11.4/bin/node',
1 verbose cli   '/home/karan/.nvm/versions/node/v8.11.4/bin/npm',
1 verbose cli   'i',
1 verbose cli   '-g',
1 verbose cli   'ok-mdx' ]
2 info using [email protected]
3 info using [email protected]
4 verbose npm-session 7dfbbfa78ccc8af2
5 silly install loadCurrentTree
6 silly install readGlobalPackageData
7 http fetch GET 304 https://registry.npmjs.org/ok-mdx 1547ms (from cache)
8 silly pacote tag manifest for ok-mdx@latest fetched in 1660ms
9 timing stage:loadCurrentTree Completed in 3306ms
10 silly install loadIdealTree
11 silly install cloneCurrentTreeToIdealTree
12 timing stage:loadIdealTree:cloneCurrentTree Completed in 1ms
13 silly install loadShrinkwrap
14 timing stage:loadIdealTree:loadShrinkwrap Completed in 2ms
15 silly install loadAllDepsIntoIdealTree
16 silly resolveWithNewModule [email protected] checking installable status
17 http fetch GET 304 https://registry.npmjs.org/ansi-html 572ms (from cache)
18 http fetch GET 304 https://registry.npmjs.org/babel-loader 631ms (from cache)
19 http fetch GET 200 https://registry.npmjs.org/babel-preset-stage-0 689ms
20 silly pacote range manifest for babel-loader@^7.1.5 fetched in 726ms
21 silly resolveWithNewModule [email protected] checking installable status
22 silly pacote range manifest for babel-preset-stage-0@^6.24.1 fetched in 725ms
23 silly resolveWithNewModule [email protected] checking installable status
24 http fetch GET 200 https://registry.npmjs.org/babel-preset-env 879ms
25 http fetch GET 200 https://registry.npmjs.org/babel-core 905ms
26 silly pacote range manifest for babel-preset-env@^1.7.0 fetched in 968ms
27 silly resolveWithNewModule [email protected] checking installable status
28 silly pacote range manifest for babel-core@^6.26.3 fetched in 972ms
29 silly resolveWithNewModule [email protected] checking installable status
30 http fetch GET 304 https://registry.npmjs.org/chalk 326ms (from cache)
31 silly pacote version manifest for [email protected] fetched in 1145ms
32 silly resolveWithNewModule [email protected] checking installable status
33 silly pacote range manifest for chalk@^2.4.1 fetched in 442ms
34 silly resolveWithNewModule [email protected] checking installable status
35 http fetch GET 304 https://registry.npmjs.org/get-port 219ms (from cache)
36 silly pacote range manifest for get-port@^3.2.0 fetched in 262ms
37 silly resolveWithNewModule [email protected] checking installable status
38 http fetch GET 304 https://registry.npmjs.org/html-entities 269ms (from cache)
39 silly pacote range manifest for html-entities@^1.2.1 fetched in 382ms
40 silly resolveWithNewModule [email protected] checking installable status
41 http fetch GET 304 https://registry.npmjs.org/connect-history-api-fallback 822ms (from cache)
42 http fetch GET 304 https://registry.npmjs.org/meow 333ms (from cache)
43 http fetch GET 200 https://registry.npmjs.org/babel-preset-react 1567ms
44 silly pacote range manifest for babel-preset-react@^6.24.1 fetched in 1682ms
45 silly resolveWithNewModule [email protected] checking installable status
46 silly pacote range manifest for connect-history-api-fallback@^1.5.0 fetched in 1055ms
47 silly resolveWithNewModule [email protected] checking installable status
48 silly pacote range manifest for meow@^5.0.0 fetched in 564ms
49 silly resolveWithNewModule [email protected] checking installable status
50 http fetch GET 304 https://registry.npmjs.org/pkg-conf 265ms (from cache)
51 silly pacote range manifest for pkg-conf@^2.1.0 fetched in 299ms
52 silly resolveWithNewModule [email protected] checking installable status
53 http fetch GET 304 https://registry.npmjs.org/raw-loader 224ms (from cache)
54 silly pacote range manifest for raw-loader@^0.5.1 fetched in 272ms
55 silly resolveWithNewModule [email protected] checking installable status
56 http fetch GET 304 https://registry.npmjs.org/brace 2150ms (from cache)
57 silly pacote range manifest for brace@^0.11.1 fetched in 2170ms
58 silly resolveWithNewModule [email protected] checking installable status
59 http fetch GET 304 https://registry.npmjs.org/koa-connect 1065ms (from cache)
60 http fetch GET 304 https://registry.npmjs.org/isocss 1102ms (from cache)
61 silly pacote range manifest for koa-connect@^2.0.1 fetched in 1142ms
62 silly resolveWithNewModule [email protected] checking installable status
63 http fetch GET 304 https://registry.npmjs.org/react-dev-utils 143ms (from cache)
64 silly pacote range manifest for isocss@^1.0.0-3 fetched in 1204ms
65 silly resolveWithNewModule [email protected] checking installable status
66 silly pacote range manifest for react-dev-utils@^5.0.1 fetched in 225ms
67 silly resolveWithNewModule [email protected] checking installable status
68 http fetch GET 304 https://registry.npmjs.org/@mdx-js%2fmdx 2479ms (from cache)
69 http fetch GET 304 https://registry.npmjs.org/@mdx-js%2ftag 2518ms (from cache)
70 silly pacote range manifest for @mdx-js/mdx@^0.14.0 fetched in 2539ms
71 silly resolveWithNewModule @mdx-js/[email protected] checking installable status
72 http fetch GET 304 https://registry.npmjs.org/react-router-dom 145ms (from cache)
73 http fetch GET 304 https://registry.npmjs.org/mini-html-webpack-plugin 1227ms (from cache)
74 silly pacote range manifest for @mdx-js/tag@^0.14.0 fetched in 2663ms
75 silly resolveWithNewModule @mdx-js/[email protected] checking installable status
76 silly pacote range manifest for react-router-dom@^4.3.1 fetched in 383ms
77 silly resolveWithNewModule [email protected] checking installable status
78 silly pacote range manifest for mini-html-webpack-plugin@^0.2.3 fetched in 1451ms
79 silly resolveWithNewModule [email protected] checking installable status
80 http fetch GET 304 https://registry.npmjs.org/@mdx-js%2floader 2883ms (from cache)
81 silly pacote range manifest for @mdx-js/loader@^0.14.0 fetched in 3017ms
82 silly resolveWithNewModule @mdx-js/[email protected] checking installable status
83 http fetch GET 304 https://registry.npmjs.org/progress-bar-webpack-plugin 1229ms (from cache)
84 http fetch GET 304 https://registry.npmjs.org/react 1092ms (from cache)
85 http fetch GET 304 https://registry.npmjs.org/styled-components 309ms (from cache)
86 silly pacote range manifest for progress-bar-webpack-plugin@^1.11.0 fetched in 1338ms
87 silly resolveWithNewModule [email protected] checking installable status
88 silly pacote range manifest for react@^16.4.1 fetched in 1148ms
89 silly resolveWithNewModule [email protected] checking installable status
90 http fetch GET 304 https://registry.npmjs.org/update-notifier 233ms (from cache)
91 http fetch GET 304 https://registry.npmjs.org/react-ace 1170ms (from cache)
92 silly fetchPackageMetaData error for react-ace@^6.1.4 Unexpected end of JSON input while parsing near '...ct-test-renderer":"^1'
93 silly pacote range manifest for styled-components@^3.3.3 fetched in 511ms
94 silly resolveWithNewModule [email protected] checking installable status
95 silly pacote range manifest for update-notifier@^2.5.0 fetched in 403ms
96 silly resolveWithNewModule [email protected] checking installable status
97 http fetch GET 304 https://registry.npmjs.org/react-dom 1123ms (from cache)
98 silly fetchPackageMetaData error for react-dom@^16.4.1 Unexpected end of JSON input while parsing near '...um":"0f1c547514263f77'
99 http fetch GET 304 https://registry.npmjs.org/webpack 327ms (from cache)
100 http fetch GET 304 https://registry.npmjs.org/ws 212ms (from cache)
101 http fetch GET 304 https://registry.npmjs.org/react-live 1174ms (from cache)
102 silly pacote range manifest for react-live@^1.11.0 fetched in 1218ms
103 silly resolveWithNewModule [email protected] checking installable status
104 silly pacote range manifest for webpack@^4.16.1 fetched in 437ms
105 silly resolveWithNewModule [email protected] checking installable status
106 silly pacote range manifest for ws@^5.2.2 fetched in 284ms
107 silly resolveWithNewModule [email protected] checking installable status
108 http fetch GET 304 https://registry.npmjs.org/rmdi 1286ms (from cache)
109 http fetch GET 304 https://registry.npmjs.org/reline 1411ms (from cache)
110 silly pacote range manifest for reline@^1.0.0-beta.3 fetched in 1489ms
111 silly resolveWithNewModule [email protected] checking installable status
112 http fetch GET 304 https://registry.npmjs.org/superbox 1215ms (from cache)
113 silly pacote range manifest for rmdi@^1.0.1 fetched in 1389ms
114 silly resolveWithNewModule [email protected] checking installable status
115 silly pacote range manifest for superbox@^2.1.0 fetched in 1254ms
116 silly resolveWithNewModule [email protected] checking installable status
117 http fetch GET 304 https://registry.npmjs.org/webpack-serve 1078ms (from cache)
118 silly pacote range manifest for webpack-serve@^2.0.2 fetched in 1100ms
119 silly resolveWithNewModule [email protected] checking installable status
120 http fetch GET 304 https://registry.npmjs.org/webpack-serve-overlay 1126ms (from cache)
121 silly pacote range manifest for webpack-serve-overlay@^0.2.2 fetched in 1148ms
122 silly resolveWithNewModule [email protected] checking installable status
123 timing stage:rollbackFailedOptional Completed in 1ms
124 timing stage:runTopLevelLifecycles Completed in 7751ms
125 verbose stack SyntaxError: Unexpected end of JSON input while parsing near '...ct-test-renderer":"^1'
125 verbose stack     at JSON.parse (<anonymous>)
125 verbose stack     at parseJson (/home/karan/.nvm/versions/node/v8.11.4/lib/node_modules/npm/node_modules/json-parse-better-errors/index.js:7:17)
125 verbose stack     at consumeBody.call.then.buffer (/home/karan/.nvm/versions/node/v8.11.4/lib/node_modules/npm/node_modules/node-fetch-npm/src/body.js:96:50)
125 verbose stack     at <anonymous>
125 verbose stack     at process._tickCallback (internal/process/next_tick.js:188:7)
126 verbose cwd /home/karan/projects/mdx-resume
127 verbose Linux 4.15.0-33-generic
128 verbose argv "/home/karan/.nvm/versions/node/v8.11.4/bin/node" "/home/karan/.nvm/versions/node/v8.11.4/bin/npm" "i" "-g" "ok-mdx"
129 verbose node v8.11.4
130 verbose npm  v6.4.0
131 error Unexpected end of JSON input while parsing near '...ct-test-renderer":"^1'
132 verbose exit [ 1, true ]

System Details:

OS: Ubuntu 16.04
NodeJS Version: 8.11.4 LTS
NPM Version: 6.4.0

Any idea what's going wrong?

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.