{"name":"marksy","version":"3.0.0","description":"Convert markdown into react components","main":"lib/index.js","scripts":{"start":"webpack-dev-server --devtool eval-source-map --progress --colors --content-base build","prepublish":"npm run build","build":"BABEL_ENV=production babel src/ --out-dir=lib/ -s","test":"jest"},"repository":{"type":"git","url":"git+https://github.com/cerebral/marksy.git"},"keywords":["react","markdown","convert"],"author":{"name":"Christian Alfoni"},"license":"MIT","bugs":{"url":"https://github.com/cerebral/marksy/issues"},"homepage":"https://github.com/cerebral/marksy","devDependencies":{"babel-core":"^6.24.1","babel-jest":"^19.0.0","babel-loader":"^7.0.0","babel-preset-es2015":"^6.24.1","babel-preset-react":"^6.24.1","css-loader":"^0.15.2","inferno-create-element":"^3.3.1","inferno-server":"^3.3.1","jest":"^20.0.1","json-loader":"^0.5.2","node-libs-browser":"^0.5.2","preact":"^8.1.0","preact-render-to-string":"^3.6.3","react":"^15.5.4","react-dom":"^15.5.4","react-test-renderer":"^15.5.4","regenerator-runtime":"^0.10.3","style-loader":"^0.12.3","webpack":"^2.4.1","webpack-dev-server":"^2.4.2"},"dependencies":{"babel-standalone":"^6.24.0","he":"^1.1.1","marked":"^0.3.6"},"gitHead":"f1e92eb9a11035f3f2313e108d1b31ae7b6c8315","_id":"marksy@3.0.0","_shasum":"a024ecaa095fef6d615b3e977cab5b15f9930e54","_from":".","_npmVersion":"3.10.10","_nodeVersion":"6.10.2","_npmUser":{"name":"christianalfoni","email":"christianalfoni@gmail.com"},"dist":{"shasum":"a024ecaa095fef6d615b3e977cab5b15f9930e54","tarball":"http://registry-npm.ywwl.com/marksy/download/marksy-3.0.0.tgz","integrity":"sha512-E2n3RsEOnD3szoM3Ow/4bfFYbDxqGONiJVvaAZHhcPmTTEiNWQdvUn7GxY54wFDjGDqz0KFtgkYuh51AasY/lA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQD9DUrBRaW2VoVuyFGAM/aUBb4ykEfwRHZs9gfomTmk8AIgGwPGLvd7LYjCElHzMxdBKm3JKTNtok7XwxpxkySwKoQ="}],"size":9454,"noattachment":false,"key":"/marksy/-/marksy-3.0.0.tgz"},"maintainers":[{"name":"christianalfoni","email":"christianalfoni@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/marksy-3.0.0.tgz_1496866592784_0.5645447121933103"},"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":1496866593727,"_cnpm_publish_time":1496866593727,"dist-tags":{"latest":"8.0.0"}}