diff --git a/example/.storybook/addons.js b/example/.storybook/addons.js
index 7f5ce36..134dd86 100644
--- a/example/.storybook/addons.js
+++ b/example/.storybook/addons.js
@@ -1,3 +1,3 @@
+import '../../register'
import '@kadira/storybook/addons'
import '@kadira/storybook-addon-options/register'
-import '../../register'
diff --git a/example/stories/index.js b/example/stories/index.js
index 8c0779b..23fcd3c 100644
--- a/example/stories/index.js
+++ b/example/stories/index.js
@@ -21,12 +21,15 @@ storiesOf('test', module)
'Paris',
() => (
- Hello
+
+ Hello
),
{ displayName: 'Testeru' },
)
- .addWithJSX('Orleans', () => Hello)
+ .addWithJSX('Orleans', () => (
+
+ ))
storiesOf('test 2', module).addWithJSX(
'Paris',
diff --git a/package.json b/package.json
index b618e72..4c2539e 100644
--- a/package.json
+++ b/package.json
@@ -32,7 +32,6 @@
},
"dependencies": {
"jsx-to-string": "^1.1.0",
- "prismjs": "^1.6.0",
"react-copy-to-clipboard": "^4.3.1"
}
}
diff --git a/src/jsx.js b/src/jsx.js
new file mode 100644
index 0000000..b633ec9
--- /dev/null
+++ b/src/jsx.js
@@ -0,0 +1,60 @@
+import React, { Component } from 'react'
+import Prism from './prism.min'
+
+import globalStyle from './css'
+
+const prismStyle = document.createElement('style')
+prismStyle.innerHTML = globalStyle
+document.body.appendChild(prismStyle)
+
+export default class JSX extends Component {
+ constructor(props, ...args) {
+ super(props, ...args)
+ props.ob({
+ next: type =>
+ (type === 'jsx'
+ ? this.onAddJSX.bind(this)
+ : this.setCurrent.bind(this)),
+ })
+
+ this.state = {}
+ this.stopListeningOnStory = () => this.setState({})
+ }
+
+ setCurrent(kind, story) {
+ this.setState({ current: { kind, story } })
+ }
+
+ onAddJSX(kind, story, jsx) {
+ const state = this.state
+
+ if (typeof state[kind] === 'undefined') {
+ state[kind] = {}
+ }
+ state[kind][story] = jsx
+ this.setState(state)
+ }
+ render() {
+ if (
+ typeof this.state.current !== 'undefined' &&
+ typeof this.state[this.state.current.kind] !== 'undefined'
+ ) {
+ const current = this.state.current
+ const code = this.state[current.kind][current.story]
+ const jsx = code ? Prism.highlight(code, Prism.languages.jsx) : ''
+
+ return (
+
+ )
+ } else {
+ return
+ }
+ }
+}
+
+const styles = {
+ pre: {
+ flex: 1,
+ padding: '5px 15px',
+ },
+}
diff --git a/src/prism.js b/src/prism.js
new file mode 100644
index 0000000..1e37c5b
--- /dev/null
+++ b/src/prism.js
@@ -0,0 +1,456 @@
+/* http://prismjs.com/download.html?themes=prism&languages=markup+clike+javascript+jsx */
+var _self = 'undefined' != typeof window
+ ? window
+ : 'undefined' != typeof WorkerGlobalScope && self instanceof WorkerGlobalScope
+ ? self
+ : {},
+ Prism = (function() {
+ var e = /\blang(?:uage)?-(\w+)\b/i,
+ t = 0,
+ n = (_self.Prism = {
+ manual: _self.Prism && _self.Prism.manual,
+ util: {
+ encode: function(e) {
+ return e instanceof a
+ ? new a(e.type, n.util.encode(e.content), e.alias)
+ : 'Array' === n.util.type(e)
+ ? e.map(n.util.encode)
+ : e
+ .replace(/&/g, '&')
+ .replace(/ e.length) break e
+ if (!(v instanceof a)) {
+ u.lastIndex = 0
+ var b = u.exec(v), k = 1
+ if (!b && h && m != r.length - 1) {
+ if (((u.lastIndex = y), (b = u.exec(e)), !b)) break
+ for (
+ var w = b.index + (c ? b[1].length : 0),
+ _ = b.index + b[0].length,
+ P = m,
+ A = y,
+ j = r.length;
+ j > P && _ > A;
+ ++P
+ )
+ (A += r[P].length), w >= A && (++m, (y = A))
+ if (r[m] instanceof a || r[P - 1].greedy) continue
+ ;(k = P - m), (v = e.slice(y, A)), (b.index -= y)
+ }
+ if (b) {
+ c && (f = b[1].length)
+ var w = b.index + f,
+ b = b[0].slice(f),
+ _ = w + b.length,
+ x = v.slice(0, w),
+ O = v.slice(_),
+ S = [m, k]
+ x && S.push(x)
+ var N = new a(i, g ? n.tokenize(b, g) : b, d, b, h)
+ S.push(N), O && S.push(O), Array.prototype.splice.apply(
+ r,
+ S,
+ )
+ }
+ }
+ }
+ }
+ }
+ return r
+ },
+ hooks: {
+ all: {},
+ add: function(e, t) {
+ var a = n.hooks.all
+ ;(a[e] = a[e] || []), a[e].push(t)
+ },
+ run: function(e, t) {
+ var a = n.hooks.all[e]
+ if (a && a.length) for (var r, l = 0; (r = a[l++]); ) r(t)
+ },
+ },
+ }),
+ a = (n.Token = function(e, t, n, a, r) {
+ ;(this.type = e), (this.content = t), (this.alias = n), (this.length =
+ 0 | (a || '').length), (this.greedy = !!r)
+ })
+ if (
+ ((a.stringify = function(e, t, r) {
+ if ('string' == typeof e) return e
+ if ('Array' === n.util.type(e))
+ return e
+ .map(function(n) {
+ return a.stringify(n, t, e)
+ })
+ .join('')
+ var l = {
+ type: e.type,
+ content: a.stringify(e.content, t, r),
+ tag: 'span',
+ classes: ['token', e.type],
+ attributes: {},
+ language: t,
+ parent: r,
+ }
+ if (
+ ('comment' == l.type && (l.attributes.spellcheck = 'true'), e.alias)
+ ) {
+ var i = 'Array' === n.util.type(e.alias) ? e.alias : [e.alias]
+ Array.prototype.push.apply(l.classes, i)
+ }
+ n.hooks.run('wrap', l)
+ var o = Object.keys(l.attributes)
+ .map(function(e) {
+ return (
+ e + '="' + (l.attributes[e] || '').replace(/"/g, '"') + '"'
+ )
+ })
+ .join(' ')
+ return (
+ '<' +
+ l.tag +
+ ' class="' +
+ l.classes.join(' ') +
+ '"' +
+ (o ? ' ' + o : '') +
+ '>' +
+ l.content +
+ '' +
+ l.tag +
+ '>'
+ )
+ }), !_self.document)
+ )
+ return _self.addEventListener
+ ? (_self.addEventListener(
+ 'message',
+ function(e) {
+ var t = JSON.parse(e.data),
+ a = t.language,
+ r = t.code,
+ l = t.immediateClose
+ _self.postMessage(n.highlight(r, n.languages[a], a)), l &&
+ _self.close()
+ },
+ !1,
+ ), _self.Prism)
+ : _self.Prism
+ var r =
+ document.currentScript ||
+ [].slice.call(document.getElementsByTagName('script')).pop()
+ return r &&
+ ((n.filename = r.src), !document.addEventListener ||
+ n.manual ||
+ r.hasAttribute('data-manual') ||
+ ('loading' !== document.readyState
+ ? window.requestAnimationFrame
+ ? window.requestAnimationFrame(n.highlightAll)
+ : window.setTimeout(n.highlightAll, 16)
+ : document.addEventListener(
+ 'DOMContentLoaded',
+ n.highlightAll,
+ ))), _self.Prism
+ })()
+'undefined' != typeof module &&
+ module.exports &&
+ (module.exports = Prism), 'undefined' != typeof global &&
+ (global.Prism = Prism)
+;(Prism.languages.markup = {
+ comment: //,
+ prolog: /<\?[\w\W]+?\?>/,
+ doctype: //i,
+ cdata: //i,
+ tag: {
+ pattern: /<\/?(?!\d)[^\s>\/=$<]+(?:\s+[^\s>\/=]+(?:=(?:("|')(?:\\\1|\\?(?!\1)[\w\W])*\1|[^\s'">=]+))?)*\s*\/?>/i,
+ inside: {
+ tag: {
+ pattern: /^<\/?[^\s>\/]+/i,
+ inside: { punctuation: /^<\/?/, namespace: /^[^\s>\/:]+:/ },
+ },
+ 'attr-value': {
+ pattern: /=(?:('|")[\w\W]*?(\1)|[^\s>]+)/i,
+ inside: { punctuation: /[=>"']/ },
+ },
+ punctuation: /\/?>/,
+ 'attr-name': {
+ pattern: /[^\s>\/]+/,
+ inside: { namespace: /^[^\s>\/:]+:/ },
+ },
+ },
+ },
+ entity: /?[\da-z]{1,8};/i,
+}), Prism.hooks.add('wrap', function(a) {
+ 'entity' === a.type && (a.attributes.title = a.content.replace(/&/, '&'))
+}), (Prism.languages.xml = Prism.languages.markup), (Prism.languages.html =
+ Prism.languages.markup), (Prism.languages.mathml =
+ Prism.languages.markup), (Prism.languages.svg = Prism.languages.markup)
+Prism.languages.clike = {
+ comment: [
+ { pattern: /(^|[^\\])\/\*[\w\W]*?\*\//, lookbehind: !0 },
+ { pattern: /(^|[^\\:])\/\/.*/, lookbehind: !0 },
+ ],
+ string: {
+ pattern: /(["'])(\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1/,
+ greedy: !0,
+ },
+ 'class-name': {
+ pattern: /((?:\b(?:class|interface|extends|implements|trait|instanceof|new)\s+)|(?:catch\s+\())[a-z0-9_\.\\]+/i,
+ lookbehind: !0,
+ inside: { punctuation: /(\.|\\)/ },
+ },
+ keyword: /\b(if|else|while|do|for|return|in|instanceof|function|new|try|throw|catch|finally|null|break|continue)\b/,
+ boolean: /\b(true|false)\b/,
+ function: /[a-z0-9_]+(?=\()/i,
+ number: /\b-?(?:0x[\da-f]+|\d*\.?\d+(?:e[+-]?\d+)?)\b/i,
+ operator: /--?|\+\+?|!=?=?|<=?|>=?|==?=?|&&?|\|\|?|\?|\*|\/|~|\^|%/,
+ punctuation: /[{}[\];(),.:]/,
+}
+;(Prism.languages.javascript = Prism.languages.extend('clike', {
+ keyword: /\b(as|async|await|break|case|catch|class|const|continue|debugger|default|delete|do|else|enum|export|extends|finally|for|from|function|get|if|implements|import|in|instanceof|interface|let|new|null|of|package|private|protected|public|return|set|static|super|switch|this|throw|try|typeof|var|void|while|with|yield)\b/,
+ number: /\b-?(0x[\dA-Fa-f]+|0b[01]+|0o[0-7]+|\d*\.?\d+([Ee][+-]?\d+)?|NaN|Infinity)\b/,
+ function: /[_$a-zA-Z\xA0-\uFFFF][_$a-zA-Z0-9\xA0-\uFFFF]*(?=\()/i,
+ operator: /--?|\+\+?|!=?=?|<=?|>=?|==?=?|&&?|\|\|?|\?|\*\*?|\/|~|\^|%|\.{3}/,
+})), Prism.languages.insertBefore('javascript', 'keyword', {
+ regex: {
+ pattern: /(^|[^\/])\/(?!\/)(\[.+?]|\\.|[^\/\\\r\n])+\/[gimyu]{0,5}(?=\s*($|[\r\n,.;})]))/,
+ lookbehind: !0,
+ greedy: !0,
+ },
+}), Prism.languages.insertBefore('javascript', 'string', {
+ 'template-string': {
+ pattern: /`(?:\\\\|\\?[^\\])*?`/,
+ greedy: !0,
+ inside: {
+ interpolation: {
+ pattern: /\$\{[^}]+\}/,
+ inside: {
+ 'interpolation-punctuation': {
+ pattern: /^\$\{|\}$/,
+ alias: 'punctuation',
+ },
+ rest: Prism.languages.javascript,
+ },
+ },
+ string: /[\s\S]+/,
+ },
+ },
+}), Prism.languages.markup &&
+ Prism.languages.insertBefore('markup', 'tag', {
+ script: {
+ pattern: /(