Skip to content

Commit 2da12a6

Browse files
committed
Now code caption is supported by the last period checker.
1 parent 125aa36 commit 2da12a6

File tree

2 files changed

+82
-0
lines changed

2 files changed

+82
-0
lines changed

src/Microdown-Rules/MicLastPeriodInCaptionChecker.class.st

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,21 @@ Class {
2828
#tag : 'CodeLastPeriod'
2929
}
3030

31+
{ #category : 'visiting - inline elements' }
32+
MicLastPeriodInCaptionChecker >> checkExtraPeriodInCode: aCode [
33+
"we should revise the API of elements to be able to identify adorment for Equation, Figure and code block."
34+
35+
| captionText |
36+
captionText := self computeMathCaptionOf: aCode.
37+
captionText ifEmpty: [ ^ self ].
38+
39+
captionText trimRight last = $. ifTrue: [
40+
results add: (MicPeriodInCaptionResult new
41+
micElement: aCode;
42+
inFile: aCode fromFile;
43+
codeShouldEndWithPeriod: codeShouldEndWithPeriod) ]
44+
]
45+
3146
{ #category : 'visiting - inline elements' }
3247
MicLastPeriodInCaptionChecker >> checkExtraPeriodInFigure: aFigure [
3348
"we should revise the API of elements to be able to identify adorment for Equation, Figure and code block."
@@ -53,6 +68,20 @@ MicLastPeriodInCaptionChecker >> checkExtraPeriodInMath: aMath [
5368
codeShouldEndWithPeriod: codeShouldEndWithPeriod) ]
5469
]
5570

71+
{ #category : 'visiting - inline elements' }
72+
MicLastPeriodInCaptionChecker >> checkMissingPeriodInCode: aCode [
73+
74+
| captionText |
75+
captionText := self computeMathCaptionOf: aCode.
76+
captionText ifEmpty: [ ^ self ].
77+
78+
captionText trimRight last = $. ifFalse: [
79+
results add: (MicPeriodInCaptionResult new
80+
micElement: aCode;
81+
inFile: aCode fromFile;
82+
codeShouldEndWithPeriod: codeShouldEndWithPeriod) ]
83+
]
84+
5685
{ #category : 'visiting - inline elements' }
5786
MicLastPeriodInCaptionChecker >> checkMissingPeriodInFigure: aFigure [
5887

@@ -84,6 +113,17 @@ MicLastPeriodInCaptionChecker >> computeMathCaptionOf: aMath [
84113
^ ' ' join: (aMath captionElements collect: [ :each | each text ])
85114
]
86115

116+
{ #category : 'visiting - inline elements' }
117+
MicLastPeriodInCaptionChecker >> visitCode: anEquation [
118+
"we should revise the API of elements to be able to identify adorment for Equation, Figure and code block."
119+
120+
"this way we could share the same logic between all the elements."
121+
122+
codeShouldEndWithPeriod
123+
ifTrue: [ self checkMissingPeriodInCode: anEquation ]
124+
ifFalse: [ self checkExtraPeriodInCode: anEquation ]
125+
]
126+
87127
{ #category : 'visiting - inline elements' }
88128
MicLastPeriodInCaptionChecker >> visitFigure: aFigure [
89129

src/Microdown-Rules/MicLastPeriodInCaptionCheckerTest.class.st

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,48 @@ MicLastPeriodInCaptionCheckerTest >> setUp [
7777
checker := MicLastPeriodInCaptionChecker new
7878
]
7979

80+
{ #category : 'tests - missing period' }
81+
MicLastPeriodInCaptionCheckerTest >> testCodeCheckerChecksCorrectlyMissingExtraPeriod [
82+
83+
checker identifyMissingLastPeriod.
84+
checker checkProject: fileSystem / 'codeCaptionEndingWithPeriod.md'.
85+
self assert: checker isOkay
86+
]
87+
88+
{ #category : 'tests - extra period' }
89+
MicLastPeriodInCaptionCheckerTest >> testCodeCheckerChecksCorrectlyNoExtraPeriod [
90+
91+
checker identifyExtraLastPeriod.
92+
checker checkProject: fileSystem / 'codeCaptionMissingPeriod.md'.
93+
self assert: checker isOkay
94+
]
95+
96+
{ #category : 'tests - extra period' }
97+
MicLastPeriodInCaptionCheckerTest >> testCodeCheckerIdentifyCorrectlyExtraPeriod [
98+
99+
checker identifyExtraLastPeriod.
100+
checker checkProject: fileSystem / 'codeCaptionEndingWithPeriod.md'.
101+
self deny: checker isOkay.
102+
103+
self
104+
assert: checker results first explanation
105+
equals:
106+
'Text: "This is the famous correctly ending period." in file/codeCaptionEndingWithPeriod.md contains a mistake: Captions should not be terminated with a period (.).'
107+
]
108+
109+
{ #category : 'tests - missing period' }
110+
MicLastPeriodInCaptionCheckerTest >> testCodeCheckerIdentifyCorrectlyMissingExtraPeriod [
111+
112+
checker identifyMissingLastPeriod.
113+
checker checkProject: fileSystem / 'codeCaptionMissingPeriod.md'.
114+
self deny: checker isOkay.
115+
116+
self
117+
assert: checker results first explanation
118+
equals:
119+
'Text: "This is the famous missing period" in file/codeCaptionMissingPeriod.md contains a mistake: Captions should be terminated with a period (.).'
120+
]
121+
80122
{ #category : 'tests - missing period' }
81123
MicLastPeriodInCaptionCheckerTest >> testFigureCheckerChecksCorrectlyMissingExtraPeriod [
82124

0 commit comments

Comments
 (0)