From a8c7db6c578e182b7374224ecd10b4b411cc10f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phaneDucasse?= Date: Wed, 4 Sep 2024 11:31:45 +0200 Subject: [PATCH] Adding code block anchor to the anchors that exist! Fix https://github.com/pillar-markup/Microdown/issues/871 --- .../MicReferenceCheckerTest.class.st | 32 ++++++++++++++++++- .../MicReferenceChecker.class.st | 6 ++++ src/Microdown/MicCodeBlock.class.st | 6 ++++ 3 files changed, 43 insertions(+), 1 deletion(-) diff --git a/src/Microdown-BookTester-Tests/MicReferenceCheckerTest.class.st b/src/Microdown-BookTester-Tests/MicReferenceCheckerTest.class.st index 2a6441eb..f348e9e0 100644 --- a/src/Microdown-BookTester-Tests/MicReferenceCheckerTest.class.st +++ b/src/Microdown-BookTester-Tests/MicReferenceCheckerTest.class.st @@ -8,7 +8,8 @@ Class { 'defAndRefFig1', 'defFig1AndRefToAnsC0', 'defFig1AndRefToAncUnkS0', - 'refToUnkS1' + 'refToUnkS1', + 'defCode1AndReferToCode1' ], #category : 'Microdown-BookTester-Tests', #package : 'Microdown-BookTester-Tests' @@ -99,6 +100,23 @@ See *@ancS1@* and *@ancS0@* ^ defAncS0TripleAncS1RefAncS1AncS0 ] +{ #category : 'helpers - anchors & references' } +MicReferenceCheckerTest >> defCode1AndReferToCode1 [ + + defCode1AndReferToCode1 := fs / 'defCode1AndReferToCode1.md'. + defCode1AndReferToCode1 writeStreamDo: [ :stream | + stream nextPutAll: '# Section 1 + +```language=pharo&anchor=Code1 +balbalbalb! +``` + +See *@Code1@* + +' ]. + defCode1AndReferToCode1 ensureCreateFile +] + { #category : 'helpers - anchors & references' } MicReferenceCheckerTest >> defEq1AndReferToEq1 [ @@ -294,6 +312,18 @@ See *@ancS1@* ' ] ] +{ #category : 'tests - single file ok references' } +MicReferenceCheckerTest >> testDefAndReferToACodeAnchorInFile [ + + | visitor | + self defCode1AndReferToCode1. + visitor := MicReferenceChecker new. + visitor rootDirectory: dir. + visitor checkProject: defCode1AndReferToCode1. + self assert: visitor isOkay. + self assert: visitor results isEmpty +] + { #category : 'tests - single file ok references' } MicReferenceCheckerTest >> testDefAndReferToAMathEquationInFile [ diff --git a/src/Microdown-BookTester/MicReferenceChecker.class.st b/src/Microdown-BookTester/MicReferenceChecker.class.st index 2b1506b6..346f1c6e 100644 --- a/src/Microdown-BookTester/MicReferenceChecker.class.st +++ b/src/Microdown-BookTester/MicReferenceChecker.class.st @@ -272,6 +272,12 @@ MicReferenceChecker >> visitAnchorReference: anAnchorReference [ references add: anAnchorReference ] +{ #category : 'visiting' } +MicReferenceChecker >> visitCode: aCodeBlock [ + + self handleAnchorOf: aCodeBlock +] + { #category : 'visiting' } MicReferenceChecker >> visitFigure: aFigure [ diff --git a/src/Microdown/MicCodeBlock.class.st b/src/Microdown/MicCodeBlock.class.st index 441eaffc..6a475a0b 100644 --- a/src/Microdown/MicCodeBlock.class.st +++ b/src/Microdown/MicCodeBlock.class.st @@ -63,6 +63,12 @@ MicCodeBlock >> anchor: aString [ self arguments at: #anchor put: aString ] +{ #category : 'accessing' } +MicCodeBlock >> anchorLabel [ + "This should only be invoked when checking references" + ^ self anchor +] + { #category : 'public' } MicCodeBlock >> closeMe [ "adjust prefix tabs based on first line