diff --git a/src/Microdown-BeamerExporter-Tests/MicBeamerWriterTest.class.st b/src/Microdown-BeamerExporter-Tests/MicBeamerWriterTest.class.st index f1665b01..a57b5139 100644 --- a/src/Microdown-BeamerExporter-Tests/MicBeamerWriterTest.class.st +++ b/src/Microdown-BeamerExporter-Tests/MicBeamerWriterTest.class.st @@ -1,10 +1,11 @@ Class { - #name : #MicBeamerWriterTest, - #superclass : #MicLaTeXWriterTest, - #category : #'Microdown-BeamerExporter-Tests' + #name : 'MicBeamerWriterTest', + #superclass : 'MicLaTeXWriterTest', + #category : 'Microdown-BeamerExporter-Tests', + #package : 'Microdown-BeamerExporter-Tests' } -{ #category : #tests } +{ #category : 'tests' } MicBeamerWriterTest class >> testParameters [ ^ ParametrizedTestMatrix new @@ -15,12 +16,12 @@ MicBeamerWriterTest class >> testParameters [ yourself ] -{ #category : #running } +{ #category : 'running' } MicBeamerWriterTest >> actualClass [ ^ MicBeamerWriter ] -{ #category : #tests } +{ #category : 'tests' } MicBeamerWriterTest >> testCode [ self writeFor: (factory codeblockNoParamBody: 'this is a code'). @@ -29,7 +30,7 @@ MicBeamerWriterTest >> testCode [ '\end{listing}', newLine ] -{ #category : #tests } +{ #category : 'tests' } MicBeamerWriterTest >> testCodeWithCaption [ self writeFor: (factory codeblock: 'caption=Pharo is **cool**' body: 'this is a code'). @@ -38,7 +39,7 @@ MicBeamerWriterTest >> testCodeWithCaption [ '\end{listing}', newLine ] -{ #category : #tests } +{ #category : 'tests' } MicBeamerWriterTest >> testCodeWithLabel [ self writeFor: (factory codeblock: 'label=Pharo' body: 'this is a code'). @@ -47,7 +48,7 @@ MicBeamerWriterTest >> testCodeWithLabel [ '\end{listing}', newLine ] -{ #category : #tests } +{ #category : 'tests' } MicBeamerWriterTest >> testColumn [ self writeFor: (factory columnSample). @@ -56,7 +57,7 @@ MicBeamerWriterTest >> testColumn [ '\end{column}', newLine, newLine ] -{ #category : #tests } +{ #category : 'tests' } MicBeamerWriterTest >> testColumns [ self writeFor: (factory columnsSample). @@ -64,7 +65,7 @@ MicBeamerWriterTest >> testColumns [ '\end{columns}', newLine , newLine ] -{ #category : #tests } +{ #category : 'tests' } MicBeamerWriterTest >> testColumnsWithChildren [ self writeFor: factory columnsWithChildrenSample. @@ -78,7 +79,7 @@ MicBeamerWriterTest >> testColumnsWithChildren [ '\end{columns}', newLine , newLine ] -{ #category : #'tests - figure/link' } +{ #category : 'tests - figure/link' } MicBeamerWriterTest >> testFigure [ self writeFor: factory figureSample. @@ -87,7 +88,7 @@ MicBeamerWriterTest >> testFigure [ '\includegraphics[width=0.8\textwidth]{/anUrl}\end{center}', newLine, newLine ] -{ #category : #'tests - figure/link' } +{ #category : 'tests - figure/link' } MicBeamerWriterTest >> testFigureBold [ "in beamer we do not display caption so bld and the rest goes away." self writeFor: factory figureBoldSample. @@ -96,7 +97,7 @@ MicBeamerWriterTest >> testFigureBold [ '\includegraphics[width=0.8\textwidth]{/anUrl}\end{center}', newLine , newLine ] -{ #category : #'tests - figure/link' } +{ #category : 'tests - figure/link' } MicBeamerWriterTest >> testFigureRealSample [ self writeFor: factory figureRealSample. @@ -105,7 +106,7 @@ MicBeamerWriterTest >> testFigureRealSample [ '\includegraphics[width=0.8\textwidth]{figures/logo.png}\end{center}', newLine , newLine ] -{ #category : #tests } +{ #category : 'tests' } MicBeamerWriterTest >> testFrameWithoutOption [ self diff --git a/src/Microdown-BeamerExporter-Tests/MicMicrodownToSlideTest.class.st b/src/Microdown-BeamerExporter-Tests/MicMicrodownToSlideTest.class.st new file mode 100644 index 00000000..627bd059 --- /dev/null +++ b/src/Microdown-BeamerExporter-Tests/MicMicrodownToSlideTest.class.st @@ -0,0 +1,41 @@ +Class { + #name : 'MicMicrodownToSlideTest', + #superclass : 'TestCase', + #category : 'Microdown-BeamerExporter-Tests', + #package : 'Microdown-BeamerExporter-Tests' +} + +{ #category : 'tests' } +MicMicrodownToSlideTest >> testSectionLevelOneIsMapToSlide [ + + | doc slide | + doc := MicrodownParser new parse: '# Slide title + +- item 1 +- item 2 +'. + MicMicrodownToSlideVisitor new visit: doc. + slide := doc children first. + self assert: slide class equals: MicSlideBlock. + self assert: slide title equals: 'Slide title'. + self assert: doc children second class equals: MicUnorderedListBlock. + + +] + +{ #category : 'tests' } +MicMicrodownToSlideTest >> testSlideGotCorrectParent [ + + | doc slide | + doc := MicrodownParser new parse: '# Slide title + +- item 1 +- item 2 +'. + self assert: doc children size equals: 2. + MicMicrodownToSlideVisitor new visit: doc. + slide := doc children first. + self assert: slide parent equals: doc. + self assert: doc children size equals: 2 + +] diff --git a/src/Microdown-BeamerExporter-Tests/package.st b/src/Microdown-BeamerExporter-Tests/package.st index 9f918ba2..1a7874ca 100644 --- a/src/Microdown-BeamerExporter-Tests/package.st +++ b/src/Microdown-BeamerExporter-Tests/package.st @@ -1 +1 @@ -Package { #name : #'Microdown-BeamerExporter-Tests' } +Package { #name : 'Microdown-BeamerExporter-Tests' } diff --git a/src/Microdown-BeamerExporter/MicMicrodownToSlideVisitor.class.st b/src/Microdown-BeamerExporter/MicMicrodownToSlideVisitor.class.st new file mode 100644 index 00000000..73306105 --- /dev/null +++ b/src/Microdown-BeamerExporter/MicMicrodownToSlideVisitor.class.st @@ -0,0 +1,13 @@ +Class { + #name : 'MicMicrodownToSlideVisitor', + #superclass : 'MicrodownVisitor', + #category : 'Microdown-BeamerExporter', + #package : 'Microdown-BeamerExporter' +} + +{ #category : 'visiting' } +MicMicrodownToSlideVisitor >> visitHeader: aHeader [ + + aHeader parent replace: aHeader by: (MicSlideBlock new title: aHeader header) + +] diff --git a/src/Microdown-Tests/MicrodownTest.class.st b/src/Microdown-Tests/MicrodownTest.class.st index 6165f884..874db2d9 100644 --- a/src/Microdown-Tests/MicrodownTest.class.st +++ b/src/Microdown-Tests/MicrodownTest.class.st @@ -77,3 +77,23 @@ MicrodownTest >> testParentBackLinkIsSet [ self assert: h children first equals: t. self assert: t parent equals: h ] + +{ #category : 'tests - replace' } +MicrodownTest >> testParentLinkIsKeptOnReplaceBy [ + + | h original new | + h := MicHeaderBlock new. + original := MicTextBlock new. + original bodyString: 'Original'. + original parent: h. + self assert: original parent equals: h. + self assert: h children first equals: original. + new := MicTextBlock new. + new bodyString: 'New'. + + original replaceBy: new. + self assert: h children size equals: 1. + self assert: h children first equals: new. + self assert: new parent equals: h. + +] diff --git a/src/Microdown/MicAbstractBlock.class.st b/src/Microdown/MicAbstractBlock.class.st index 5a774b05..3e2a3e2f 100644 --- a/src/Microdown/MicAbstractBlock.class.st +++ b/src/Microdown/MicAbstractBlock.class.st @@ -133,20 +133,17 @@ MicAbstractBlock >> parserClass [ ] { #category : 'replacement' } -MicAbstractBlock >> replace: aBlock by: anotherBlock [ +MicAbstractBlock >> replace: aMicElement by: anotherMicElement [ - children replaceAll: aBlock with: anotherBlock + self children replaceAll: aMicElement with: anotherMicElement. + aMicElement basicParent: nil. + anotherMicElement basicParent: self. ] { #category : 'replacement' } -MicAbstractBlock >> replace: aBlock byCollection: aCollection [ +MicAbstractBlock >> replace: aMicElement byCollection: aCollection [ - children := children copyReplaceAll: {aBlock} with: aCollection -] - -{ #category : 'replacement' } -MicAbstractBlock >> replaceBy: anotherBlock [ - self parent replace: self by: anotherBlock + children := children copyReplaceAll: {aMicElement} with: aCollection ] { #category : 'replacement' } diff --git a/src/Microdown/MicArgumentList.class.st b/src/Microdown/MicArgumentList.class.st index 4d6b245e..7f64ba9d 100644 --- a/src/Microdown/MicArgumentList.class.st +++ b/src/Microdown/MicArgumentList.class.st @@ -58,10 +58,7 @@ MicArgumentList class >> split: aString defaultArg: defArg [ { #category : 'instance creation' } MicArgumentList class >> split: aString defaultArg: defArg defaultValue: defValue [ ^ self new - defaultArg: defArg; - at: defArg put: defValue; - initialValue: defValue; - from: aString; + split: aString defaultArg: defArg defaultValue: defValue; yourself ] @@ -188,6 +185,16 @@ MicArgumentList >> setNoDefaultButArguments: string [ ] +{ #category : 'initialization' } +MicArgumentList >> split: aString defaultArg: defArg defaultValue: defValue [ + + self + defaultArg: defArg; + at: defArg put: defValue; + initialValue: defValue; + from: aString +] + { #category : 'copying' } MicArgumentList >> withoutDefaultValue [ "remove the defaultArg if no new value was assigned to it" diff --git a/src/Microdown/MicElement.class.st b/src/Microdown/MicElement.class.st index 00c65d78..23c3b918 100644 --- a/src/Microdown/MicElement.class.st +++ b/src/Microdown/MicElement.class.st @@ -151,6 +151,18 @@ MicElement >> removeProperty: aKey ifAbsent: aBlock [ ^ answer ] +{ #category : 'replacement' } +MicElement >> replaceBy: aMicElement [ + "Replace the receiver by the argument. + Make sure that the new element parent is the parent of the receiver." + + parent replace: self by: aMicElement. + "We use basicParent and not parent, + because parent is doing an addChild:" + aMicElement basicParent: parent. + parent := nil. +] + { #category : 'public' } MicElement >> resolveFrom: aBase [ Microdown resolveDocument: self withBase: aBase diff --git a/src/Microdown/MicEnvironmentBlock.class.st b/src/Microdown/MicEnvironmentBlock.class.st index 1cb64811..ca98bb59 100644 --- a/src/Microdown/MicEnvironmentBlock.class.st +++ b/src/Microdown/MicEnvironmentBlock.class.st @@ -176,6 +176,14 @@ MicEnvironmentBlock >> extractFirstLineFrom: aLine [ ifFalse: [ firstLine ] ] +{ #category : 'parse support' } +MicEnvironmentBlock >> initialize [ + + super initialize. + arguments := MicArgumentList new + +] + { #category : 'markups' } MicEnvironmentBlock >> lineStartMarkup [ diff --git a/src/Microdown/MicEvaluatedBlock.class.st b/src/Microdown/MicEvaluatedBlock.class.st index b00911d1..c0383fea 100644 --- a/src/Microdown/MicEvaluatedBlock.class.st +++ b/src/Microdown/MicEvaluatedBlock.class.st @@ -47,6 +47,12 @@ MicEvaluatedBlock >> printOn: stream [ ] +{ #category : 'replacement' } +MicEvaluatedBlock >> replace: aBlock by: anotherBlock [ + + self children replaceAll: aBlock with: anotherBlock +] + { #category : 'accessing' } MicEvaluatedBlock >> textElement [ "Should only be used for tests" diff --git a/src/Microdown/MicHeaderBlock.class.st b/src/Microdown/MicHeaderBlock.class.st index 7966fd66..f9f45ca0 100644 --- a/src/Microdown/MicHeaderBlock.class.st +++ b/src/Microdown/MicHeaderBlock.class.st @@ -56,8 +56,9 @@ MicHeaderBlock >> formattedCode [ { #category : 'accessing' } MicHeaderBlock >> header [ "I am used to get an adhoc string for the header" - ^ String streamContents: [ :s | - children do: [ :e | s nextPutAll: e bodystring ] ] + + ^ String streamContents: [ :s | + children do: [ :e | s nextPutAll: e bodyString ] ] ] { #category : 'accessing' } diff --git a/src/Microdown/MicSlideBlock.class.st b/src/Microdown/MicSlideBlock.class.st index 577670ed..24570f0b 100644 --- a/src/Microdown/MicSlideBlock.class.st +++ b/src/Microdown/MicSlideBlock.class.st @@ -10,6 +10,8 @@ to have the same slide but on two different layouts and not emit both. - bullet 3 !> ``` + +It should be noted that the title is not reified as a Microdown object because so far the extensions does not support a way to describe the argument that should be reified. " Class { #name : 'MicSlideBlock', @@ -46,3 +48,9 @@ MicSlideBlock >> tag [ MicSlideBlock >> title [ ^ arguments at: 'title' ifAbsent: [ '' ] ] + +{ #category : 'accessing' } +MicSlideBlock >> title: aString [ + + arguments at: #title put: aString +]