33const { RuleHelper} = require ( "textlint-rule-helper" ) ;
44const StringSource = require ( "textlint-util-to-string" ) . default ;
55const rousseau = require ( "rousseau" ) ;
6- const filter = require ( 'unist-util-filter' ) ;
6+ const ObjectAssign = require ( "object-assign" ) ;
77const defaultOptions = {
88 // "suggestion", "warning", "error"
99 showLevels : [ "suggestion" , "warning" , "error" ] ,
@@ -12,12 +12,25 @@ const defaultOptions = {
1212 // ignore textlint's node type
1313 ignoreInlineNodeTypes : undefined
1414} ;
15+
16+ const mapNode = function ( ast , mapFn ) {
17+ return ( function preorder ( node , index , parent ) {
18+ const newNode = ObjectAssign ( { } , mapFn ( node , index , parent ) ) ;
19+ if ( node . children ) {
20+ newNode . children = node . children . map ( function ( child , index ) {
21+ return preorder ( child , index , node ) ;
22+ } ) ;
23+ }
24+ return newNode ;
25+ } ( ast , null , null ) ) ;
26+ } ;
27+
1528export default function textlintRousseau ( context , options = defaultOptions ) {
1629 const helper = new RuleHelper ( context ) ;
1730 const { Syntax, RuleError, report, getSource} = context ;
1831 const showLevels = options . showLevels || defaultOptions . showLevels ;
1932 const ignoreTypes = options . ignoreTypes || defaultOptions . ignoreTypes ;
20- const ignoreInlineNodeTypes = options . ignoreInlineNodeTypes || [ Syntax . Image , Syntax . Code , Syntax . Link ] ;
33+ const ignoreInlineNodeTypes = options . ignoreInlineNodeTypes || [ Syntax . Code ] ;
2134 const isShowType = ( type ) => {
2235 return ignoreTypes . indexOf ( type ) === - 1 ;
2336 } ;
@@ -82,8 +95,17 @@ export default function textlintRousseau(context, options = defaultOptions) {
8295 if ( helper . isChildNode ( node , [ Syntax . Link , Syntax . Image , Syntax . BlockQuote , Syntax . Emphasis ] ) ) {
8396 return ;
8497 }
85- const filteredNode = filter ( node , ( node ) => {
86- return ignoreInlineNodeTypes . indexOf ( node . type ) === - 1 ;
98+ const filteredNode = mapNode ( node , ( node ) => {
99+ const index = ignoreInlineNodeTypes . indexOf ( node . type ) ;
100+ if ( index === - 1 ) {
101+ return node ;
102+ }
103+ /*
104+ `xxx` => code
105+ */
106+ return ObjectAssign ( { } , node , {
107+ value : node . type . toLocaleLowerCase ( )
108+ } ) ;
87109 } ) ;
88110 if ( ! filteredNode ) {
89111 return ;
0 commit comments