Skip to content

Commit

Permalink
[Doc Enhancement] Introduce MarkdownElement #2224
Browse files Browse the repository at this point in the history
  • Loading branch information
Frank Fischer committed Nov 25, 2015
1 parent 3bf02a8 commit f29aaf2
Show file tree
Hide file tree
Showing 6 changed files with 108 additions and 5 deletions.
3 changes: 3 additions & 0 deletions docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@
},
"dependencies": {
"codemirror": "^5.5.0",
"github-markdown-css": "^2.1.0",
"hightlight.js": "^8.9.1",
"history": "^1.11.1",
"intl": "^1.0.1",
"marked": "^0.3.5",
"react-addons-perf": "^0.14.0",
"react-dom": "^0.14.0",
"react-motion": "^0.3.1",
Expand Down
45 changes: 45 additions & 0 deletions docs/src/app/components/markdown-element.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
const React = require('react');
let { Paper } = require('material-ui');
require('github-markdown-css/github-markdown.css');
import marked from 'marked';

const MarkdownElement = React.createClass({
propTypes: {
text: React.PropTypes.string.isRequired,
},
getDefaultProps() {
return {
text: '',
};
},


componentWillMount() {
marked.setOptions({
gfm: true,
tables: true,
breaks: false,
pedantic: false,
sanitize: true,
smartLists: true,
smartypants: false,
highlight: function (code) {
return require('highlight.js').highlightAuto(code).value;
},
});
},

render() {
const { text } = this.props,
html = marked(text || '');

return (
<Paper style = {{marginBottom: '22px', padding: '0 24px 24px 24px'}}>
<div className="markdown-body">
<div dangerouslySetInnerHTML={{__html: html}} />
</div>
</Paper>);
},
});

module.exports = MarkdownElement;
31 changes: 31 additions & 0 deletions docs/src/app/components/markdown/lists-markdown.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Headline 1

This is a paragraph describing something.

## Subheadline

Detailes description here. And some code:
```javascript
const FileFolder = require('svg-icons/file/folder');
const MoreVertIcon = require('svg-icons/navigation/more-vert');

```


```javascript
export default class Login extends React.Component {

constructor() {
super()
this.state = {
user: '',
password: ''
};
}
}
function fancyAlert(arg) {
if(arg) {
$.facebox({div:'#foo'})
}
}
```
6 changes: 5 additions & 1 deletion docs/src/app/components/pages/components/lists.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import FileFolder from 'svg-icons/file/folder';
import MoreVertIcon from 'svg-icons/navigation/more-vert';
import { SelectableContainerEnhance } from 'material-ui/hoc/selectable-enhance';


const {
Avatar,
Checkbox,
Expand All @@ -33,6 +34,7 @@ import MenuItem from 'menus/menu-item';

const { Colors } = Styles;
import Code from 'lists-code';
import ListsMarkdown from 'lists-markdown';
import CodeExample from '../../code-example/code-example';
import CodeBlock from '../../code-example/code-block';
let SelectableList = SelectableContainerEnhance(List);
Expand Down Expand Up @@ -98,7 +100,6 @@ export default class ListsPage extends React.Component {
}

render() {

let componentInfo = [
{
name: 'List Props',
Expand Down Expand Up @@ -769,6 +770,9 @@ import ListItem from 'material-ui/lib/lists/list-item';
</SelectableList>
</MobileTearSheet>
</CodeExample>
<MarkdownElement text={`# Headline
No more info`}/>
<MarkdownElement text={ListsMarkdown} />

<Paper style={{padding: '24px', marginBottom: '32px'}}>
<div>
Expand Down
14 changes: 12 additions & 2 deletions docs/webpack-dev-server.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ var config = {
//Webpack config options on how to obtain modules
resolve: {
//When requiring, you don't need to add these extensions
extensions: ["", ".js", ".jsx", ".txt"],
extensions: ["", ".js", ".jsx", ".md", ".txt"],
alias: {
//material-ui requires will be searched in src folder, not in node_modules
'material-ui': path.resolve(__dirname, '../src'),
Expand All @@ -27,7 +27,8 @@ var config = {
path.resolve(__dirname, "node_modules"),
path.resolve(__dirname, '../src'),
path.resolve(__dirname, '../node_modules'),
path.resolve(__dirname, 'src/app/components/raw-code')
path.resolve(__dirname, 'src/app/components/raw-code'),
path.resolve(__dirname, 'src/app/components/markdown')
]
},
//Configuration for dev server
Expand Down Expand Up @@ -78,12 +79,21 @@ var config = {
loader: 'raw-loader',
include: path.resolve(__dirname, 'src/app/components/raw-code')
},
{
test:/\.md$/,
loader: 'raw-loader',
include: path.resolve(__dirname, 'src/app/components/markdown')
},
{
test: /\.js$/, //All .js and .jsx files
loader:'babel-loader?optional=runtime&stage=0', //react-hot is like browser sync and babel loads jsx and es6-7
include: [__dirname, path.resolve(__dirname, '../src')], //include these files
exclude: [nodeModulesPath] //exclude node_modules so that they are not all compiled
},
{
test: /\.css$/,
loader: "style-loader!css-loader"
},
]
},
eslint: {
Expand Down
14 changes: 12 additions & 2 deletions docs/webpack-production.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ var config = {
//Webpack config options on how to obtain modules
resolve: {
//When requiring, you don't need to add these extensions
extensions: ["", ".js", ".jsx", ".txt"],
extensions: ["", ".js", ".jsx", ".md", ".txt"],
alias: {
//material-ui requires will be searched in src folder, not in node_modules
'material-ui': path.resolve(__dirname, '../src'),
Expand All @@ -25,7 +25,8 @@ var config = {
"node_modules",
path.resolve(__dirname, '../src'),
path.resolve(__dirname, '../node_modules'),
path.resolve(__dirname, 'src/app/components/raw-code')
path.resolve(__dirname, 'src/app/components/raw-code'),
path.resolve(__dirname, 'src/app/components/markdown')
]
},
devtool: 'source-map',
Expand Down Expand Up @@ -85,6 +86,15 @@ var config = {
loader: 'raw-loader',
include: path.resolve(__dirname, 'src/app/components/raw-code')
},
{
test:/\.md$/,
loader: 'raw-loader',
include: path.resolve(__dirname, 'src/app/components/markdown')
},
{
test: /\.css$/,
loader: "style-loader!css-loader"
},
]
},
eslint: {
Expand Down

0 comments on commit f29aaf2

Please sign in to comment.