Skip to content

Commit

Permalink
[Doc Enhancement] Introduce MarkdownElement mui#2224
Browse files Browse the repository at this point in the history
  • Loading branch information
Frank Fischer committed Nov 20, 2015
1 parent 80548a8 commit edd7eb5
Show file tree
Hide file tree
Showing 6 changed files with 110 additions and 4 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
44 changes: 44 additions & 0 deletions docs/src/app/components/markdown-element.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
const React = require('react');
let { Paper } = require('material-ui');
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'})
}
}
```
8 changes: 8 additions & 0 deletions docs/src/app/components/pages/components/lists.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const React = require('react');
const mui = require('material-ui');
const ComponentDoc = require('../../component-doc');
const MobileTearSheet = require('../../mobile-tear-sheet');
const MarkdownElement = require('../../markdown-element');
const ActionAssignment = require('svg-icons/action/assignment');
const ActionGrade = require('svg-icons/action/grade');
const ActionInfo = require('svg-icons/action/info');
Expand All @@ -15,6 +16,8 @@ const EditorInsertChart = require('svg-icons/editor/insert-chart');
const FileFolder = require('svg-icons/file/folder');
const MoreVertIcon = require('svg-icons/navigation/more-vert');
import { SelectableContainerEnhance } from 'material-ui/hoc/selectable-enhance';
require('github-markdown-css/github-markdown.css');


const {
Avatar,
Expand All @@ -33,6 +36,7 @@ const MenuItem = require('menus/menu-item');

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

render() {
console.log("Markdown loaded: %O", ListsMarkdown);

let componentInfo = [
{
Expand Down Expand Up @@ -766,6 +771,9 @@ export default class ListsPage extends React.Component {
</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 edd7eb5

Please sign in to comment.