Skip to content

Commit

Permalink
feat(options): add fakeInlineCode option
Browse files Browse the repository at this point in the history
  • Loading branch information
azu committed Feb 14, 2016
1 parent b4d7d88 commit 2066eb4
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions src/textlint-rule-rousseau.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ import rousseau from "rousseau";
const defaultOptions = {
// "suggestion", "warning", "error"
showLevels: ["suggestion", "warning", "error"],
ignoreTypes: []
ignoreTypes: [],
fakeInlineCode: true
};
export default function textlintRousseau(context, options) {
const helper = new RuleHelper(context);
const {Syntax, RuleError, report, getSource} = context;
const showLevels = options.showLevels || defaultOptions.showLevels;
const ignoreTypes = options.ignoreTypes || defaultOptions.ignoreTypes;
const fakeInlineCode = options.fakeInlineCode || defaultOptions.fakeInlineCode;
const isShowType = (type)=> {
return ignoreTypes.indexOf(type) === -1;
};
Expand Down Expand Up @@ -77,10 +79,21 @@ export default function textlintRousseau(context, options) {
if (helper.isChildNode(node, [Syntax.Link, Syntax.Image, Syntax.BlockQuote, Syntax.Emphasis])) {
return;
}
// remove Code
node.children = node.children.filter(childNode => {
return childNode.type !== Syntax.Code;
});
// fake `code`
if (fakeInlineCode) {
node.children = node.children.map(childNode => {
if (childNode.type === Syntax.Code) {
return {
type: Syntax.Str,
value: "code",
raw: "code",
loc: childNode.loc,
range: childNode.range
}
}
return childNode;
});
}
const source = new StringSource(node);
const text = source.toString();
const reportSourceError = reportError.bind(null, node, source);
Expand Down

0 comments on commit 2066eb4

Please sign in to comment.