Package Exports
- textlint-rule-helper
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 (textlint-rule-helper) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
textlint-rule-helper
This is helper library for creating textlint rule.
Installation
npm install textlint-rule-helper
Usage - API
#####new RuleHelper() RuleHelper is helper class for textlint.
#####ruleHelper.getParents(node)
Get parents of node.
The parent nodes are returned in order from the closest parent to the outer ones.
node
is not contained in the results.
Params
- node
TxtNode
- the node is start point.
Returns: Array.<TxtNode>
#####ruleHelper.isChildNode(node, types)
Return true if node
is wrapped any one of node types
.
Params
- node
TxtNode
- is target node - types
Array.<string>
- are wrapped target node
Returns: boolean
####ruleHelper.getParents(node)
Get parents of node.
The parent nodes are returned in order from the closest parent to the outer ones.
node
is not contained in the results.
Params
- node
TxtNode
- the node is start point.
Returns: Array.<TxtNode>
####ruleHelper.isChildNode(node, types)
Return true if node
is wrapped any one of node types
.
Params
- node
TxtNode
- is target node - types
Array.<string>
- are wrapped target node
Returns: boolean
Example
A rule for textlint.
var RuleHelper = require("textlint-rule-helper").RuleHelper;
module.exports = function (context) {
var helper = new RuleHelper(context);
var exports = {}
exports[context.Syntax.Str] = function(node){
// parent nodes is any one Link or Image.
if(helper.isChildNode(node, [context.Syntax.Link, context.Syntax.Image]){
return;
}
// get Parents
var parents = helper.getParents(node);
}
return exports;
}
Development
# watch
npm run watch
# build
npm run build
# test
npm run test
# Generate README from tempalte
npm run docs
Contributing
- Fork it!
- Create your feature branch:
git checkout -b my-new-feature
- Commit your changes:
git commit -am 'Add some feature'
- Push to the branch:
git push origin my-new-feature
- Submit a pull request :D
License
MIT