Skip to content

Commit

Permalink
Merge pull request #626 from kasperosterbye/InlineRewrite
Browse files Browse the repository at this point in the history
MERGE ME - Inline rewrite all green
  • Loading branch information
Ducasse authored Jan 7, 2024
2 parents b509ed8 + 41c83d2 commit 9dc52bd
Show file tree
Hide file tree
Showing 87 changed files with 2,323 additions and 3,614 deletions.
27 changes: 16 additions & 11 deletions src/Microdown-Evaluator-Tests/MicCodeblockEvaluatorTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,25 @@ MicCodeblockEvaluatorTest >> actualClass [

{ #category : #private }
MicCodeblockEvaluatorTest >> testCodeblockWithEvalExecuteBody [

| input |
input := MicRootBlock new
addChild:
(MicParagraphBlock new
addChild:
((MicCodeBlock new body: 'stream nextPutAll: ''- test''')
eval: true;
yourself);
yourself) yourself.
input := MicRootBlock new addChild: (MicParagraphBlock new
addChild:
((MicCodeBlock new body: 'stream nextPutAll: ''- test''')
eval: true;
yourself);
yourself) yourself.
self actualClass new visit: input.
self assert: input children first class equals: MicParagraphBlock.
self assert: input children first children first class equals: MicUnorderedListBlock.
self assert: input children first children first children first class equals: MicListItemBlock.
self assert: input children first children first children first text equals: 'test'
self
assert: input children first children first class
equals: MicUnorderedListBlock.
self
assert: input children first children first children first class
equals: MicListItemBlock.
self
assert: input children first children first children first testText
equals: 'Text(test)'
]

{ #category : #tests }
Expand Down
6 changes: 4 additions & 2 deletions src/Microdown-Evaluator/MicCodeBlock.extension.st
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ MicCodeBlock >> evaluate [
| content |
content := self evaluationString.
^ [ (self parserClass parse: content) children ]
on: Error
do: [ :e | MicBoldFormatBlock new children: { (MicTextBlock new substring: e messageText) } ]
on: Error
do: [ :e |
MicBoldFormatBlock new children:
{ (MicTextBlock new bodystring: e messageText) } ]
]

{ #category : #'*Microdown-Evaluator' }
Expand Down
10 changes: 5 additions & 5 deletions src/Microdown-HTMLExporter-Tests/MicHTMLExporterTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ MicHTMLExporterTest >> testFigureBold [
self
parse: factory figureBoldSample
andCheckWeGet: newLine ,
'<p><figure><img src="/anUrl" alt="**Foo**" class="figureTest" width="80"><figcaption><strong>Foo</strong></figcaption></img></figure></p>'
'<p><figure><img src="/anUrl" alt="Foo" class="figureTest" width="80"><figcaption><strong>Foo</strong></figcaption></img></figure></p>'
]

{ #category : #tests }
Expand All @@ -115,7 +115,7 @@ MicHTMLExporterTest >> testFigureItalic [
self
parse: factory figureItalicSample
andCheckWeGet: newLine ,
'<p><figure><img src="/anUrl" alt="_Foo_" class="figureTest" width="80"><figcaption><i>Foo</i></figcaption></img></figure></p>'
'<p><figure><img src="/anUrl" alt="Foo" class="figureTest" width="80"><figcaption><i>Foo</i></figcaption></img></figure></p>'
]

{ #category : #tests }
Expand All @@ -124,7 +124,7 @@ MicHTMLExporterTest >> testFigureNested [
self
parse: factory figureNestedSample
andCheckWeGet: newLine ,
'<p><figure><img src="/anUrl" alt="**Foo_**" class="figureTest" width="80"><figcaption><strong>Foo_</strong></figcaption></img></figure></p>'
'<p><figure><img src="/anUrl" alt="Foo_" class="figureTest" width="80"><figcaption><strong>Foo_</strong></figcaption></img></figure></p>'
]

{ #category : #tests }
Expand All @@ -142,7 +142,7 @@ MicHTMLExporterTest >> testFigureStrike [
self
parse: factory figureStrikeSample
andCheckWeGet: newLine ,
'<p><figure><img src="/anUrl" alt="~Foo~" class="figureTest" width="80"><figcaption><strike>Foo</strike></figcaption></img></figure></p>'
'<p><figure><img src="/anUrl" alt="Foo" class="figureTest" width="80"><figcaption><strike>Foo</strike></figcaption></img></figure></p>'
]

{ #category : #tests }
Expand Down Expand Up @@ -178,7 +178,7 @@ MicHTMLExporterTest >> testGoutDeFraise [
self
parse: factory figureGoutDeFraise
andCheckWeGet: newLine ,
'<p><figure><img src="un-gout-de-fraise.jpg" alt="Proposition pour le thème : _Un goût de fraise_"><figcaption>Proposition pour le thème : <i>Un goût de fraise</i></figcaption></img></figure></p>'
'<p><figure><img src="un-gout-de-fraise.jpg" alt="Proposition pour le thème : Un goût de fraise"><figcaption>Proposition pour le thème : <i>Un goût de fraise</i></figcaption></img></figure></p>'
]

{ #category : #tests }
Expand Down
7 changes: 4 additions & 3 deletions src/Microdown-HTMLExporter-Tests/MicHTMLVisitorTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,12 @@ MicHTMLVisitorTest >> testConfiguration [
]

{ #category : #tests }
MicHTMLVisitorTest >> testContents [
MicHTMLVisitorTest >> testContents [

self assert: writer contents equals: String empty.
writer visitItalic: (MicItalicFormatBlock new textElement: (MicTextBlock new substring: 'test')).
self assert: writer contents equals: '<i>test</i>'.
writer visitItalic: (MicItalicFormatBlock new children:
{ (MicTextBlock new bodystring: 'test') }).
self assert: writer contents equals: '<i>test</i>'
]

{ #category : #tests }
Expand Down
6 changes: 6 additions & 0 deletions src/Microdown-HTMLExporter/MicFigureBlock.extension.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Extension { #name : #MicFigureBlock }

{ #category : #'*Microdown-HTMLExporter' }
MicFigureBlock >> altText [
^ (self children collect: #plainText) joinUsing: ' '
]
4 changes: 2 additions & 2 deletions src/Microdown-HTMLExporter/MicHTMLTag.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ MicHTMLTag >> addArguments: aMicInlineBlockWithUrl [

aMicInlineBlockWithUrl hasArguments ifFalse: [ ^ self ].
self htmlArgumentsMapDo: [ :argAssoc |
aMicInlineBlockWithUrl
argumentAt: argAssoc key
aMicInlineBlockWithUrl arguments
at: argAssoc key
ifPresent: [ :labelString | self parameterAt: argAssoc value put: labelString ] ]
]

Expand Down
10 changes: 4 additions & 6 deletions src/Microdown-HTMLExporter/MicHTMLVisitor.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -314,9 +314,7 @@ MicHTMLVisitor >> visitFigCaption: aFigCaptionBlock [

canvas tag
name: 'figcaption';
with: [
aFigCaptionBlock hasCaption ifTrue: [
aFigCaptionBlock captionElements do: [:each | each accept: self ] ] ]
with: [ self visitAll: aFigCaptionBlock children ]
]

{ #category : #'visiting - inline elements' }
Expand All @@ -335,7 +333,7 @@ MicHTMLVisitor >> visitHeader: aHeader [
canvas newLine.
canvas tag
name: 'h', aHeader level asString;
with: aHeader header
with: [ self visitAll: aHeader children]

]

Expand All @@ -357,7 +355,7 @@ MicHTMLVisitor >> visitImg: aMicFigureBlock [
canvas tag
name: 'img';
parameterAt: 'src' put: aMicFigureBlock reference path;
parameterAt: 'alt' put: (aMicFigureBlock hasChildren ifTrue: [ aMicFigureBlock text ] ifFalse: [ '' ]);
parameterAt: 'alt' put: aMicFigureBlock altText;
addArguments: aMicFigureBlock;
with: [ self visitFigCaption: aMicFigureBlock ]
]
Expand All @@ -379,7 +377,7 @@ MicHTMLVisitor >> visitLink: aLink [
parameterAt: 'target' put: self configuration targetAttribute;
parameterAt: 'href' put: aLink referencePath;
addArguments: aLink;
with: aLink caption
with: [self visitAll: aLink children]

]

Expand Down
24 changes: 24 additions & 0 deletions src/Microdown-HTMLExporter/MicInlineBlockWithUrl.extension.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
Extension { #name : #MicInlineBlockWithUrl }

{ #category : #'*Microdown-HTMLExporter' }
MicInlineBlockWithUrl >> argumentAt: aKey ifPresent: aBlock [
"Lookup the given key in the receiver. If it is present, answer the value of evaluating the given block with the value associated with the key. Otherwise, answer self."

self arguments
at: aKey
ifPresent: aBlock
]

{ #category : #'*Microdown-HTMLExporter' }
MicInlineBlockWithUrl >> argumentAt: aKey put: value [
"Lookup the given key in the receiver. If it is present, answer the value of evaluating the given block with the value associated with the key. Otherwise, answer self."

self arguments
at: aKey
put: value
]

{ #category : #'*Microdown-HTMLExporter' }
MicInlineBlockWithUrl >> hasChildren [
^ self children notEmpty
]
Original file line number Diff line number Diff line change
Expand Up @@ -276,12 +276,9 @@ MicLaTeXWriterTest >> testLink [
{ #category : #'tests - figure/link' }
MicLaTeXWriterTest >> testLinkBold [

self flag: 'caption do not use bold in the caption'.
self writeFor: factory linkBoldSample.
self flag: #toFix.
"\textbf{Foo}"
self assert: writer contents equals: newLine ,
'\href{/anUrl}{**Foo**}\footnotesize{\url{/anUrl}}', newLine
'\href{/anUrl}{\textbf{Foo}}\footnotesize{\url{/anUrl}}', newLine
]

{ #category : #'tests - formats' }
Expand Down
23 changes: 23 additions & 0 deletions src/Microdown-LaTeXExporter/MicInlineBlockWithUrl.extension.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
Extension { #name : #MicInlineBlockWithUrl }

{ #category : #'*Microdown-LaTeXExporter' }
MicInlineBlockWithUrl >> fileStringWithoutHostFile [
| urlString localFileIndicator |
urlString := url asString.
localFileIndicator := 'file://'.
^ (urlString beginsWith: localFileIndicator)
ifTrue: [ urlString allButFirst: localFileIndicator size ]
ifFalse: [ urlString ]
]

{ #category : #'*Microdown-LaTeXExporter' }
MicInlineBlockWithUrl >> fullName [

^ reference fullName
]

{ #category : #'*Microdown-LaTeXExporter' }
MicInlineBlockWithUrl >> hasCaption [

^ children notEmpty
]
30 changes: 11 additions & 19 deletions src/Microdown-LaTeXExporter/MicLaTeXWriter.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -227,24 +227,15 @@ MicLaTeXWriter >> visitItalic: anItalic [

{ #category : #'blocks - inline' }
MicLaTeXWriter >> visitLink: aLink [
| text reference |
| reference |
reference := aLink fileStringWithoutHostFile.
self flag: #todo.
"I do not get this logic if the string does not have file:// it can still be
something else than a url... all this logic is bogus."
text := aLink text.
(text isEmptyOrNil or: [ reference = text ])
ifTrue: [ canvas command
name: 'url';
parameter: reference ]
ifFalse: [
canvas command
name: 'href';
parameter: reference;
parameter: [ canvas nextPutAll: text ].
canvas command
name: 'footnotesize';
parameter: [ canvas command name: 'url'; parameter: (self protectUrl: reference) ] ]
canvas command
name: 'href';
parameter: reference;
parameter: [ self visitAll: aLink children ].
canvas command
name: 'footnotesize';
parameter: [ canvas command name: 'url'; parameter: (self protectUrl: reference) ]
]

{ #category : #'blocks - list' }
Expand Down Expand Up @@ -360,7 +351,7 @@ MicLaTeXWriter >> visitTableRow: aRow with: aBool at: anIndex [
{ #category : #blocks }
MicLaTeXWriter >> visitText: aText [

canvas nextPutAllLines: aText substring
canvas nextPutAllLines: aText bodystring
]

{ #category : #'blocks - list' }
Expand All @@ -381,7 +372,8 @@ MicLaTeXWriter >> visitUnorderedList: aList [

{ #category : #helpers }
MicLaTeXWriter >> writeCaptionOfExternalLink: anExternalLink [
self visitAll: anExternalLink captionElements

self visitAll: anExternalLink children
]

{ #category : #helpers }
Expand Down
2 changes: 1 addition & 1 deletion src/Microdown-PrettyPrinter-Tests/MicDumperTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ MicDumperTest >> testBoldFormat [
| micBold |
micBold := (parser parse: factory boldFormatSample) children first
children first.
self assert: micBold children first class equals: MicTextBlock.
self assert: micBold children first class equals: MicTextBlock.
visitor visit: micBold.
self
assert: visitor contents
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ MicTextualMicrodownExporterTest >> testParagraphWithItalic [
MicTextualMicrodownExporterTest >> testParagraphWithMicroDownMarkup [

| mic |
mic := parser parse: 'blab\~l\**a*1'.
mic := parser parse: 'blab\~l\*\*a*1'.
self assert: (mic accept: visitor) contents equals: '
blab\~l\**a*1
'
Expand Down
60 changes: 28 additions & 32 deletions src/Microdown-PrettyPrinter/MicRealDumper.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -147,20 +147,18 @@ MicRealDumper >> visitComment: aComment [
MicRealDumper >> visitFigure: aMicFigure [

self flag: #arg.
self
element: aMicFigure
during: [
aMicFigure hasArguments ifTrue: [ self emitParameters: aMicFigure ].
stream nextPutAll: 'url: '.
stream print: aMicFigure reference fullName.
stream
space;
nextPutAll: ';'.
stream nextPutAll: ' caption: { '.
aMicFigure captionElements
do: [ :each | self visit: each ]
separatedBy: [ stream nextPutAll: ' . ' ].
stream nextPutAll: '}; yourself' ]
self element: aMicFigure during: [
aMicFigure hasArguments ifTrue: [ self emitParameters: aMicFigure ].
stream nextPutAll: 'url: '.
stream print: aMicFigure reference fullName.
stream
space;
nextPutAll: ';'.
stream nextPutAll: ' caption: { '.
aMicFigure children
do: [ :each | self visit: each ]
separatedBy: [ stream nextPutAll: ' . ' ].
stream nextPutAll: '}; yourself' ]
]

{ #category : #'visit - section' }
Expand All @@ -187,15 +185,15 @@ MicRealDumper >> visitItalic: aMicItalic [
{ #category : #'visit - section' }
MicRealDumper >> visitLink: aMicLink [

self
element: aMicLink
during: [
stream nextPutAll: 'captionElements: '.
stream nextPutAll: '{'.
aMicLink captionElements do: [ :each | self visit: each ] separatedBy: [ stream nextPutAll: ' . ' ].
stream nextPutAll: '} ; url: '.
stream print: aMicLink url.
stream nextPutAll: ' ; yourself' ]
self element: aMicLink during: [
stream nextPutAll: 'captionElements: '.
stream nextPutAll: '{'.
aMicLink children
do: [ :each | self visit: each ]
separatedBy: [ stream nextPutAll: ' . ' ].
stream nextPutAll: '} ; url: '.
stream print: aMicLink url.
stream nextPutAll: ' ; yourself' ]
]

{ #category : #'visit - section' }
Expand Down Expand Up @@ -287,15 +285,13 @@ MicRealDumper >> visitTable: aTable [

{ #category : #'visit - section' }
MicRealDumper >> visitText: aText [

self
element: aText
during: [
stream
nextPutAll: 'substring: ';
nextPutAll: '''';
nextPutAll: aText substring;
nextPutAll: '''' ]

self element: aText during: [
stream
nextPutAll: 'substring: ';
nextPutAll: '''';
nextPutAll: aText bodystring;
nextPutAll: '''' ]
]

{ #category : #'visit - section' }
Expand Down
Loading

0 comments on commit 9dc52bd

Please sign in to comment.