diff --git a/README.md b/README.md
index ca2a141f..f15e437c 100644
--- a/README.md
+++ b/README.md
@@ -318,6 +318,41 @@ For example, to parse all .css files using postcss parser, following configurati
}
```
+
+**styleguideProcessors** (object, optional)
+
+default:
+
+```js
+styleguideProcessors: {}
+```
+
+Styleguide has several processors that enrich or modify the data. For example the `sg-wrapper` replacement is done by a processor.
+You can add you own processor to enrich the styleguide data with you own content or modifications.
+You can also override existing functionality by overwriting the related processor.
+Currently these processors exist by default and should not be overwritten unless you know what you are doing:
+
+```js
+styleguideProcessors: {
+ 10: replaceSectionReferences,
+ 20: generateSectionWrapperMarkup
+}
+```
+
+You can define your own processors:
+
+```js
+styleguideProcessors: {
+ 11: function(styleguide) {
+ // this will run after replaceSectionReferences
+ styleguide.sections[0].description = styleguide.sections[0].description + ' [Description from custom Processor]';
+ },
+ 30: function(styleguide) {
+ // this will run after generateSectionWrapperMarkup
+ }
+}
+```
+
**filesConfig** (array, optional) **(Experimental feature)**
diff --git a/demo-gulpfile.js b/demo-gulpfile.js
index d4f9b38c..9193425b 100644
--- a/demo-gulpfile.js
+++ b/demo-gulpfile.js
@@ -15,6 +15,11 @@ gulp.task('styleguide:generate', function() {
styleVariables: 'lib/app/css/_styleguide_variables.css',
parsers: {
css: 'postcss'
+ },
+ styleguideProcessors: {
+ 40: function(styleguide) {
+ styleguide.sections[0].description = styleguide.sections[0].description + ' [Description from custom Processor]';
+ }
}
}))
.pipe(gulp.dest(outputPath));
diff --git a/lib/modules/common.js b/lib/modules/common.js
index 34d2ed6c..e957bbeb 100644
--- a/lib/modules/common.js
+++ b/lib/modules/common.js
@@ -30,7 +30,8 @@ function sanitizeOptions(opt) {
less: 'less',
postcss: 'postcss'
},
- filesConfig: opt.filesConfig
+ filesConfig: opt.filesConfig,
+ styleguideProcessors: opt.styleguideProcessors || {}
};
}
diff --git a/lib/styleguide.js b/lib/styleguide.js
index b15a0642..5f19a830 100644
--- a/lib/styleguide.js
+++ b/lib/styleguide.js
@@ -225,7 +225,14 @@ module.exports.generate = function(options) {
throughOpts = {
objectMode: true,
allowHalfOpen: false
- };
+ },
+ styleguideProcessors = _.extend(
+ {
+ 10: replaceSectionReferences,
+ 20: generateSectionWrapperMarkup
+ },
+ opt.styleguideProcessors
+ );
function bufferFileContents(file, enc, done) {
if (file.isNull()) {
@@ -296,8 +303,11 @@ module.exports.generate = function(options) {
}
options.enableJade && generateJadeMarkup(styleguide, options);
- replaceSectionReferences(styleguide);
- generateSectionWrapperMarkup(styleguide);
+
+ _.each(styleguideProcessors, function(processor) {
+ processor(styleguide);
+ });
+
copyUsedOptionsToJsonConfig(opt, styleguide);
appendUsedVariablesToEachBlock(opt, styleguide);
addFileHashesAndReplaceAbsolutePaths(styleguide);