@@ -20,7 +20,12 @@ const defaultOptions = {
2020 allowEmojiAtEnd : false ,
2121 // 句点で終わって無い場合に`periodMark`を--fix時に追加するかどうか
2222 // デフォルトでは自動的に追加しない
23- forceAppendPeriod : false
23+ forceAppendPeriod : false ,
24+ // [Note] このオプションは標準外なので隠しオプション扱い
25+ // [Warning] このオプションはsemverの範囲外なのでいつでも壊れる可能性がある
26+ // 脚注はチェック対象から外すかどうか(実質Re:View向け)
27+ // デフォルトでは脚注構文(Re:View)は無視する
28+ checkFootnote : false
2429} ;
2530const reporter = ( context , options = { } ) => {
2631 const { Syntax, RuleError, report, fixer, getSource } = context ;
@@ -29,18 +34,29 @@ const reporter = (context, options = {}) => {
2934 const preferPeriodMark = options . periodMark || defaultOptions . periodMark ;
3035 // 優先する句点記号は常に句点として許可される
3136 const allowPeriodMarks = ( options . allowPeriodMarks || defaultOptions . allowPeriodMarks ) . concat ( preferPeriodMark ) ;
32- const allowEmojiAtEnd = options . allowEmojiAtEnd !== undefined
33- ? options . allowEmojiAtEnd
34- : defaultOptions . allowEmojiAtEnd ;
35- const forceAppendPeriod = options . forceAppendPeriod !== undefined
36- ? options . forceAppendPeriod
37- : defaultOptions . forceAppendPeriod ;
38-
39- const ignoredNodeTypes = [
40- Syntax . ListItem , Syntax . Link , Syntax . Code , Syntax . Image , Syntax . BlockQuote , Syntax . Emphasis
37+ const allowEmojiAtEnd =
38+ options . allowEmojiAtEnd !== undefined ? options . allowEmojiAtEnd : defaultOptions . allowEmojiAtEnd ;
39+ const forceAppendPeriod =
40+ options . forceAppendPeriod !== undefined ? options . forceAppendPeriod : defaultOptions . forceAppendPeriod ;
41+ const checkFootnote = options . checkFootnote !== undefined ? options . checkFootnote : defaultOptions . checkFootnote ;
42+ // 脚注のNode Typeを定義(TxtASTの定義外)
43+ const FootnoteNodes = [
44+ // https://github.com/orangain/textlint-plugin-review
45+ "Footnote" ,
46+ // https://github.com/textlint/textlint/blob/master/packages/%40textlint/markdown-to-ast/src/mapping/markdown-syntax-map.js
47+ // 実際にはmarkdown-to-astではこれはParagraphを含まないInlineNodeなのであまり意味はない
48+ "Definition"
4149 ] ;
50+ const ignoredNodeTypes = [
51+ Syntax . ListItem ,
52+ Syntax . Link ,
53+ Syntax . Code ,
54+ Syntax . Image ,
55+ Syntax . BlockQuote ,
56+ Syntax . Emphasis
57+ ] . concat ( checkFootnote ? FootnoteNodes : [ ] ) ;
4258 return {
43- [ Syntax . Paragraph ] ( node ) {
59+ [ Syntax . Paragraph ] ( node ) {
4460 if ( helper . isChildNode ( node , ignoredNodeTypes ) ) {
4561 return ;
4662 }
@@ -66,35 +82,47 @@ const reporter = (context, options = {}) => {
6682 }
6783 // 文末がスペースである場合はスペースを削除する
6884 if ( / \s / . test ( periodMark ) ) {
69- report ( lastNode , new RuleError ( `文末が"${ preferPeriodMark } "で終わっていません。末尾に不要なスペースがあります。` , {
70- index,
71- fix : fixer . replaceTextRange ( [ index , index + periodMark . length ] , "" )
72- } ) ) ;
73- return
85+ report (
86+ lastNode ,
87+ new RuleError ( `文末が"${ preferPeriodMark } "で終わっていません。末尾に不要なスペースがあります。` , {
88+ index,
89+ fix : fixer . replaceTextRange ( [ index , index + periodMark . length ] , "" )
90+ } )
91+ ) ;
92+ return ;
7493 }
7594 // 典型的なパターンは自動的に`preferPeriodMark`に置き換える
7695 // 例) "." であるなら "。"に変換
7796 if ( classicPeriodMarkPattern . test ( periodMark ) ) {
78- report ( lastNode , new RuleError ( `文末が"${ preferPeriodMark } "で終わっていません。` , {
79- index : index ,
80- fix : fixer . replaceTextRange ( [ index , index + preferPeriodMark . length ] , preferPeriodMark )
81- } ) ) ;
97+ report (
98+ lastNode ,
99+ new RuleError ( `文末が"${ preferPeriodMark } "で終わっていません。` , {
100+ index : index ,
101+ fix : fixer . replaceTextRange ( [ index , index + preferPeriodMark . length ] , preferPeriodMark )
102+ } )
103+ ) ;
82104 } else {
83105 // 句点を忘れているパターン
84106 if ( forceAppendPeriod ) {
85107 // `forceAppendPeriod`のオプションがtrueならば、自動で句点を追加する。
86- report ( lastNode , new RuleError ( `文末が"${ preferPeriodMark } "で終わっていません。` , {
87- index : index ,
88- fix : fixer . replaceTextRange ( [ index + 1 , index + 1 ] , preferPeriodMark )
89- } ) ) ;
108+ report (
109+ lastNode ,
110+ new RuleError ( `文末が"${ preferPeriodMark } "で終わっていません。` , {
111+ index : index ,
112+ fix : fixer . replaceTextRange ( [ index + 1 , index + 1 ] , preferPeriodMark )
113+ } )
114+ ) ;
90115 } else {
91- report ( lastNode , new RuleError ( `文末が"${ preferPeriodMark } "で終わっていません。` , {
92- index : index
93- } ) ) ;
116+ report (
117+ lastNode ,
118+ new RuleError ( `文末が"${ preferPeriodMark } "で終わっていません。` , {
119+ index : index
120+ } )
121+ ) ;
94122 }
95123 }
96124 }
97- }
125+ } ;
98126} ;
99127
100128module . exports = {
0 commit comments