diff --git a/Readme.md b/Readme.md index 0606fb170..006871077 100644 --- a/Readme.md +++ b/Readme.md @@ -298,6 +298,20 @@ You can change some settings in the `styleguide.config.js` file in your project }; ``` +* **`propsParser`**
+ Type: `Function`, optional
+ Function that allows you to override the mechanism used to parse props from a source file. Default mechanism is using + [react-docgen](https://github.com/reactjs/react-docgen) to parse props. + + ```javascript + module.exports = { + // ... + propsParser: function(filePath, source) { + return require('react-docgen').parse(source); + } + } + ``` + * **`resolver`**
Type: `Function`, optional
Function that allows you to override the mechanism used to identify classes/components to analyze. Default diff --git a/loaders/props.loader.js b/loaders/props.loader.js index 5f6e9376d..9c86c42c4 100644 --- a/loaders/props.loader.js +++ b/loaders/props.loader.js @@ -8,9 +8,14 @@ var requirePlaceholder = '<%{#require#}%>'; module.exports = function (source) { this.cacheable && this.cacheable(); + var defaultPropsParser = function(filePath, source) { + return reactDocs.parse(source, config.resolver, config.handlers); + }; + var jsonProps; try { - var props = reactDocs.parse(source, config.resolver, config.handlers); + var propsParser = config.propsParser || defaultPropsParser; + var props = propsParser(this.request.split('!').pop(), source); jsonProps = (isArray(props) ? props : [props]).map(function(doc) { if (doc.description) { @@ -25,7 +30,7 @@ module.exports = function (source) { } return JSON.stringify(doc).replace( - '"' + requirePlaceholder + '"', + '"' + requirePlaceholder + '"', doc.doclets.example && 'require(' + JSON.stringify('examples!' + doc.doclets.example) + ')' ); });