Skip to content

Commit

Permalink
Merge pull request #10 from kadirahq/inline-css-for-markdown
Browse files Browse the repository at this point in the history
Using markdown-to-react-components for rendering markdown.
  • Loading branch information
arunoda authored Jun 19, 2016
2 parents b48e3e4 + a29d2af commit 2c2ad75
Show file tree
Hide file tree
Showing 9 changed files with 231 additions and 263 deletions.
1 change: 0 additions & 1 deletion .storybook/config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { configure } from '@kadira/storybook';

configure(function () {
require('../styles.css');
require('../src/stories/Story');
}, module);
5 changes: 5 additions & 0 deletions .storybook/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ const config = {
loaders: ['style', 'raw'],
include: path.resolve(__dirname, '../'),
},
{
test: /\.json?$/,
loaders: ['json'],
include: path.resolve(__dirname, '../'),
}
],
},
};
Expand Down
30 changes: 16 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,39 +18,41 @@
"publish-storybook": "bash .scripts/publish_storybook.sh"
},
"devDependencies": {
"react": "^15.0.0",
"react-dom": "^15.0.0",
"@kadira/storybook": "^1.31.0",
"babel-cli": "^6.5.0",
"babel-core": "^6.5.0",
"babel-eslint": "^6.0.2",
"babel-loader": "^6.2.4",
"babel-plugin-transform-runtime": "^6.5.0",
"babel-polyfill": "^6.5.0",
"babel-preset-es2015": "^6.5.0",
"babel-preset-react": "^6.5.0",
"babel-preset-stage-0": "^6.5.0",
"babel-plugin-transform-runtime": "^6.5.0",
"babel-cli": "^6.5.0",
"chai": "^3.5.0",
"enzyme": "^2.2.0",
"eslint": "^2.7.0",
"babel-eslint": "^6.0.2",
"eslint-config-airbnb": "^7.0.0",
"eslint-plugin-babel": "^3.2.0",
"eslint-plugin-jsx-a11y": "^0.6.2",
"eslint-plugin-react": "^4.3.0",
"mocha": "^2.4.5",
"chai": "^3.5.0",
"sinon": "^1.17.3",
"enzyme": "^2.2.0",
"react-addons-test-utils": "^15.0.0",
"git-url-parse": "^6.0.1",
"jsdom": "^8.3.1",
"eslint-plugin-jsx-a11y": "^0.6.2",
"@kadira/storybook": "^1.31.0",
"style-loader": "^0.13.1",
"json-loader": "^0.5.4",
"mocha": "^2.4.5",
"raw-loader": "^0.5.1",
"git-url-parse": "^6.0.1"
"react": "^15.0.0",
"react-addons-test-utils": "^15.0.0",
"react-dom": "^15.0.0",
"sinon": "^1.17.3",
"style-loader": "^0.13.1"
},
"peerDependencies": {
"react": "^0.14.7 || ^15.0.0"
},
"dependencies": {
"babel-runtime": "^6.5.0",
"markdown-modest": "github:markdowncss/modest",
"markdown-to-react-components": "^0.2.0",
"react-addons-create-fragment": "^15.1.0",
"react-remarkable": "^1.1.1"
},
Expand Down
52 changes: 42 additions & 10 deletions src/components/Story.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,21 @@
import React from 'react';
import Remarkable from 'react-remarkable';
import MTRC from 'markdown-to-react-components';
import PropTable from './PropTable';
import Node from './Node.js';
import Node from './Node';
import {H1, H2, H3, H4, H5, H6, Code, Pre, P, Small, A} from './markdown'

MTRC.configure({
h1: H1,
h2: H2,
h3: H3,
h4: H4,
h5: H5,
h6: H6,
code: Code,
pre: Pre,
p: P,
a: A,
});

export default class Story extends React.Component {
static displayName = 'Story';
Expand Down Expand Up @@ -48,6 +62,18 @@ export default class Story extends React.Component {
padding: '0 40px',
overflow: 'auto',
},
infoBody: {
fontSize: "16px",
},
infoBody: {
color: '#444',
fontFamily: "'Open Sans Condensed', sans-serif",
fontWeight: 300,
margin: '0 auto',
maxWidth: '48rem',
lineHeight: 1.45,
padding: '.25rem',
}
}

constructor(...args) {
Expand All @@ -63,11 +89,17 @@ export default class Story extends React.Component {
}

_renderInline() {
const infoBodyInlineStyle = {
borderTop: 'solid 1px #fafafa',
marginTop: '1.5em',
}
const infoBodyStyle = Object.assign(this.stylesheet.infoBody, infoBodyInlineStyle);

return (
<div>
{ this.props.children }
<div className='storybook-story-info-page'>
<div className='storybook-story-info-body storybook-story-info-body-inline'>
<div style={this.stylesheet.infoPage}>
<div style={infoBodyStyle} >
{ this._getInfoContent() }
{ this._getSourceCode() }
{ this._getPropTables() }
Expand Down Expand Up @@ -103,8 +135,8 @@ export default class Story extends React.Component {
<a style={linkStyle} onClick={openOverlay}>?</a>
<div style={infoStyle}>
<a style={linkStyle} onClick={closeOverlay}>×</a>
<div className='storybook-story-info-page'>
<div className='storybook-story-info-body'>
<div style={this.stylesheet.infoPage}>
<div style={this.stylesheet.infoBody}>
{ this._getInfoHeader() }
{ this._getInfoContent() }
{ this._getSourceCode() }
Expand Down Expand Up @@ -143,7 +175,7 @@ export default class Story extends React.Component {
padding = matches[0].length;
}
const source = lines.map(s => s.slice(padding)).join('\n');
return <Remarkable source={source}></Remarkable>;
return MTRC(source).tree;
}

_getSourceCode() {
Expand All @@ -153,12 +185,12 @@ export default class Story extends React.Component {

return (
<div>
<h3>Example Source</h3>
<pre>
<H3>Example Source</H3>
<Pre>
{React.Children.map(this.props.children, (root, idx) => (
<Node key={idx} depth={0} node={root}></Node>
))}
</pre>
</Pre>
</div>
);
}
Expand Down
41 changes: 41 additions & 0 deletions src/components/markdown/code.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import React from 'react';

export class Code extends React.Component {
render() {
const style = {
fontSize: '1.88em',
fontFamily: 'Menlo, Monaco, "Courier New", monospace',
backgroundColor: '#fafafa',
};

return <code style={style}>{this.props.children}</code>;
}
}

export class Pre extends React.Component {
render() {
const style = {
fontSize: '.88em',
fontFamily: 'Menlo, Monaco, "Courier New", monospace',
backgroundColor: '#fafafa',
padding: '.5rem',
lineHeight: 1.5,
overflowX: 'scroll',
};

return <pre style={style}>{this.props.children}</pre>;
}
}

export class Blockquote extends React.Component {
render() {
const style = {
fontSize: '1.88em',
fontFamily: 'Menlo, Monaco, "Courier New", monospace',
borderLeft: '8px solid #fafafa',
padding: '1rem',
};

return <blockquote style={style}>{this.props.children}</blockquote>;
}
}
92 changes: 92 additions & 0 deletions src/components/markdown/htags.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import React from 'react';

export class H1 extends React.Component {
render() {
const styles = {
fontFamily: 'Arimo, Helvetica, sans-serif',
color: '#777',
borderBottom: '2px solid #fafafa',
marginBottom: '1.15rem',
paddingBottom: '.5rem',
margin: '1.414rem 0 .5rem',
fontWeight: 'inherit',
lineHeight: 1.42,
textAlign: 'center',
marginTop: 0,
fontSize: '3.998rem',
};

return <h1 id={this.props.id} style={styles}>{this.props.children}</h1>;
}
}

export class H2 extends React.Component {
render() {
const styles = {
fontFamily: 'Arimo, Helvetica, sans-serif',
borderBottom: '2px solid #fafafa',
marginBottom: '1.15rem',
paddingBottom: '.5rem',
margin: '1.414rem 0 .5rem',
fontWeight: 'inherit',
lineHeight: 1.42,
fontSize: '2.827rem',
};

return <h2 id={this.props.id} style={styles}>{this.props.children}</h2>;
}
}

export class H3 extends React.Component {
render() {
const styles = {
fontFamily: 'Arimo, Helvetica, sans-serif',
borderBottom: '2px solid #fafafa',
marginBottom: '1.15rem',
paddingBottom: '.5rem',
margin: '1.414rem 0 .5rem',
fontWeight: 'inherit',
lineHeight: 1.42,
fontSize: '1.999rem',
};

return <h3 id={this.props.id} style={styles}>{this.props.children}</h3>;
}
}

export class H4 extends React.Component {
render() {
const styles = {
fontFamily: 'Arimo, Helvetica, sans-serif',
color: '#444',
margin: '1.414rem 0 .5rem',
fontWeight: 'inherit',
lineHeight: 1.42,
fontSize: '1.414rem',
};

return <h4 id={this.props.id} style={styles}>{this.props.children}</h4>;
}
}

export class H5 extends React.Component {
render() {
const styles = {
fontFamily: 'Arimo, Helvetica, sans-serif',
fontSize: '1.121rem',
};

return <h5 id={this.props.id} style={styles}>{this.props.children}</h5>;
}
}

export class H6 extends React.Component {
render() {
const styles = {
fontFamily: 'Arimo, Helvetica, sans-serif',
fontSize: '.88rem',
};

return <h6 id={this.props.id} style={styles}>{this.props.children}</h6>;
}
}
3 changes: 3 additions & 0 deletions src/components/markdown/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export { H1, H2, H3, H4, H5, H6 } from './htags';
export { Code, Pre } from './code';
export { P, Small, A } from './text';
32 changes: 32 additions & 0 deletions src/components/markdown/text.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import React from 'react';

export class P extends React.Component {
render() {
const style = {
fontFamily: 'Arimo, Helvetica, sans-serif',
fontSize: '1rem',
marginBottom: '1.3rem',
color: '#444',
};
return <p style={style}>{this.props.children}</p>;
}
}

export class Small extends React.Component {
render() {
const style = {};

return <ul style={style}>{this.props.children}</ul>;
}
}

export class A extends React.Component {
render() {
const style = {
color: '#3498db',
};

return <a href={this.props.href} style={style}>{this.props.children}</a>;
}
}

Loading

0 comments on commit 2c2ad75

Please sign in to comment.