Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 830 extend the extension mechanism #851

Merged
merged 5 commits into from
Aug 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions src/Microdown-Tests/MicCitationBlockTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -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 [

Expand All @@ -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'.
]
32 changes: 32 additions & 0 deletions src/Microdown-Tests/MicFootnoteBlockTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -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'
]
20 changes: 20 additions & 0 deletions src/Microdown-Tests/MicNoteBlockTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -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'.
]
14 changes: 13 additions & 1 deletion src/Microdown/MicAnnotationBlock.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ MicAnnotationBlock class >> closingDelimiter [
^ AnnotationCloserMarkup
]

{ #category : 'parsing' }
MicAnnotationBlock class >> key [

^ 'key'
]

{ #category : 'accessing' }
MicAnnotationBlock class >> openingDelimiter [

Expand All @@ -46,7 +52,13 @@ MicAnnotationBlock class >> parse: delimiter stream: aTokenStream for: aParser [
tag := arguments defaultValue trimBoth.

extensionClass := self extensionClassFor: tag.


arguments justTheArguments ifNotEmpty: [ | key |
key := arguments justTheArguments keyAtIndex: 1.
(arguments at: key) ifNil: [ arguments at: extensionClass key put: key ]].



^ extensionClass new
bodyString: bodystring;
arguments: arguments
Expand Down
5 changes: 5 additions & 0 deletions src/Microdown/MicCitationBlock.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ Class {
#tag : 'Extensions'
}

{ #category : 'accessing' }
MicCitationBlock class >> key [
^ 'ref'
]

{ #category : 'accessing' }
MicCitationBlock class >> tag [

Expand Down
5 changes: 5 additions & 0 deletions src/Microdown/MicFootnoteBlock.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ Class {
#tag : 'Extensions'
}

{ #category : 'accessing' }
MicFootnoteBlock class >> key [
^ 'note'
]

{ #category : 'accessing' }
MicFootnoteBlock class >> tag [

Expand Down
6 changes: 6 additions & 0 deletions src/Microdown/MicNoteBlock.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,14 @@ Class {
#tag : 'Extensions'
}

{ #category : 'accessing' }
MicNoteBlock class >> key [
^ 'contents'
]

{ #category : 'accessing' }
MicNoteBlock class >> tag [

^ #note
]

Expand Down
Loading