From 90568d5a77357ed7b4c593f0a2c0b341ec46b831 Mon Sep 17 00:00:00 2001 From: "quentin.moutte.etu" Date: Sat, 10 Aug 2024 13:06:45 +0200 Subject: [PATCH 1/4] use key class method for give a default key in MicAnnotationBlock --- src/Microdown/MicAnnotationBlock.class.st | 5 ++++- src/Microdown/MicCitationBlock.class.st | 5 +++++ src/Microdown/MicFootnoteBlock.class.st | 5 +++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/Microdown/MicAnnotationBlock.class.st b/src/Microdown/MicAnnotationBlock.class.st index 744baec3..b88a01c7 100644 --- a/src/Microdown/MicAnnotationBlock.class.st +++ b/src/Microdown/MicAnnotationBlock.class.st @@ -37,7 +37,7 @@ MicAnnotationBlock class >> openingDelimiter [ { #category : 'parsing' } MicAnnotationBlock class >> parse: delimiter stream: aTokenStream for: aParser [ - | bodystring arguments tag extensionClass | + | bodystring arguments tag extensionClass key | bodystring := delimiter undelimitedSubstring. arguments := MicArgumentList split: bodystring @@ -46,6 +46,9 @@ MicAnnotationBlock class >> parse: delimiter stream: aTokenStream for: aParser [ tag := arguments defaultValue trimBoth. extensionClass := self extensionClassFor: tag. + + key := arguments justTheArguments keyAtIndex: 1. + key = extensionClass key ifFalse: [ arguments at: extensionClass key put: key ]. ^ extensionClass new bodyString: bodystring; diff --git a/src/Microdown/MicCitationBlock.class.st b/src/Microdown/MicCitationBlock.class.st index 8322dd43..3c50a35c 100644 --- a/src/Microdown/MicCitationBlock.class.st +++ b/src/Microdown/MicCitationBlock.class.st @@ -14,6 +14,11 @@ Class { #tag : 'Extensions' } +{ #category : 'accessing' } +MicCitationBlock class >> key [ + ^ 'ref' +] + { #category : 'accessing' } MicCitationBlock class >> tag [ diff --git a/src/Microdown/MicFootnoteBlock.class.st b/src/Microdown/MicFootnoteBlock.class.st index f64f288d..5ca387f8 100644 --- a/src/Microdown/MicFootnoteBlock.class.st +++ b/src/Microdown/MicFootnoteBlock.class.st @@ -11,6 +11,11 @@ Class { #tag : 'Extensions' } +{ #category : 'accessing' } +MicFootnoteBlock class >> key [ + ^ 'note' +] + { #category : 'accessing' } MicFootnoteBlock class >> tag [ From 79ce8efe62b1b53f34326bcab328608e02bad38e Mon Sep 17 00:00:00 2001 From: "quentin.moutte.etu" Date: Sat, 10 Aug 2024 16:22:37 +0200 Subject: [PATCH 2/4] add test for annotation withoutKey, and whit a non default Key --- .../MicCitationBlockTest.class.st | 40 +++++++++++++++++++ .../MicFootnoteBlockTest.class.st | 32 +++++++++++++++ src/Microdown-Tests/MicNoteBlockTest.class.st | 20 ++++++++++ 3 files changed, 92 insertions(+) diff --git a/src/Microdown-Tests/MicCitationBlockTest.class.st b/src/Microdown-Tests/MicCitationBlockTest.class.st index 7c0a6ac2..9f827504 100644 --- a/src/Microdown-Tests/MicCitationBlockTest.class.st +++ b/src/Microdown-Tests/MicCitationBlockTest.class.st @@ -16,6 +16,26 @@ MicCitationBlockTest >> testCreateTheRightCitationObject [ self assert: (doc children first children first arguments at: #key) equals: 'Duca99a'. ] +{ #category : 'tests' } +MicCitationBlockTest >> testCreateTheRightCitationObjectWithNonDefaultKey [ + + | doc | + doc := parser parse: '{!citation|key2=Duca99a!}'. + self assert: doc children first children first class equals: MicCitationBlock. + self assert: doc children first children first name equals: 'citation'. + self assert: (doc children first children first arguments at: #key2) equals: 'Duca99a'. +] + +{ #category : 'tests' } +MicCitationBlockTest >> testCreateTheRightCitationObjectWithoutKey [ + + | doc | + doc := parser parse: '{!citation|Duca99a!}'. + self assert: doc children first children first class equals: MicCitationBlock. + self assert: doc children first children first name equals: 'citation'. + self assert: (doc children first children first arguments at: #ref) equals: 'Duca99a'. +] + { #category : 'tests' } MicCitationBlockTest >> testDefaultingClassWhenNoTag [ @@ -25,3 +45,23 @@ MicCitationBlockTest >> testDefaultingClassWhenNoTag [ self assert: doc children first children first name equals: 'citation2'. self assert: (doc children first children first arguments at: #key) equals: 'Duca99a'. ] + +{ #category : 'tests' } +MicCitationBlockTest >> testDefaultingClassWhenNoTagAndNoKey [ + + | doc | + doc := parser parse: '{!citation2|Duca99a!}'. + self assert: doc children first children first class equals: MicAnnotationBlock. + self assert: doc children first children first name equals: 'citation2'. + self assert: (doc children first children first arguments at: #key) equals: 'Duca99a'. +] + +{ #category : 'tests' } +MicCitationBlockTest >> testDefaultingClassWhenNoTagWithNonDefaultKey [ + + | doc | + doc := parser parse: '{!citation2|key2=Duca99a!}'. + self assert: doc children first children first class equals: MicAnnotationBlock. + self assert: doc children first children first name equals: 'citation2'. + self assert: (doc children first children first arguments at: #key2) equals: 'Duca99a'. +] diff --git a/src/Microdown-Tests/MicFootnoteBlockTest.class.st b/src/Microdown-Tests/MicFootnoteBlockTest.class.st index 08a8fd6e..022346c5 100644 --- a/src/Microdown-Tests/MicFootnoteBlockTest.class.st +++ b/src/Microdown-Tests/MicFootnoteBlockTest.class.st @@ -21,3 +21,35 @@ MicFootnoteBlockTest >> testCreateTheRightFootnoteObject [ assert: (doc children first children first arguments at: #note) equals: 'Duca99a' ] + +{ #category : 'tests' } +MicFootnoteBlockTest >> testCreateTheRightFootnoteObjectWithNonDefaultKey [ + + | doc | + doc := parser parse: '{!footnote|note2=Duca99a!}'. + self + assert: doc children first children first class + equals: MicFootnoteBlock. + self + assert: doc children first children first name + equals: 'footnote'. + self + assert: (doc children first children first arguments at: #note2) + equals: 'Duca99a' +] + +{ #category : 'tests' } +MicFootnoteBlockTest >> testCreateTheRightFootnoteObjectWithoutKey [ + + | doc | + doc := parser parse: '{!footnote|Duca99a!}'. + self + assert: doc children first children first class + equals: MicFootnoteBlock. + self + assert: doc children first children first name + equals: 'footnote'. + self + assert: (doc children first children first arguments at: #note) + equals: 'Duca99a' +] diff --git a/src/Microdown-Tests/MicNoteBlockTest.class.st b/src/Microdown-Tests/MicNoteBlockTest.class.st index 0394e7cb..a8ba6296 100644 --- a/src/Microdown-Tests/MicNoteBlockTest.class.st +++ b/src/Microdown-Tests/MicNoteBlockTest.class.st @@ -15,3 +15,23 @@ MicNoteBlockTest >> testCreateTheRightNoteObject [ self assert: doc children first children first name equals: 'note'. self assert: (doc children first children first arguments at: #contents) equals: 'Duca99a'. ] + +{ #category : 'tests' } +MicNoteBlockTest >> testCreateTheRightNoteObjectWithNonDefaultKey [ + + | doc | + doc := parser parse: '{!note|contents2=Duca99a!}'. + self assert: doc children first children first class equals: MicNoteBlock. + self assert: doc children first children first name equals: 'note'. + self assert: (doc children first children first arguments at: #contents2) equals: 'Duca99a'. +] + +{ #category : 'tests' } +MicNoteBlockTest >> testCreateTheRightNoteObjectWithoutKey [ + + | doc | + doc := parser parse: '{!note|Duca99a!}'. + self assert: doc children first children first class equals: MicNoteBlock. + self assert: doc children first children first name equals: 'note'. + self assert: (doc children first children first arguments at: #contents) equals: 'Duca99a'. +] From 8626529be28934504a41525bf9efa3416c0bce00 Mon Sep 17 00:00:00 2001 From: "quentin.moutte.etu" Date: Sat, 10 Aug 2024 16:23:23 +0200 Subject: [PATCH 3/4] add default key to MicAnnotationBlock and MicNoteBlock --- src/Microdown/MicAnnotationBlock.class.st | 10 ++++++++-- src/Microdown/MicNoteBlock.class.st | 6 ++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/Microdown/MicAnnotationBlock.class.st b/src/Microdown/MicAnnotationBlock.class.st index b88a01c7..01aed011 100644 --- a/src/Microdown/MicAnnotationBlock.class.st +++ b/src/Microdown/MicAnnotationBlock.class.st @@ -28,6 +28,12 @@ MicAnnotationBlock class >> closingDelimiter [ ^ AnnotationCloserMarkup ] +{ #category : 'parsing' } +MicAnnotationBlock class >> key [ + + ^ 'key' +] + { #category : 'accessing' } MicAnnotationBlock class >> openingDelimiter [ @@ -48,8 +54,8 @@ MicAnnotationBlock class >> parse: delimiter stream: aTokenStream for: aParser [ extensionClass := self extensionClassFor: tag. key := arguments justTheArguments keyAtIndex: 1. - key = extensionClass key ifFalse: [ arguments at: extensionClass key put: key ]. - + (arguments at: key) ifNil: [ arguments at: extensionClass key put: key ]. + ^ extensionClass new bodyString: bodystring; arguments: arguments diff --git a/src/Microdown/MicNoteBlock.class.st b/src/Microdown/MicNoteBlock.class.st index 5c264147..79bce0fa 100644 --- a/src/Microdown/MicNoteBlock.class.st +++ b/src/Microdown/MicNoteBlock.class.st @@ -6,8 +6,14 @@ Class { #tag : 'Extensions' } +{ #category : 'accessing' } +MicNoteBlock class >> key [ + ^ 'contents' +] + { #category : 'accessing' } MicNoteBlock class >> tag [ + ^ #note ] From c27edcdfe63899c9672e7ee07fdea1aebb5d0591 Mon Sep 17 00:00:00 2001 From: "quentin.moutte.etu" Date: Sat, 10 Aug 2024 16:43:41 +0200 Subject: [PATCH 4/4] fix broken test --- src/Microdown/MicAnnotationBlock.class.st | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/Microdown/MicAnnotationBlock.class.st b/src/Microdown/MicAnnotationBlock.class.st index 01aed011..c53b32fd 100644 --- a/src/Microdown/MicAnnotationBlock.class.st +++ b/src/Microdown/MicAnnotationBlock.class.st @@ -43,7 +43,7 @@ MicAnnotationBlock class >> openingDelimiter [ { #category : 'parsing' } MicAnnotationBlock class >> parse: delimiter stream: aTokenStream for: aParser [ - | bodystring arguments tag extensionClass key | + | bodystring arguments tag extensionClass | bodystring := delimiter undelimitedSubstring. arguments := MicArgumentList split: bodystring @@ -53,8 +53,11 @@ MicAnnotationBlock class >> parse: delimiter stream: aTokenStream for: aParser [ extensionClass := self extensionClassFor: tag. - key := arguments justTheArguments keyAtIndex: 1. - (arguments at: key) ifNil: [ arguments at: extensionClass key put: key ]. + arguments justTheArguments ifNotEmpty: [ | key | + key := arguments justTheArguments keyAtIndex: 1. + (arguments at: key) ifNil: [ arguments at: extensionClass key put: key ]]. + + ^ extensionClass new bodyString: bodystring;