{"name":"marksy","version":"8.0.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","prepublish":"npm run build","size":"size-limit","start":"webpack-dev-server --devtool eval-source-map --progress --colors --content-base build","test":"jest"},"dependencies":{"@babel/standalone":"^7.4.5","he":"^1.2.0","marked":"^0.3.12"},"devDependencies":{"@babel/cli":"^7.0.0","@babel/core":"^7.0.0","@babel/plugin-proposal-class-properties":"^7.0.0","@babel/plugin-proposal-decorators":"^7.0.0","@babel/plugin-proposal-export-namespace-from":"^7.0.0","@babel/plugin-proposal-function-sent":"^7.0.0","@babel/plugin-proposal-json-strings":"^7.0.0","@babel/plugin-proposal-numeric-separator":"^7.0.0","@babel/plugin-proposal-throw-expressions":"^7.0.0","@babel/plugin-syntax-dynamic-import":"^7.0.0","@babel/plugin-syntax-import-meta":"^7.0.0","@babel/preset-env":"^7.0.0","@babel/preset-react":"^7.0.0","babel-core":"^7.0.0-bridge.0","babel-eslint":"^9.0.0","babel-jest":"^23.4.2","babel-loader":"^8.0.0","cross-env":"^5.2.0","css-loader":"^2.1.1","eslint":"^5.16.0","eslint-config-airbnb":"^17.1.0","eslint-config-prettier":"^4.3.0","eslint-plugin-import":"^2.17.2","eslint-plugin-jest":"^22.6.4","eslint-plugin-json":"^1.4.0","eslint-plugin-jsx-a11y":"^6.2.1","eslint-plugin-prettier":"^3.1.0","eslint-plugin-react":"^7.13.0","global":"^4.3.2","highlight.js":"^9.15.6","inferno-create-element":"^7.1.12","inferno-server":"^7.1.12","jest":"^24.8.0","json-loader":"^0.5.7","node-libs-browser":"^2.2.0","preact":"^8.4.2","preact-render-to-string":"^4.1.0","prettier":"^1.17.1","prismjs":"^1.16.0","prop-types":"^15.7.2","react":"^16.8.6","react-dom":"^16.8.6","react-test-renderer":"^16.8.6","react-testing-library":"^7.0.1","regenerator-runtime":"^0.11.1","size-limit":"^1.3.2","style-loader":"^0.23.1","webpack":"^4.32.2","webpack-cli":"^3.3.2","webpack-dev-server":"^3.4.1"},"size-limit":[{"path":"lib/index.js","limit":"35 KB"}],"gitHead":"4deccce8204547bdb031a1be2b1b9a96517fdb67","_id":"marksy@8.0.0","_nodeVersion":"10.15.3","_npmVersion":"6.9.0","dist":{"integrity":"sha512-mmHcKZojCQAGuKTuu3153viXdCuxUmsSxomFaSOBTkOlfWFOZBmDhmJkOp0CsPMNRQ7m6oN2wflvAHLpBNZVPw==","shasum":"b595f121fd47058df9dda1448f6ee156ab48810a","tarball":"http://registry-npm.ywwl.com/marksy/download/marksy-8.0.0.tgz","fileCount":14,"unpackedSize":55954,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJc588VCRA9TVsSAnZWagAApmEP/1daZr6qtZ8cVhZwAx0u\nGqbAImmHdkY4BiVxjCU1RHO6BrvoqvGaaT7Do2cvygq9YJvXwdCasCZ+TPto\ncOsxV/Ux719FAyl0M9PDxd8snpX7wAMpajw4BFQSIM50LBR3tXRWTUvoMh2n\n4xy3oe+dc469exiXPynZN+5iEeBX6oltIbDZ7xibfxT2SLnvEGHq/3uL4o7l\nlKZXS2NxOhZgkOM1kaKfwJvCPAN0W48vfbgMoRzmdqxsmBGcltyfSU1cNq79\nbdXwKPhJLv3OsyNDrWZ0bTTv3kuTDnE30xo5CnC3SbJKOLSg0tWWNpsTzkhF\nmMhApU01QgvLjzrPr6jJE8uFjfhL0qs3LXroPxnuRPjkiTlwmn/pVa0ywadn\ndia4k5kJR4oJfPGaSMiLb4unJWJuYaurLGx/d7O33XvpiYQ8SmmFodhrdIjZ\nMn3CdOR6Ul4akuWLzz+WrQaEr2pbTL+ymQM3jdLFqYnQkrQWWeWYIa7+bi2/\na/QTY+JLmwClqi1tPiHfvYb/gFiJ4T/xp/F5/im8DweGb4i+UeTUDIsRn7kk\nmSmgGVLpRae5ILtDE/FEp7XeObArG2tANMoXzjXfsMnZd1UdkDdsfzVvUDJb\n+xdDxJ748Gt1WPSniw1iNFcecdVK1KcU8d4DYYaRfPtq68npxsV4x6S56ooL\nyByS\r\n=WWy/\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCmwcPOYTh1EwNVb1UX+UGr7J4bLkdHEPQsOtHwOS6CRgIhAPqxp/lsiFrmSPIrNtIxECVpQq/eyAN78w7ggPmDiPeI"}],"size":14307,"noattachment":false,"key":"/marksy/-/marksy-8.0.0.tgz"},"maintainers":[{"email":"christianalfoni@gmail.com","name":"christianalfoni"},{"email":"talpa@yandex.ru","name":"hypnosphi"},{"email":"ndelangen@me.com","name":"ndelangen"}],"_npmUser":{"name":"ndelangen","email":"ndelangen@me.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/marksy_8.0.0_1558695700517_0.3550911215237531"},"_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":1558695700705,"_cnpm_publish_time":1558695700705,"dist-tags":{"latest":"8.0.0"}}