{"name":"marksy","version":"6.0.3","description":"Convert markdown into react components","keywords":["convert","markdown","react"],"homepage":"https://github.com/storybooks/marksy","bugs":{"url":"https://github.com/storybooks/marksy/issues"},"license":"MIT","author":{"name":"Christian Alfoni"},"main":"lib/index.js","repository":{"type":"git","url":"git+https://github.com/storybooks/marksy.git"},"scripts":{"build":"BABEL_ENV=production babel src/ --out-dir=lib/ -s","lint":"cross-env NODE_ENV=production eslint --cache --cache-location=.cache/eslint --ext .js,.jsx,.json ./src ./app","prepare":"npm run build","size":"size-limit","start":"webpack-dev-server --devtool eval-source-map --progress --colors --content-base build","test":"jest && size-limit"},"dependencies":{"babel-standalone":"^6.26.0","he":"^1.1.1","marked":"^0.3.9"},"devDependencies":{"babel-cli":"^6.26.0","babel-core":"^6.26.0","babel-eslint":"^8.1.2","babel-jest":"^22.0.4","babel-loader":"^7.1.2","babel-preset-env":"^1.6.1","babel-preset-react":"^6.24.1","babel-preset-stage-2":"^6.24.1","cross-env":"^5.1.3","css-loader":"^0.28.7","eslint":"^4.14.0","eslint-config-airbnb":"^16.1.0","eslint-config-prettier":"^2.9.0","eslint-plugin-import":"^2.8.0","eslint-plugin-jest":"^21.5.0","eslint-plugin-json":"^1.2.0","eslint-plugin-jsx-a11y":"^6.0.3","eslint-plugin-prettier":"^2.4.0","eslint-plugin-react":"^7.5.1","global":"^4.3.2","highlight.js":"^9.12.0","inferno-create-element":"^3.10.1","inferno-server":"^3.10.1","jest":"^22.0.4","json-loader":"^0.5.7","node-libs-browser":"^2.1.0","preact":"^8.2.7","preact-render-to-string":"^3.7.0","prettier":"^1.9.2","prismjs":"^1.9.0","prop-types":"^15.6.0","react":"^16.2.0","react-dom":"^16.2.0","react-test-renderer":"^16.2.0","regenerator-runtime":"^0.11.1","size-limit":"^0.13.2","style-loader":"^0.19.1","webpack":"^3.10.0","webpack-dev-server":"^2.9.7"},"size-limit":[{"path":"lib/index.js","limit":"30 KB"}],"gitHead":"27e764793fab679c0a7cb124c573df0975cd1487","_id":"marksy@6.0.3","_npmVersion":"5.5.1","_nodeVersion":"8.9.1","_npmUser":{"name":"hypnosphi","email":"talpa@yandex.ru"},"dist":{"integrity":"sha512-k9r4HIpKlreInh6IVDGxhRs0veCr6WfLwP6lr2HXG8so+N6m6rfFKSpik9ZbvnTfKvdPhehwBWT5W+Fli29Ebg==","shasum":"6079076e8689b563b61be058942090c7ba1f5d20","tarball":"http://registry-npm.ywwl.com/marksy/download/marksy-6.0.3.tgz","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIDwPzdDg0RVdmstAbQ6c0kGpvZQaB3X3cIiitT2oY63fAiEAn+9dP22tO74V7bU+0ePZIyLyY86xanAPP3jQS6v+d/k="}],"size":19450,"noattachment":false,"key":"/marksy/-/marksy-6.0.3.tgz"},"maintainers":[{"email":"ndelangen@me.com","name":"ndelangen"},{"email":"talpa@yandex.ru","name":"hypnosphi"},{"email":"christianalfoni@gmail.com","name":"christianalfoni"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/marksy-6.0.3.tgz_1515237418009_0.08529217774048448"},"directories":{},"readme":"# Marksy\nA markdown to custom components library. Supports any virtual DOM library.\n\n## Installation\n\n```sh\nnpm install marksy\n```\n\n## Usage\n```js\nimport React, {createElement} from 'React';\nimport marksy from 'marksy'\n// const marksy = require('marksy').marksy\n\nconst compile = marksy({\n  // Pass in whatever creates elements for your\n  // virtual DOM library. h('h1', {})\n  createElement,\n\n  // You can override the default elements with\n  // custom VDOM trees\n  elements: {\n    h1 ({id, children}) {\n      return <h1 className=\"my-custom-class\">{children}</h1>\n    },\n    h2 ({id, children}) {},\n    h3 ({id, children}) {},\n    h4 ({id, children}) {},\n    blockquote ({children}) {},\n    hr () {},\n    ol ({children}) {},\n    ul ({children}) {},\n    p ({children}) {},\n    table ({children}) {},\n    thead ({children}) {},\n    tbody ({children}) {},\n    tr ({children}) {},\n    th ({children}) {},\n    td ({children}) {},\n    a ({href, title, target, children}) {},\n    strong ({children}) {},\n    em ({children}) {},\n    br () {},\n    del ({children}) {},\n    img ({src, alt}) {},\n    code ({language, code}) {},\n    codespan ({children}) {},\n  },\n});\n\nconst compiled = compile('# hello', {\n  // Options passed to \"marked\" (https://www.npmjs.com/package/marked)\n});\n\ncompiled.tree // The React tree of components\ncompiled.toc // The table of contents, based on usage of headers\n```\n\n### Components\nYou can also add your own custom components. You do this by importing `marksy/jsx`. This build of marksy includes babel transpiler which will convert any HTML to elements and allow for custom components:\n\n<pre lang=\"js\"><code>\nimport React, {createElement} from 'react'\nimport marksy from 'marksy'\n\nconst compile = marksy({\n  createElement,\n  components: {\n    MyCustomComponent (props) {\n      return &lt;h1>{props.children}&lt;/h1>\n    }\n  }\n})\n\n/* CREATE MARKDOWN USING MARKSY LANGUAGE:\n  # Just a test\n  ```marksy\n  h(MyCustomComponent, {}, \"Some text\")\n  ```\n*/\n</code></pre>\n\nThis will be converted to the component above. You can pass in any kind of props, as if it was normal code. If you are not familiar with `h`, this is a convention for creating elements and components in virtual dom implementations.\n\n### Jsx\n\nYou can take one step further and create components wherever you want in the markdown, using jsx. You will have to import `marksy/jsx`. This build of marksy includes babel transpiler which will convert any HTML to elements and allow for custom components. Note that this will increase your bundle size sagnificantly:\n\n<pre lang=\"js\"><code>\nimport React, {createElement} from 'react'\nimport marksy from 'marksy/jsx'\n\nconst compile = marksy({\n  createElement,\n  components: {\n    MyCustomComponent (props) {\n      return &lt;h1>{props.children}&lt;/h1>\n    }\n  }\n})\n\n/* MARKDOWN:\n  # Just a test\n  &lt;MyCustomComponent>some text&lt;/MyCustomComponent>\n*/\n\n/* WITH LANGUAGE FOR GENERIC SUPPORT:\n  # Just a test\n  ```marksy\n  &lt;MyCustomComponent>some text&lt;/MyCustomComponent>\n  ```\n*/\n</code></pre>\n\n### Context\nYou might need to pass in general information to your custom elements and components. You can pass in a context to do so:\n\n```js\nimport React, {createElement} from 'react'\nimport marksy from 'marksy/jsx'\n\nconst compile = marksy({\n  createElement,\n  elements: {\n    h1(props) {\n      return <h1>{props.context.foo}</h1>\n    }\n  },\n  components: {\n    MyCustomComponent (props) {\n      return <h1>{props.context.foo}</h1>\n    }\n  }\n})\n\ncompile('<MyCustomComponent />', null, {\n  foo: 'bar'\n})\n```\n\n### Code highlighting\nTo enable code highlighting you just need to add a method that does the transformation. Here is an example with [Highlight.js](https://highlightjs.org/), but you could also use [Prism](http://prismjs.com/). Both of them support server side rendering. For example:\n\n```js\nimport {createElement} from 'react'\nimport 'highlight.js/styles/github.css';\nimport hljs from 'highlight.js/lib/highlight';\nimport hljsJavascript from 'highlight.js/lib/languages/javascript';\nimport marksy from 'marksy/jsx'\n\nhljs.registerLanguage('javascript', hljsJavascript);\n\nconst compile = marksy({\n  createElement,\n  highlight(language, code) {\n    return hljs.highlight(language, code).value\n  }\n})\n```\n\nThe elements returned is:\n\n```html\n<pre>\n  <code class=\"language-js\">\n    ...code...\n  </code>\n</pre>\n```\n\nMeaning that the `code` element is added a classname based on the language.\n\n## Developing\n1. Clone repo\n2. `yarn install`\n3. `yarn start` -> localhost:8080 (development app)\n","publish_time":1515237419095,"_cnpm_publish_time":1515237419095,"dist-tags":{"latest":"8.0.0"}}