Skip to content

Commit

Permalink
Merge pull request #824 from pillar-markup/822-figuresfpng-is-breaking
Browse files Browse the repository at this point in the history
822 figuresfpng is breaking
  • Loading branch information
Ducasse authored Aug 5, 2024
2 parents d448f37 + 3bebe84 commit 8b617b1
Show file tree
Hide file tree
Showing 9 changed files with 75 additions and 32 deletions.
12 changes: 6 additions & 6 deletions src/Microdown-HTMLExporter/MicHTMLVisitor.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -278,11 +278,11 @@ MicHTMLVisitor >> visitCodeblock: aCodeBlock [

canvas tag
name: 'figure';
with: [
with: [
canvas tag
name: 'pre';
with: [
| code language |
with: [
| code |
code := canvas tag
name: 'code';
yourself.
Expand All @@ -291,11 +291,11 @@ MicHTMLVisitor >> visitCodeblock: aCodeBlock [
code with: [ canvas lines: aCodeBlock text ] ].
canvas tag
name: 'figcaption';
with: [
aCodeBlock hasLabel ifTrue: [
with: [
aCodeBlock hasAnchor ifTrue: [
self visitAnchor: aCodeBlock.
self writeCounterForScript: aCodeBlock ].
aCodeBlock hasCaption ifTrue: [
aCodeBlock hasCaption ifTrue: [
self visitAll: aCodeBlock caption children ] ] ].
canvas newLine
]
Expand Down
11 changes: 11 additions & 0 deletions src/Microdown-LaTeXExporter-Tests/MicLaTeXWriterTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,17 @@ self flag: #todo.

]

{ #category : 'tests - figure/link' }
MicLaTeXWriterTest >> testFigureWithEmptyCaption [

self writeFor: '![](figures/f.png)'.
self
assert: writer contents
equals:
newLine , '\begin{center}', newLine, '\includegraphics[width=1.0\textwidth]{figures/f.png}'
, '\end{center}', newLine, newLine
]

{ #category : 'tests' }
MicLaTeXWriterTest >> testFootnote [

Expand Down
13 changes: 7 additions & 6 deletions src/Microdown-LaTeXExporter/MicLaTeXWriter.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -183,17 +183,18 @@ MicLaTeXWriter >> visitCode: aCodeBlock [
{ #category : 'blocks - inline' }
MicLaTeXWriter >> visitFigure: aFigure [

(aFigure hasCaption not and: [ aFigure hasLabel not ])
ifTrue: [
self includeGraphicsFor: aFigure.
^ self ].
(aFigure hasCaption not and: [ aFigure hasAnchor not ]) ifTrue: [
canvas environment
name: 'center';
with: [ self includeGraphicsFor: aFigure ].
^ self ].
canvas environment
name: 'figure';
optParameter: [ canvas raw: 'htpb' ];
with: [
with: [
canvas environment
name: 'center';
with: [
with: [
self includeGraphicsFor: aFigure.
canvas newLine.
canvas command
Expand Down
20 changes: 15 additions & 5 deletions src/Microdown-Tests/MicFigureBlockTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -192,18 +192,28 @@ MicFigureBlockTest >> testIsNotRelativeFilePathWithUrl [

{ #category : 'tests' }
MicFigureBlockTest >> testPrintOn [

| figure |
figure := (splitterClass new parse: '![caption](http://www.Pharo.ORG)') first.
self assert: figure asString equals: 'Figure{ Text(caption) }(http://www.Pharo.ORG)'

figure := (splitterClass new parse:
'![caption](http://www.Pharo.ORG)') first.
self
assert: figure asString
equals: 'Figure[ Text(caption) ](http://www.Pharo.ORG)'

"not really good but let us make it work"
]

{ #category : 'tests' }
MicFigureBlockTest >> testPrintOnWithParameters [

| figure |
figure := (splitterClass new parse: '![caption](http://anURL.org?label=1&title=testFigure)') first.
self assert: figure asString equals: 'Figure{ Text(caption) }(http://anURL.org?label=1&title=testFigure)'
figure := (splitterClass new parse:
'![caption](http://anURL.org?label=1&title=testFigure)')
first.
self
assert: figure asString
equals:
'Figure[ Text(caption) ](http://anURL.org?label=1&title=testFigure)'
]

{ #category : 'tests' }
Expand Down
13 changes: 9 additions & 4 deletions src/Microdown-Tests/MicInlineParserTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ MicInlineParserTest >> testBold_UnclompletedNested [
MicInlineParserTest >> testBrokenNestedBlocksHandles [
| res |
res := (self inlineParse: '![[aaaa]bbb)](ccc)sss![[aaaa](bbb](ccc)').
self assert: res printString equals: 'an Array(Text(![) Link{ Text(aaaa]bbb)) }(ccc) Text(sss![) Link{ Text(aaaa) }(bbb](ccc))'
self assert: res printString equals: 'an Array(Text(![) Link[ Text(aaaa]bbb)) ](ccc) Text(sss![) Link[ Text(aaaa) ](bbb](ccc))'
]

{ #category : 'test generated' }
Expand Down Expand Up @@ -440,10 +440,15 @@ MicInlineParserTest >> testMonospace_unevaluated [

{ #category : 'tests' }
MicInlineParserTest >> testNestedBlocksWithUrl [

| res |
res := (self inlineParse: '[![aaaa](bbb)](ccc) ![[aaaa](bbb)](ccc)').
self assert: res first printString equals: 'Link{ Figure{ Text(aaaa) }(bbb) }(ccc)'.
self assert: res third printString equals: 'Figure{ Link{ Text(aaaa) }(bbb) }(ccc)'
res := self inlineParse: '[![aaaa](bbb)](ccc) ![[aaaa](bbb)](ccc)'.
self
assert: res first printString
equals: 'Link[ Figure[ Text(aaaa) ](bbb) ](ccc)'.
self
assert: res third printString
equals: 'Figure[ Link[ Text(aaaa) ](bbb) ](ccc)'
]

{ #category : 'test generated' }
Expand Down
7 changes: 5 additions & 2 deletions src/Microdown-Tests/MicLinkBlockTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,11 @@ MicLinkBlockTest >> testOneUrl [
{ #category : 'tests' }
MicLinkBlockTest >> testPrintOn [

link := (splitterClass new parse: '[caption](http://www.pharo.org)') first.
self assert: link asString equals: 'Link{ Text(caption) }(http://www.pharo.org)'
link := (splitterClass new parse: '[caption](http://www.pharo.org)')
first.
self
assert: link asString
equals: 'Link[ Text(caption) ](http://www.pharo.org)'
]

{ #category : 'tests' }
Expand Down
3 changes: 1 addition & 2 deletions src/Microdown/MicAnchorBlock.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@ MicAnchorBlock >> label: aLabel [
MicAnchorBlock >> printOn: aStream [

super printOn: aStream.
self hasLabel
ifTrue: [ aStream nextPutAll: ' (', self label, ')' ]
label ifNotNil: [ aStream nextPutAll: ' (' , label , ')' ]
]

{ #category : 'accessing' }
Expand Down
9 changes: 6 additions & 3 deletions src/Microdown/MicCodeBlock.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,12 @@ MicCodeBlock >> hasBody [

{ #category : 'accessing' }
MicCodeBlock >> hasLabel [
self deprecated: 'Use hasAnchor' transformWith: '`@rec hasLabel' -> '`@rec hasAnchor'.

^ self anchor

self
deprecated: 'Use hasAnchor'
transformWith: '`@rec hasLabel' -> '`@rec hasAnchor'.

^ self hasAnchor
]

{ #category : 'testing' }
Expand Down
19 changes: 15 additions & 4 deletions src/Microdown/MicInlineBlockWithUrl.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,15 @@ MicInlineBlockWithUrl >> hasChildren [
^ self children notEmpty
]

{ #category : 'testing' }
MicInlineBlockWithUrl >> hasLabel [

self
deprecated: 'Use hasAnchor instead'
transformWith: '`@rec hasLabel' -> '`@rec hasAnchor'.
^ self hasAnchor
]

{ #category : 'initialization' }
MicInlineBlockWithUrl >> initialize [
super initialize.
Expand All @@ -169,11 +178,13 @@ MicInlineBlockWithUrl >> initialize [

{ #category : 'printing' }
MicInlineBlockWithUrl >> printOn: stream [
stream << self blockName << '{ '.
children do: [ :ch | ch printOn: stream. stream nextPut: Character space ].
stream << $}.

stream << self blockName << '[ '.
children do: [ :ch |
ch printOn: stream.
stream nextPut: Character space ].
stream << $].
stream << $( << url << $)

]

{ #category : 'accessing' }
Expand Down

0 comments on commit 8b617b1

Please sign in to comment.