Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
55 changes: 55 additions & 0 deletions src/Microdown-Tests/MicSecondaryRootBlockTest.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
Class {
#name : 'MicSecondaryRootBlockTest',
#superclass : 'TestCase',
#category : 'Microdown-Tests-Model',
#package : 'Microdown-Tests',
#tag : 'Model'
}

{ #category : 'tests' }
MicSecondaryRootBlockTest >> testAcceptDoubleDispatch [

| block visitor |
block := MicSecondaryRootBlock new.
visitor := MicrodownVisitor new.
self shouldnt: [ block accept: visitor ] raise: Error
]

{ #category : 'tests' }
MicSecondaryRootBlockTest >> testCanHoldChildren [

| root child |
root := MicSecondaryRootBlock new.
child := MicParagraphBlock new.

root addChild: child.

self assert: root children size equals: 1.
self assert: root children first equals: child
]

{ #category : 'tests' }
MicSecondaryRootBlockTest >> testFileProperty [

| root fileRef |
root := MicSecondaryRootBlock new.
fileRef := 'fichierInclus.md'.

root file: fileRef.

self assert: root file equals: fileRef
]

{ #category : 'tests' }
MicSecondaryRootBlockTest >> testIsSecondaryRoot [

| mainRoot secondaryRoot |
mainRoot := MicRootBlock new.
secondaryRoot := MicSecondaryRootBlock new.

self deny: mainRoot isSecondaryRoot.

secondaryRoot parent: mainRoot.

self assert: secondaryRoot isSecondaryRoot
]
8 changes: 6 additions & 2 deletions src/Microdown-Transformer/MicFileIncluder.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -113,14 +113,18 @@ MicFileIncluder >> topFile: aFileReference [
MicFileIncluder >> visitInputFile: anInputFileAnnotation [
"I load the file and if the file exist I replace the node of the annotation by the content of the file."

| inputRef inputDoc |
| inputRef inputDoc newRoot |
inputRef := anInputFileAnnotation path.
[ inputDoc := inputRef loadMicrodown inlineInputFiles]
on: MicResourceReferenceError
do: [ :error | isStrict
ifFalse: [ ^ self ]
ifTrue: [ error pass ]].

self replaceCurrentNodeBy: inputDoc children
newRoot := MicSecondaryRootBlock new.
newRoot file: inputRef.
newRoot children: inputDoc children.

self replaceCurrentNodeBy: { newRoot }

]
6 changes: 6 additions & 0 deletions src/Microdown/MicRootBlock.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,12 @@ MicRootBlock >> initialize [
debugId := self class nextDebugId.
]

{ #category : 'debugging' }
MicRootBlock >> isSecondaryRoot [

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It could be smarter. I wonder. Because a main root block parent is nil while by construction a secondaryRootBlock should be nested into something.


^ parent notNil
]

{ #category : 'hooks' }
MicRootBlock >> massageLine: aLine [
"In some cases an element may want to massage the line such as removing leading tab. By default we delegate to the parent because environments may contain nodes such as code block and this is this nesting that will determine what should be done with the tab. In such a case the environment should remov the tabs. Here on the root we do nothing special."
Expand Down
28 changes: 28 additions & 0 deletions src/Microdown/MicSecondaryRootBlock.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
Class {
#name : 'MicSecondaryRootBlock',
#superclass : 'MicRootBlock',
#instVars : [
'file'

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you look in the superclass fromFile is already defined so
either we use fromFile implementation (I do not remember but may be it was with managed with a property and we could move it using an instance variable (and remove the implementation in secondaryRootBlock

],
#category : 'Microdown-Model',
#package : 'Microdown',
#tag : 'Model'
}

{ #category : 'testing' }
MicSecondaryRootBlock >> accept: aVisitor [

^ aVisitor visitSecondaryRootBlock: self
]

{ #category : 'testing' }
MicSecondaryRootBlock >> file [

^ file
]

{ #category : 'testing' }
MicSecondaryRootBlock >> file: aFileReference [

file := aFileReference
]
6 changes: 6 additions & 0 deletions src/Microdown/MicrodownVisitor.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,12 @@ MicrodownVisitor >> visitScript: aSlide [
^ self visitChildrenOf: aSlide
]

{ #category : 'visiting' }
MicrodownVisitor >> visitSecondaryRootBlock: aSecondaryRootBlock [

^ self visitRoot: aSecondaryRootBlock
]

{ #category : 'visiting' }
MicrodownVisitor >> visitSegment: aSegment [
"subclassResponsibility"
Expand Down
Loading