From e69277b396286dee2d15ec3137832ea394b7322f Mon Sep 17 00:00:00 2001 From: "antoine.usal" Date: Mon, 4 May 2026 15:06:45 +0200 Subject: [PATCH 1/9] Add new checker : MicFigureCaption --- .../MicFigureCaptionChecker.class.st | 19 ++++++ .../MicFigureCaptionCheckerTest.class.st | 66 +++++++++++++++++++ .../MicMissingFigureCaptionResult.class.st | 19 ++++++ 3 files changed, 104 insertions(+) create mode 100644 src/Microdown-BookTester/MicFigureCaptionChecker.class.st create mode 100644 src/Microdown-BookTester/MicFigureCaptionCheckerTest.class.st create mode 100644 src/Microdown-BookTester/MicMissingFigureCaptionResult.class.st diff --git a/src/Microdown-BookTester/MicFigureCaptionChecker.class.st b/src/Microdown-BookTester/MicFigureCaptionChecker.class.st new file mode 100644 index 000000000..0c01e54aa --- /dev/null +++ b/src/Microdown-BookTester/MicFigureCaptionChecker.class.st @@ -0,0 +1,19 @@ +Class { + #name : 'MicFigureCaptionChecker', + #superclass : 'MicChecker', + #category : 'Microdown-BookTester', + #package : 'Microdown-BookTester' +} + +{ #category : 'visiting - inline elements' } +MicFigureCaptionChecker >> visitFigure: aFigure [ + | captionText | + captionText := String streamContents: [ :stream | + aFigure children do: [ :child | stream nextPutAll: child plainText ] ]. + (captionText isEmpty or: [ (captionText anySatisfy: #isAlphaNumeric) not ]) ifTrue: [ + self results add: (MicMissingFigureCaptionResult new + figure: aFigure; + yourself) ]. + + ^ super visitFigure: aFigure +] diff --git a/src/Microdown-BookTester/MicFigureCaptionCheckerTest.class.st b/src/Microdown-BookTester/MicFigureCaptionCheckerTest.class.st new file mode 100644 index 000000000..454496ba6 --- /dev/null +++ b/src/Microdown-BookTester/MicFigureCaptionCheckerTest.class.st @@ -0,0 +1,66 @@ +Class { + #name : 'MicFigureCaptionCheckerTest', + #superclass : 'TestCase', + #instVars : [ + 'results' + ], + #category : 'Microdown-BookTester', + #package : 'Microdown-BookTester' +} + +{ #category : 'tests' } +MicFigureCaptionCheckerTest >> testCaptionIsEmpty [ + | visitor mdFile mem | + mem := FileSystem memory root. + mdFile := mem / 'test.md'. + mdFile writeStreamDo: [ :stream | stream nextPutAll: '![](/fig.png)' ]. + + visitor := MicFigureCaptionChecker new. + visitor rootDirectory: mem. + visitor checkProject: mdFile. + + self assert: visitor results size equals: 1. + self assert: visitor results first class name equals: #MicMissingFigureCaptionResult. +] + +{ #category : 'tests' } +MicFigureCaptionCheckerTest >> testCaptionIsOnlyPunctuationAndSpaces [ + | visitor mdFile mem | + mem := FileSystem memory root. + mdFile := mem / 'test.md'. + mdFile writeStreamDo: [ :stream | stream nextPutAll: '![ , ; ](/fig.png)' ]. + + visitor := MicFigureCaptionChecker new. + visitor rootDirectory: mem. + visitor checkProject: mdFile. + + self assert: visitor results size equals: 1. + self assert: visitor results first class name equals: #MicMissingFigureCaptionResult. +] + +{ #category : 'tests' } +MicFigureCaptionCheckerTest >> testCaptionIsOnlySpaces [ + | visitor mdFile mem | + mem := FileSystem memory root. + mdFile := mem / 'test.md'. + mdFile writeStreamDo: [ :stream | stream nextPutAll: '![ ](/fig.png)' ]. + visitor := MicFigureCaptionChecker new. + visitor rootDirectory: mem. + visitor checkProject: mdFile. + + self assert: visitor results size equals: 1. +] + +{ #category : 'tests' } +MicFigureCaptionCheckerTest >> testCaptionIsValid [ + | visitor mdFile mem | + mem := FileSystem memory root. + mdFile := mem / 'test.md'. + mdFile writeStreamDo: [ :stream | stream nextPutAll: '![Une vraie légende](fig.png)' ]. + + visitor := MicFigureCaptionChecker new. + visitor rootDirectory: mem. + visitor checkProject: mdFile. + + self assert: visitor results isEmpty. +] diff --git a/src/Microdown-BookTester/MicMissingFigureCaptionResult.class.st b/src/Microdown-BookTester/MicMissingFigureCaptionResult.class.st new file mode 100644 index 000000000..efacc897f --- /dev/null +++ b/src/Microdown-BookTester/MicMissingFigureCaptionResult.class.st @@ -0,0 +1,19 @@ +Class { + #name : 'MicMissingFigureCaptionResult', + #superclass : 'MicResult', + #instVars : [ + 'figure' + ], + #category : 'Microdown-BookTester', + #package : 'Microdown-BookTester' +} + +{ #category : 'accessing' } +MicMissingFigureCaptionResult >> figure [ + ^ figure +] + +{ #category : 'accessing' } +MicMissingFigureCaptionResult >> figure: aFigure [ + figure := aFigure +] From 3456057f9fd22216e6467b874e0c3d43e5f3deba Mon Sep 17 00:00:00 2001 From: "antoine.usal" Date: Mon, 4 May 2026 16:18:20 +0200 Subject: [PATCH 2/9] Missing some tests --- .../MicFigureCaptionChecker.class.st | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/Microdown-BookTester/MicFigureCaptionChecker.class.st b/src/Microdown-BookTester/MicFigureCaptionChecker.class.st index 0c01e54aa..0a220180c 100644 --- a/src/Microdown-BookTester/MicFigureCaptionChecker.class.st +++ b/src/Microdown-BookTester/MicFigureCaptionChecker.class.st @@ -5,6 +5,18 @@ Class { #package : 'Microdown-BookTester' } +{ #category : 'visiting - inline elements' } +MicFigureCaptionChecker >> visitCode: aCode [ + | captionText | + captionText := ' ' join: (aCode captionElements collect: [ :each | each text ]). + (captionText isEmpty or: [ (captionText anySatisfy: #isAlphaNumeric) not ]) ifTrue: [ + self results add: (MicMissingFigureCaptionResult new + figure: aCode; + yourself) ]. + + ^ super visitCode: aCode +] + { #category : 'visiting - inline elements' } MicFigureCaptionChecker >> visitFigure: aFigure [ | captionText | @@ -17,3 +29,15 @@ MicFigureCaptionChecker >> visitFigure: aFigure [ ^ super visitFigure: aFigure ] + +{ #category : 'visiting - inline elements' } +MicFigureCaptionChecker >> visitMath: aMath [ + | captionText | + captionText := ' ' join: (aMath captionElements collect: [ :each | each text ]). + (captionText isEmpty or: [ (captionText anySatisfy: #isAlphaNumeric) not ]) ifTrue: [ + self results add: (MicMissingFigureCaptionResult new + figure: aMath; + yourself) ]. + + ^ super visitMath: aMath +] From c839fab2091d93e2868cdeeda6b61ceaba0075b1 Mon Sep 17 00:00:00 2001 From: "antoine.usal" Date: Tue, 5 May 2026 15:47:40 +0200 Subject: [PATCH 3/9] upgrade checker MicFigure --- .../MicFigureCaptionChecker.class.st | 92 +++++++++++++++---- .../MicFigureCaptionCheckerTest.class.st | 34 +++++++ 2 files changed, 107 insertions(+), 19 deletions(-) diff --git a/src/Microdown-BookTester/MicFigureCaptionChecker.class.st b/src/Microdown-BookTester/MicFigureCaptionChecker.class.st index 0a220180c..7061b0eb5 100644 --- a/src/Microdown-BookTester/MicFigureCaptionChecker.class.st +++ b/src/Microdown-BookTester/MicFigureCaptionChecker.class.st @@ -1,43 +1,97 @@ Class { #name : 'MicFigureCaptionChecker', #superclass : 'MicChecker', + #instVars : [ + 'checkFigure', + 'checkCode', + 'checkMath' + ], #category : 'Microdown-BookTester', #package : 'Microdown-BookTester' } +{ #category : 'accessing' } +MicFigureCaptionChecker >> checkCode [ + + ^ checkCode +] + +{ #category : 'accessing' } +MicFigureCaptionChecker >> checkCode: anObject [ + + checkCode := anObject +] + +{ #category : 'accessing' } +MicFigureCaptionChecker >> checkFigure [ + + ^ checkFigure +] + +{ #category : 'accessing' } +MicFigureCaptionChecker >> checkFigure: anObject [ + + checkFigure := anObject +] + +{ #category : 'accessing' } +MicFigureCaptionChecker >> checkMath [ + + ^ checkMath +] + +{ #category : 'accessing' } +MicFigureCaptionChecker >> checkMath: anObject [ + + checkMath := anObject +] + { #category : 'visiting - inline elements' } -MicFigureCaptionChecker >> visitCode: aCode [ - | captionText | - captionText := ' ' join: (aCode captionElements collect: [ :each | each text ]). +MicFigureCaptionChecker >> checkMissingCaptionIn: aBlock text: captionText [ (captionText isEmpty or: [ (captionText anySatisfy: #isAlphaNumeric) not ]) ifTrue: [ self results add: (MicMissingFigureCaptionResult new - figure: aCode; - yourself) ]. - + figure: aBlock; + yourself) ] +] + +{ #category : 'visiting - inline elements' } +MicFigureCaptionChecker >> initialize [ + super initialize. + checkFigure := true. + checkCode := true. + checkMath := true. +] + +{ #category : 'visiting - inline elements' } +MicFigureCaptionChecker >> visitCode: aCode [ + | captionText | + + self checkCode ifTrue: [ + captionText := ' ' join: (aCode captionElements collect: [ :each | each text ]). + self checkMissingCaptionIn: aCode text: captionText ]. + ^ super visitCode: aCode ] { #category : 'visiting - inline elements' } MicFigureCaptionChecker >> visitFigure: aFigure [ | captionText | - captionText := String streamContents: [ :stream | - aFigure children do: [ :child | stream nextPutAll: child plainText ] ]. - (captionText isEmpty or: [ (captionText anySatisfy: #isAlphaNumeric) not ]) ifTrue: [ - self results add: (MicMissingFigureCaptionResult new - figure: aFigure; - yourself) ]. - + + self checkFigure ifTrue: [ + captionText := String streamContents: [ :stream | + aFigure children do: [ :child | stream nextPutAll: child plainText ] ]. + self checkMissingCaptionIn: aFigure text: captionText ]. + ^ super visitFigure: aFigure ] { #category : 'visiting - inline elements' } MicFigureCaptionChecker >> visitMath: aMath [ | captionText | - captionText := ' ' join: (aMath captionElements collect: [ :each | each text ]). - (captionText isEmpty or: [ (captionText anySatisfy: #isAlphaNumeric) not ]) ifTrue: [ - self results add: (MicMissingFigureCaptionResult new - figure: aMath; - yourself) ]. - + + self checkMath ifTrue: [ + captionText := ' ' join: (aMath captionElements collect: [ :each | each text ]). + self checkMissingCaptionIn: aMath text: captionText ]. + ^ super visitMath: aMath ] diff --git a/src/Microdown-BookTester/MicFigureCaptionCheckerTest.class.st b/src/Microdown-BookTester/MicFigureCaptionCheckerTest.class.st index 454496ba6..3372598e2 100644 --- a/src/Microdown-BookTester/MicFigureCaptionCheckerTest.class.st +++ b/src/Microdown-BookTester/MicFigureCaptionCheckerTest.class.st @@ -64,3 +64,37 @@ MicFigureCaptionCheckerTest >> testCaptionIsValid [ self assert: visitor results isEmpty. ] + +{ #category : 'tests' } +MicFigureCaptionCheckerTest >> testCodeBlockCaptionIsOnlySpaces [ + | visitor mdFile mem | + mem := FileSystem memory root. + mdFile := mem / 'test.md'. + mdFile writeStreamDo: [ :stream | + stream nextPutAll: '```smalltalk&caption= '; cr. + stream nextPutAll: '1 + 1'; cr. + stream nextPutAll: '```' ]. + + visitor := MicFigureCaptionChecker new. + visitor rootDirectory: mem. + visitor checkProject: mdFile. + + self assert: visitor results size equals: 1. +] + +{ #category : 'tests' } +MicFigureCaptionCheckerTest >> testMathBlockCaptionIsEmpty [ + | visitor mdFile mem | + mem := FileSystem memory root. + mdFile := mem / 'test.md'. + mdFile writeStreamDo: [ :stream | + stream nextPutAll: '$$&caption='; cr. + stream nextPutAll: 'V = \frac{4}{3}\pi r^3'; cr. + stream nextPutAll: '$$' ]. + + visitor := MicFigureCaptionChecker new. + visitor rootDirectory: mem. + visitor checkProject: mdFile. + + self assert: visitor results size equals: 1. +] From fc7934ce098a629a2659374656118e8d50cbe259 Mon Sep 17 00:00:00 2001 From: "antoine.usal" Date: Wed, 6 May 2026 10:39:59 +0200 Subject: [PATCH 4/9] Some changes for MicFigureCaption --- .../MicFigureCaptionChecker.class.st | 31 ++++++------------- .../MicFigureCaptionCheckerTest.class.st | 4 +-- 2 files changed, 11 insertions(+), 24 deletions(-) diff --git a/src/Microdown-BookTester/MicFigureCaptionChecker.class.st b/src/Microdown-BookTester/MicFigureCaptionChecker.class.st index 7061b0eb5..c77cc208a 100644 --- a/src/Microdown-BookTester/MicFigureCaptionChecker.class.st +++ b/src/Microdown-BookTester/MicFigureCaptionChecker.class.st @@ -64,34 +64,21 @@ MicFigureCaptionChecker >> initialize [ { #category : 'visiting - inline elements' } MicFigureCaptionChecker >> visitCode: aCode [ - | captionText | - - self checkCode ifTrue: [ - captionText := ' ' join: (aCode captionElements collect: [ :each | each text ]). - self checkMissingCaptionIn: aCode text: captionText ]. - - ^ super visitCode: aCode + self checkCode ifTrue: [ + (self hasCorrectCaption: aCode caption) ifFalse: [ + self results add: MicMissingFigureCaptionResult new ] ] ] { #category : 'visiting - inline elements' } MicFigureCaptionChecker >> visitFigure: aFigure [ - | captionText | - - self checkFigure ifTrue: [ - captionText := String streamContents: [ :stream | - aFigure children do: [ :child | stream nextPutAll: child plainText ] ]. - self checkMissingCaptionIn: aFigure text: captionText ]. - - ^ super visitFigure: aFigure + self checkFigure ifTrue: [ + (self hasCorrectCaption: aFigure caption) ifFalse: [ + self results add: MicMissingFigureCaptionResult new ] ] ] { #category : 'visiting - inline elements' } MicFigureCaptionChecker >> visitMath: aMath [ - | captionText | - - self checkMath ifTrue: [ - captionText := ' ' join: (aMath captionElements collect: [ :each | each text ]). - self checkMissingCaptionIn: aMath text: captionText ]. - - ^ super visitMath: aMath + self checkMath ifTrue: [ + (self hasCorrectCaption: aMath caption) ifFalse: [ + self results add: MicMissingFigureCaptionResult new ] ] ] diff --git a/src/Microdown-BookTester/MicFigureCaptionCheckerTest.class.st b/src/Microdown-BookTester/MicFigureCaptionCheckerTest.class.st index 3372598e2..f6f56ddcd 100644 --- a/src/Microdown-BookTester/MicFigureCaptionCheckerTest.class.st +++ b/src/Microdown-BookTester/MicFigureCaptionCheckerTest.class.st @@ -69,7 +69,7 @@ MicFigureCaptionCheckerTest >> testCaptionIsValid [ MicFigureCaptionCheckerTest >> testCodeBlockCaptionIsOnlySpaces [ | visitor mdFile mem | mem := FileSystem memory root. - mdFile := mem / 'test.md'. + mdFile := mem / 'bogusCaption.md'. mdFile writeStreamDo: [ :stream | stream nextPutAll: '```smalltalk&caption= '; cr. stream nextPutAll: '1 + 1'; cr. @@ -86,7 +86,7 @@ MicFigureCaptionCheckerTest >> testCodeBlockCaptionIsOnlySpaces [ MicFigureCaptionCheckerTest >> testMathBlockCaptionIsEmpty [ | visitor mdFile mem | mem := FileSystem memory root. - mdFile := mem / 'test.md'. + mdFile := mem / 'emptyCaption.md'. mdFile writeStreamDo: [ :stream | stream nextPutAll: '$$&caption='; cr. stream nextPutAll: 'V = \frac{4}{3}\pi r^3'; cr. From e39a59056b2ce9913f7a0c19a8651b2f50fcc524 Mon Sep 17 00:00:00 2001 From: "antoine.usal" Date: Wed, 6 May 2026 15:21:08 +0200 Subject: [PATCH 5/9] Fix git error --- .../MicFigureCaptionChecker.class.st | 18 ++++++++++++++++++ src/Microdown/MicFigureBlock.class.st | 5 +++++ 2 files changed, 23 insertions(+) diff --git a/src/Microdown-BookTester/MicFigureCaptionChecker.class.st b/src/Microdown-BookTester/MicFigureCaptionChecker.class.st index c77cc208a..e42f92f6d 100644 --- a/src/Microdown-BookTester/MicFigureCaptionChecker.class.st +++ b/src/Microdown-BookTester/MicFigureCaptionChecker.class.st @@ -54,6 +54,24 @@ MicFigureCaptionChecker >> checkMissingCaptionIn: aBlock text: captionText [ yourself) ] ] +{ #category : 'visiting - inline elements' } +MicFigureCaptionChecker >> configureFrom: aConfiguration [ + super configureFrom: aConfiguration. + checkFigure := aConfiguration propertyAt: #checkFigure ifAbsent: [ true ]. + checkCode := aConfiguration propertyAt: #checkCode ifAbsent: [ true ]. + checkMath := aConfiguration propertyAt: #checkMath ifAbsent: [ true ]. +] + +{ #category : 'visiting - inline elements' } +MicFigureCaptionChecker >> explanationForConfiguration [ + ^ 'I check that figures, math environments and code blocks have a valid and non-empty caption.' +] + +{ #category : 'visiting - inline elements' } +MicFigureCaptionChecker >> hasCorrectCaption: aCaptionText [ + ^ aCaptionText isNotEmpty and: [ aCaptionText anySatisfy: #isAlphaNumeric ] +] + { #category : 'visiting - inline elements' } MicFigureCaptionChecker >> initialize [ super initialize. diff --git a/src/Microdown/MicFigureBlock.class.st b/src/Microdown/MicFigureBlock.class.st index b100f286a..8dd4a8b00 100644 --- a/src/Microdown/MicFigureBlock.class.st +++ b/src/Microdown/MicFigureBlock.class.st @@ -40,6 +40,11 @@ MicFigureBlock >> altText [ ^ (self children collect: #plainText) joinUsing: ' ' ] +{ #category : 'accessing' } +MicFigureBlock >> caption [ + ^ ' ' join: (self captionElements collect: [ :each | each text ]) +] + { #category : 'visiting' } MicFigureBlock >> closeMe [ From 020acab3a6a2d743345bcfde1730ff657e9d5f83 Mon Sep 17 00:00:00 2001 From: "antoine.usal" Date: Thu, 7 May 2026 11:56:25 +0200 Subject: [PATCH 6/9] add 2 tests --- .../MicFigureCaptionCheckerTest.class.st | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/Microdown-BookTester/MicFigureCaptionCheckerTest.class.st b/src/Microdown-BookTester/MicFigureCaptionCheckerTest.class.st index f6f56ddcd..f5a6f8df6 100644 --- a/src/Microdown-BookTester/MicFigureCaptionCheckerTest.class.st +++ b/src/Microdown-BookTester/MicFigureCaptionCheckerTest.class.st @@ -82,6 +82,33 @@ MicFigureCaptionCheckerTest >> testCodeBlockCaptionIsOnlySpaces [ self assert: visitor results size equals: 1. ] +{ #category : 'tests' } +MicFigureCaptionCheckerTest >> testDocumentWithOnlyText [ + | visitor mdFile mem | + mem := FileSystem memory root. + mdFile := mem / 'test.md'. + + mdFile writeStreamDo: [ :stream | + stream nextPutAll: '# Mon chapitre'; cr. + stream nextPutAll: 'Voici du texte tout à fait normal, sans aucune figure ni bloc de code.' ]. + + visitor := MicFigureCaptionChecker new. + visitor rootDirectory: mem. + visitor checkProject: mdFile. + + self assert: visitor results isEmpty. +] + +{ #category : 'tests' } +MicFigureCaptionCheckerTest >> testInitializationDefaults [ + | checker | + checker := MicFigureCaptionChecker new. + + self assert: checker checkFigure. + self assert: checker checkCode. + self assert: checker checkMath. +] + { #category : 'tests' } MicFigureCaptionCheckerTest >> testMathBlockCaptionIsEmpty [ | visitor mdFile mem | From 377e34759c8b69a45a5be3c08b0cd2e864fbdc70 Mon Sep 17 00:00:00 2001 From: "antoine.usal" Date: Thu, 7 May 2026 12:34:28 +0200 Subject: [PATCH 7/9] remove --- .../MicFigureCaptionCheckerTest.class.st | 27 ------------------- 1 file changed, 27 deletions(-) diff --git a/src/Microdown-BookTester/MicFigureCaptionCheckerTest.class.st b/src/Microdown-BookTester/MicFigureCaptionCheckerTest.class.st index f5a6f8df6..f6f56ddcd 100644 --- a/src/Microdown-BookTester/MicFigureCaptionCheckerTest.class.st +++ b/src/Microdown-BookTester/MicFigureCaptionCheckerTest.class.st @@ -82,33 +82,6 @@ MicFigureCaptionCheckerTest >> testCodeBlockCaptionIsOnlySpaces [ self assert: visitor results size equals: 1. ] -{ #category : 'tests' } -MicFigureCaptionCheckerTest >> testDocumentWithOnlyText [ - | visitor mdFile mem | - mem := FileSystem memory root. - mdFile := mem / 'test.md'. - - mdFile writeStreamDo: [ :stream | - stream nextPutAll: '# Mon chapitre'; cr. - stream nextPutAll: 'Voici du texte tout à fait normal, sans aucune figure ni bloc de code.' ]. - - visitor := MicFigureCaptionChecker new. - visitor rootDirectory: mem. - visitor checkProject: mdFile. - - self assert: visitor results isEmpty. -] - -{ #category : 'tests' } -MicFigureCaptionCheckerTest >> testInitializationDefaults [ - | checker | - checker := MicFigureCaptionChecker new. - - self assert: checker checkFigure. - self assert: checker checkCode. - self assert: checker checkMath. -] - { #category : 'tests' } MicFigureCaptionCheckerTest >> testMathBlockCaptionIsEmpty [ | visitor mdFile mem | From 4c16e88fa1619f7da5ef68d77d4839f43310a652 Mon Sep 17 00:00:00 2001 From: "antoine.usal" Date: Thu, 7 May 2026 15:07:29 +0200 Subject: [PATCH 8/9] Change duplicate methods --- .../MicFigureCaptionChecker.class.st | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/Microdown-BookTester/MicFigureCaptionChecker.class.st b/src/Microdown-BookTester/MicFigureCaptionChecker.class.st index e42f92f6d..8501ed28c 100644 --- a/src/Microdown-BookTester/MicFigureCaptionChecker.class.st +++ b/src/Microdown-BookTester/MicFigureCaptionChecker.class.st @@ -10,6 +10,12 @@ Class { #package : 'Microdown-BookTester' } +{ #category : 'accessing' } +MicFigureCaptionChecker >> checkCaptionOf: aBlock [ + (self hasCorrectCaption: aBlock caption) ifFalse: [ + self results add: MicMissingFigureCaptionResult new ] +] + { #category : 'accessing' } MicFigureCaptionChecker >> checkCode [ @@ -82,21 +88,18 @@ MicFigureCaptionChecker >> initialize [ { #category : 'visiting - inline elements' } MicFigureCaptionChecker >> visitCode: aCode [ - self checkCode ifTrue: [ - (self hasCorrectCaption: aCode caption) ifFalse: [ - self results add: MicMissingFigureCaptionResult new ] ] + self checkCode ifTrue: [ self checkCaptionOf: aCode ]. + ^ super visitCode: aCode ] { #category : 'visiting - inline elements' } MicFigureCaptionChecker >> visitFigure: aFigure [ - self checkFigure ifTrue: [ - (self hasCorrectCaption: aFigure caption) ifFalse: [ - self results add: MicMissingFigureCaptionResult new ] ] + self checkFigure ifTrue: [ self checkCaptionOf: aFigure ]. + ^ super visitFigure: aFigure ] { #category : 'visiting - inline elements' } MicFigureCaptionChecker >> visitMath: aMath [ - self checkMath ifTrue: [ - (self hasCorrectCaption: aMath caption) ifFalse: [ - self results add: MicMissingFigureCaptionResult new ] ] + self checkMath ifTrue: [ self checkCaptionOf: aMath ]. + ^ super visitMath: aMath ] From a46af2e692dea42250957c35b1da8c3a7792200c Mon Sep 17 00:00:00 2001 From: "antoine.usal" Date: Thu, 7 May 2026 15:17:12 +0200 Subject: [PATCH 9/9] update config --- .../MicFigureCaptionChecker.class.st | 20 +++++++++++-------- .../MicFigureCaptionCheckerTest.class.st | 19 ++++++++++++++++++ 2 files changed, 31 insertions(+), 8 deletions(-) diff --git a/src/Microdown-BookTester/MicFigureCaptionChecker.class.st b/src/Microdown-BookTester/MicFigureCaptionChecker.class.st index 8501ed28c..d68f9723d 100644 --- a/src/Microdown-BookTester/MicFigureCaptionChecker.class.st +++ b/src/Microdown-BookTester/MicFigureCaptionChecker.class.st @@ -61,11 +61,15 @@ MicFigureCaptionChecker >> checkMissingCaptionIn: aBlock text: captionText [ ] { #category : 'visiting - inline elements' } -MicFigureCaptionChecker >> configureFrom: aConfiguration [ - super configureFrom: aConfiguration. - checkFigure := aConfiguration propertyAt: #checkFigure ifAbsent: [ true ]. - checkCode := aConfiguration propertyAt: #checkCode ifAbsent: [ true ]. - checkMath := aConfiguration propertyAt: #checkMath ifAbsent: [ true ]. +MicFigureCaptionChecker >> configureFrom: aDictionary [ + super configureFrom: aDictionary. + aDictionary at: 'checkOnly' ifPresent: [ :list | + self checkCode: false. + self checkFigure: false. + self checkMath: false. + (list includes: 'code') ifTrue: [ self checkCode: true ]. + (list includes: 'figure') ifTrue: [ self checkFigure: true ]. + (list includes: 'math') ifTrue: [ self checkMath: true ] ] ] { #category : 'visiting - inline elements' } @@ -81,9 +85,9 @@ MicFigureCaptionChecker >> hasCorrectCaption: aCaptionText [ { #category : 'visiting - inline elements' } MicFigureCaptionChecker >> initialize [ super initialize. - checkFigure := true. - checkCode := true. - checkMath := true. + self checkCode: true. + self checkFigure: true. + self checkMath: true. ] { #category : 'visiting - inline elements' } diff --git a/src/Microdown-BookTester/MicFigureCaptionCheckerTest.class.st b/src/Microdown-BookTester/MicFigureCaptionCheckerTest.class.st index f6f56ddcd..4eafee8c4 100644 --- a/src/Microdown-BookTester/MicFigureCaptionCheckerTest.class.st +++ b/src/Microdown-BookTester/MicFigureCaptionCheckerTest.class.st @@ -82,6 +82,25 @@ MicFigureCaptionCheckerTest >> testCodeBlockCaptionIsOnlySpaces [ self assert: visitor results size equals: 1. ] +{ #category : 'tests' } +MicFigureCaptionCheckerTest >> testConfigureFromCheckOnly [ + | checker config | + checker := MicFigureCaptionChecker new. + + self assert: checker checkCode. + self assert: checker checkFigure. + self assert: checker checkMath. + + config := Dictionary new. + config at: 'checkOnly' put: #('code' 'math'). + + checker configureFrom: config. + + self assert: checker checkCode. + self assert: checker checkMath. + self deny: checker checkFigure. +] + { #category : 'tests' } MicFigureCaptionCheckerTest >> testMathBlockCaptionIsEmpty [ | visitor mdFile mem |