Skip to content

Commit

Permalink
Merge pull request #750 from pillar-markup/movingFigArgsInCaption
Browse files Browse the repository at this point in the history
started to get green tests on supporting ![ a caption % width=60&anch…
  • Loading branch information
Ducasse authored May 26, 2024
2 parents 7d035b9 + db8aa42 commit 7641d44
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 8 deletions.
46 changes: 46 additions & 0 deletions src/Microdown-Tests/MicFigureBlockTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,20 @@ MicFigureBlockTest >> testAnchorExpressedUsingLabel [
self assert: figure anchor equals: '233'
]

{ #category : 'tests - new position' }
MicFigureBlockTest >> testAnchorInCaption [

| figure |
figure := (splitterClass new parse:
'![ caption with space and dot... % width=80&anchor=233]( https://github.com/pillar-markup/Microdown/runs/4336482137?check_suite_focus=true )') first.

self assert: figure hasArguments.
self assert: figure hasAnchor.
self assert: figure anchor equals: '233'.
self assert: (figure arguments at: #width) equals: '80'.
self assert: figure children first bodyString equals: ' caption with space and dot... '
]

{ #category : 'running' }
MicFigureBlockTest >> testArgumentAtIfPresent [

Expand Down Expand Up @@ -113,6 +127,24 @@ MicFigureBlockTest >> testFigureCaptionIsReified [
self assert: fig children second parent equals: fig
]

{ #category : 'tests - new position' }
MicFigureBlockTest >> testFigureCaptionIsReifiedWithNewFormat [
"And as such their parent is the math block"

| root fig |
root := Microdown parse: '
![This **great** caption % width=666&anchor=myAnchor](figures/f.png)'.
fig := root children first children first.
self
assert: fig children second class equals: MicBoldFormatBlock.
self assert: fig children second parent equals: fig.

self assert: fig hasArguments.
self assert: fig hasAnchor.
self assert: fig anchor equals: 'myAnchor'.
self assert: (fig arguments at: #width) equals: '666'
]

{ #category : 'tests' }
MicFigureBlockTest >> testHasArguments [
| figure |
Expand All @@ -137,6 +169,20 @@ MicFigureBlockTest >> testHasNoArguments [

]

{ #category : 'tests - new position' }
MicFigureBlockTest >> testIfArgumentInCaptionIgnoresInURL [
"Since we will move to the first solution"

| figure |
figure := (splitterClass new parse:
'![ caption with space and dot... % width=80&anchor=233]( https://github.com/pillar-markup/Microdown/runs/4336482137?check_suite_focus=true width=100&anchor=NotThatOne)') first.

self assert: figure hasArguments.
self assert: figure hasAnchor.
self assert: figure anchor equals: '233'.
self assert: (figure arguments at: #width) equals: '80'
]

{ #category : 'tests - testing' }
MicFigureBlockTest >> testIsNotRelativeFilePathWithUrl [
| figure |
Expand Down
7 changes: 4 additions & 3 deletions src/Microdown/MicInlineBlockWithUrl.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,10 @@ MicInlineBlockWithUrl >> closeMe [
| split title |
split := url splitOnFirst: Character space.
self reference: (MicResourceReference fromUri: split first).
title := (split second ifNil: [ '' ])
trimBoth: [:char | {$". Character space} includes: char].
self arguments: (MicArgumentList withString: title)
self arguments ifNil: [
title := (split second ifNil: [ '' ])
trimBoth: [:char | {$". Character space} includes: char].
self arguments: (MicArgumentList withString: title)]
]
{ #category : 'utilities' }
Expand Down
25 changes: 25 additions & 0 deletions src/Microdown/MicInlineCommentBlock.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
Class {
#name : 'MicInlineCommentBlock',
#superclass : 'MicUnEvaluatedBlock',
#category : 'Microdown-Model',
#package : 'Microdown',
#tag : 'Model'
}

{ #category : 'accessing' }
MicInlineCommentBlock class >> closingDelimiter [

^ self shouldNotImplement
]

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

^ CommentedLineMarkup
]

{ #category : 'visiting' }
MicInlineCommentBlock >> accept: aVisitor [
"For now do nothing"

]
30 changes: 25 additions & 5 deletions src/Microdown/MicInlineParser.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -98,15 +98,35 @@ MicInlineParser >> parseEvaluatedBlock: blockType token: token stream: tokenStre
{ #category : 'private parsing' }
MicInlineParser >> parseNameUrlBlock: blockType from: aTokenStream token: token [

| skipRes children urlToken |
| skipRes children urlToken caption rest toCaption newBlock |

skipRes := self skipToUrlStartInStream: aTokenStream.
skipRes ifNil: [ ^ self createTextBlock: token string ].
children := self parseChildrenIn: skipRes second.
"We look if we have a % in the caption to remove the rest from the caption
and place them as arguments"
caption := OrderedCollection new.
rest := OrderedCollection new.
toCaption := true.
"Pay attention skipRes second do: is not equal to skip second contents do: the latter returns the complete stream ignoring previous positions."
skipRes second do: [:each |
each delimiter markup = '%'
ifTrue: [toCaption := false].
toCaption
ifTrue: [ caption add: each ]
ifFalse: [ rest add: each ] ].
caption := caption readStream.
children := self parseChildrenIn: caption.
urlToken := aTokenStream next.
^ blockType new
newBlock := blockType new
children: children;
url: urlToken undelimitedSubstring;
closeMe
url: urlToken undelimitedSubstring.
rest
ifNotEmpty: [ newBlock arguments: (MicArgumentList withString: rest second string )]
ifEmpty: [
"We mark it to nil to indicate to the closeMe that there were no arguments in the caption. In the future when all the books and more will not use arguments in the url then we will remove this hack. For now it enables backward compatibility while giving precedence to caption arguments."
newBlock arguments: nil ].
newBlock closeMe.
^ newBlock
]

{ #category : 'private parsing' }
Expand Down
3 changes: 3 additions & 0 deletions src/Microdown/MicInlineStandardDelimiter.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ MicInlineStandardDelimiter class >> initializeDelimiters [
"The fixious text delimiter"
self new markup: FixiousTextDelimiter; blockClass: MicTextBlock; closer: nil; addMe.

"The comment text delimiter"
self new markup: CommentedLineMarkup ; blockClass: MicInlineCommentBlock; closer: nil; addMe.

"formating"
self new markup: BoldMarkup; blockClass: MicBoldFormatBlock; closer: BoldMarkup; addMe.
self new markup: ItalicMarkup; blockClass: MicItalicFormatBlock; closer: ItalicMarkup; addMe.
Expand Down

0 comments on commit 7641d44

Please sign in to comment.