Comparing version 3.2.1 to 4.0.0
@@ -37,4 +37,4 @@ 'use strict'; | ||
return options.createElement('pre', null, options.createElement('code', { | ||
className: 'hljs ' + props.language, | ||
dangerouslySetInnerHTML: { __html: options.highlight ? options.highlight.highlight(props.language, props.code).value : props.code } | ||
className: 'language-' + props.language, | ||
dangerouslySetInnerHTML: { __html: options.highlight ? options.highlight(props.language, props.code) : props.code } | ||
})); | ||
@@ -41,0 +41,0 @@ } |
@@ -78,4 +78,4 @@ 'use strict'; | ||
return options.createElement('pre', null, options.createElement('code', { | ||
className: 'hljs ' + language, | ||
dangerouslySetInnerHTML: { __html: options.highlight ? options.highlight.highlight(language, code).value : code } | ||
className: 'language-' + language, | ||
dangerouslySetInnerHTML: { __html: options.highlight ? options.highlight(language, code) : code } | ||
})); | ||
@@ -82,0 +82,0 @@ } |
{ | ||
"name": "marksy", | ||
"version": "3.2.1", | ||
"version": "4.0.0", | ||
"description": "Convert markdown into react components", | ||
@@ -42,2 +42,3 @@ "main": "lib/index.js", | ||
"preact-render-to-string": "^3.6.3", | ||
"prismjs": "^1.6.0", | ||
"react": "^15.5.4", | ||
@@ -44,0 +45,0 @@ "react-dom": "^15.5.4", |
@@ -116,3 +116,3 @@ # marksy | ||
## Code highlighting | ||
To enable code highlighting the [Highlight.js](https://highlightjs.org/) project needs to be passed in as an option. It can be a good idea to register only necessary languages you need: | ||
To 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: | ||
@@ -122,16 +122,28 @@ ```js | ||
import 'highlight.js/styles/github.css'; | ||
import highlight from 'highlight.js/lib/highlight'; | ||
import hljs from 'highlight.js/lib/highlight'; | ||
import hljsJavascript from 'highlight.js/lib/languages/javascript'; | ||
import marksy from 'marksy/components' | ||
highlight.registerLanguage('javascript', hljsJavascript); | ||
hljs.registerLanguage('javascript', hljsJavascript); | ||
const compile = marksy({ | ||
createElement, | ||
highlight | ||
highlight(language, code) { | ||
return hljs.highlight(language, code).value | ||
} | ||
}) | ||
``` | ||
This can also be used on server side. | ||
The elements returned is: | ||
```html | ||
<pre> | ||
<code class="language-js"> | ||
...code... | ||
</code> | ||
</pre> | ||
``` | ||
Meaning that the `code` element is added a classname based on the language. | ||
## Developing | ||
@@ -138,0 +150,0 @@ 1. Clone repo |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
37369
151
22