Package Exports
- mdcss
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (mdcss) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
mdcss
mdcss lets you easily create and maintain style guides with CSS comments using Markdown.
/*---
title: Buttons
section: Base CSS
---
Button styles can be applied to any element. Typically you'll want to use
either a `<button>` or an `<a>` element:
```html_example
<button class="btn">Click</button>
<a class="btn" href="/some-page">Trulia!</a>
```
*/
.btn {
background-color: black;
color: white;
}Usage
Add mdcss to your build tool:
npm install mdcss --save-devNode
require('mdcss')({ /* options */ }).process(YOUR_CSS);PostCSS
Add PostCSS to your build tool:
npm install postcss --save-devLoad mdcss as a PostCSS plugin:
postcss([
require('mdcss')({ /* options */ })
]);Gulp
Add Gulp PostCSS to your build tool:
npm install gulp-postcss --save-devEnable mdcss within your Gulpfile:
var postcss = require('gulp-postcss');
gulp.task('css', function () {
return gulp.src('./css/src/*.css').pipe(
postcss([
require('mdcss')({ /* options */ })
])
).pipe(
gulp.dest('./css')
);
});Grunt
Add Grunt PostCSS to your build tool:
npm install grunt-postcss --save-devEnable mdcss within your Gruntfile:
grunt.loadNpmTasks('grunt-postcss');
grunt.initConfig({
postcss: {
options: {
processors: [
require('mdcss')({ /* options */ })
]
},
dist: {
src: 'css/*.css'
}
}
});Options
theme
Type: NPM Repository
Default: require('mdcss-theme-github')
The theme to be used by mdcss to create the style guide.
require('mdcss')({
theme: require('mdcss-theme-github')
})destination
Type: String
Default: 'styleguide'
The directory to write the style guide to.
Writing documentation
Add a section of documentation by writing a CSS comment that starts with three dashes ---.
/*---
This is documentation.
*//*
This is not documentation
*/The content of documentation will be parsed by Markdown and turned into HTML.
/*---
Button styles can be applied to **any** element. Typically you'll want to use
either a `<button>` or an `<a>` element:
```html
<button class="btn">Click</button>
<a class="btn" href="/some-page">Trulia!</a>
```
*/<p>Button styles can be applied to <strong>any</strong> element. Typically you'll want to use
either a <code><button></code> or an <code><a></code> element:</p>
<pre><code class="lang-html"><button class="btn">Click</button>
<a class="btn" href="/some-page">Trulia!</a>
</code></pre>Add details before a second set of three dashes --- to establish a heading for a section. Details consist of a word followed by a colon and then some text. Details are added to the Documentation object which is passed to the theme.
/*---
title: Buttons
section: Base CSS
---
Button styles can be applied to **any** element.
*/Anatomy of Documentation
Each Documentation object contains information about itself as well its relationship to other sections and the CSS itself.
- title: The proper title of the current section.
- name: The unique, hash-safe name of the current section.
- section: The proper title of the parent of the current section.
- content: The body of the current section.
- context: The original
Commentnode used to generate the current section. - parent: The
Documentationparent of the current section, if there is one. - children: An array of child
Documentationsections.
And remember, the Documentation object includes any and all details added to the heading.
/*---
title: Buttons
section: Base CSS
yakkityyak: Don’t Talk Back
---
Button styles can be applied to **any** element.
*/Writing themes
Developing themes requires a basic understanding of creating and publishing npm packages.
To get started; in a new npm package directory, create an index.js file that exports a function.
module.exports = function (opts) {
// initialize the theme
// example usage:
//
// require('mdcss')({
// theme: require('mdcss-theme-mytheme')({ /* opts */ })
// })
return function (documentation, destination, result) {
// do things with the documentation and destination path
// remember to use __dirname to target the theme directory
return new Promise(function (resolve, reject) {
// the theme may return a promise to more accurately resolve mdcss
});
};
};
// this is so mdcss can check whether the plugin has already been initialized
module.exports.type = 'mdcss-theme';The exports function is where any theme options should be initialized. It should be executed when mdcss is executed.
require('mdcss')({
theme: require('mdcss-theme-mytheme')({ /* theme options */ });
});The exports function will then return a processor function, which is the heart of a theme. The processor function will receive 3 parameters — documentation, the Documentation object; destination, the directory to write the style guide to; and result, the Result instance from PostCSS.
The documentation object can be used to put together many different styles of documentation. The sky is the limit.
Have fun, and thanks for using mdcss.