{"name":"marksy","version":"6.1.0","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":"cross-env 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"},"dependencies":{"babel-standalone":"^6.26.0","he":"^1.1.1","marked":"^0.3.12"},"devDependencies":{"babel-cli":"^6.26.0","babel-core":"^6.26.0","babel-eslint":"^8.2.1","babel-jest":"^22.1.0","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.9","eslint":"^4.16.0","eslint-config-airbnb":"^16.1.0","eslint-config-prettier":"^2.9.0","eslint-plugin-import":"^2.8.0","eslint-plugin-jest":"^21.7.0","eslint-plugin-json":"^1.2.0","eslint-plugin-jsx-a11y":"^6.0.3","eslint-plugin-prettier":"^2.5.0","eslint-plugin-react":"^7.6.1","global":"^4.3.2","highlight.js":"^9.12.0","inferno-create-element":"^3.10.1","inferno-server":"^3.10.1","jest":"^23.5.0","json-loader":"^0.5.7","node-libs-browser":"^2.1.0","preact":"^8.2.7","preact-render-to-string":"^3.7.0","prettier":"^1.10.2","prismjs":"^1.10.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.14.0","style-loader":"^0.20.1","webpack":"^3.10.0","webpack-dev-server":"^2.11.1"},"jest":{"testEnvironment":"node"},"size-limit":[{"path":"lib/index.js","limit":"30 KB"}],"gitHead":"86dde964d4eec5186e16a8f8769c4f9dec0ef6d7","_id":"marksy@6.1.0","_npmVersion":"6.3.0","_nodeVersion":"8.11.2","_npmUser":{"name":"christianalfoni","email":"christianalfoni@gmail.com"},"dist":{"integrity":"sha512-xVAuJQxwdAljvFVqlY7CIRewn5YHGvCqeJkY1bbcTBfZV4dNDSZpHWTREb1MNu/oXYzKgg5pmTfE1DIW6M1zrA==","shasum":"36482148a1115cc78570855f7ebd744bb453d5cc","tarball":"http://registry-npm.ywwl.com/marksy/download/marksy-6.1.0.tgz","fileCount":15,"unpackedSize":56606,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJbir5HCRA9TVsSAnZWagAAkdIP/1keCCjrMpvEB0y8YnjA\nMjmhctuXFDo9XX5Bl35LChqzwtViyd2STmUx9zWcCfmGxf/w8ScPcAQS3Urx\n6Ltruy+U/gv/SUmU9/RWeGzuEI/b6i5NimVMcHYTxMawO6/IvRTRhNy1qDMZ\n1AJ7L5CCNxoyl5W0qoeNrA3Hb12A4kDz4yVf5kQfJe6U2BIA5kw721ZF9KBG\noRs4enFsZv3NX4k0nXDoPjHOKeMwcYPqEWnmXWcyI7Z2uWXuSkU6X3YJ8AQZ\n9hsUnq2deLMTppmuYUyYVVFkfZfS/lJC7cM4zqKcuDF6dGwnf6mGSQPHLXVh\nPcLcDXiWrEaMnSi/yXnJdIkvMkiM4XGwldflHeFlAX9nA06Z9ptZB0sCisqp\neZhS0M/b1Jh2u/Ju4YqSaYxQOWHj80Alk8UuR5Yt3bY1SHNeZ8grmN3RrlUa\nKhjh73o4Ol3QeWuO/5eI17ARUu/NgtpwlvxvgJwVeIhfr2s9agNgzXm6ohNs\nn2UUcf8rq9B79giUSat3l/XO3n7FJmIwd/n7BO6fqz9LhxBnJZtWBiacHJyB\nzeJQK+BxYBRWkXi1i1R/Gx1hxJmWxrztkmvgtg6fENVlC/al2C/muqUvO/3z\nhagcNcNnQMWgreNXVoF/wG6IgK02x9zcz8l+VqNU9ib389CQIiPC4OWdxHFs\nCMTr\r\n=ithx\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDl6HIkho+3FPuYrWvfNI9NXTk1KAjhYCiCCTkyO7CwmwIhAN4NJ8jG3cVTU0YVV039xxWXa2H7YhUAWzJAwkPwIvDp"}],"size":13991,"noattachment":false,"key":"/marksy/-/marksy-6.1.0.tgz"},"maintainers":[{"email":"christianalfoni@gmail.com","name":"christianalfoni"},{"email":"talpa@yandex.ru","name":"hypnosphi"},{"email":"ndelangen@me.com","name":"ndelangen"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/marksy_6.1.0_1535819334504_0.5697965573364665"},"_hasShrinkwrap":false,"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":1535819334706,"_cnpm_publish_time":1535819334706,"dist-tags":{"latest":"8.0.0"}}