Skip to content

Commit 2066eb4

Browse files
committed
feat(options): add fakeInlineCode option
1 parent b4d7d88 commit 2066eb4

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

src/textlint-rule-rousseau.js

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@ import rousseau from "rousseau";
66
const defaultOptions = {
77
// "suggestion", "warning", "error"
88
showLevels: ["suggestion", "warning", "error"],
9-
ignoreTypes: []
9+
ignoreTypes: [],
10+
fakeInlineCode: true
1011
};
1112
export default function textlintRousseau(context, options) {
1213
const helper = new RuleHelper(context);
1314
const {Syntax, RuleError, report, getSource} = context;
1415
const showLevels = options.showLevels || defaultOptions.showLevels;
1516
const ignoreTypes = options.ignoreTypes || defaultOptions.ignoreTypes;
17+
const fakeInlineCode = options.fakeInlineCode || defaultOptions.fakeInlineCode;
1618
const isShowType = (type)=> {
1719
return ignoreTypes.indexOf(type) === -1;
1820
};
@@ -77,10 +79,21 @@ export default function textlintRousseau(context, options) {
7779
if (helper.isChildNode(node, [Syntax.Link, Syntax.Image, Syntax.BlockQuote, Syntax.Emphasis])) {
7880
return;
7981
}
80-
// remove Code
81-
node.children = node.children.filter(childNode => {
82-
return childNode.type !== Syntax.Code;
83-
});
82+
// fake `code`
83+
if (fakeInlineCode) {
84+
node.children = node.children.map(childNode => {
85+
if (childNode.type === Syntax.Code) {
86+
return {
87+
type: Syntax.Str,
88+
value: "code",
89+
raw: "code",
90+
loc: childNode.loc,
91+
range: childNode.range
92+
}
93+
}
94+
return childNode;
95+
});
96+
}
8497
const source = new StringSource(node);
8598
const text = source.toString();
8699
const reportSourceError = reportError.bind(null, node, source);

0 commit comments

Comments
 (0)