Skip to content

Commit

Permalink
Merge branch 'dev' of github.com:pillar-markup/Microdown into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
Ducasse committed Nov 2, 2024
2 parents 353cedd + a6c6480 commit 965856e
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 10 deletions.
1 change: 1 addition & 0 deletions src/Microdown-BookTester/MicCodeBlockValidator.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ MicCodeBlockValidator >> validTests [
MicCodeBlockValidator >> visitCode: aCodeBlock [
"Creates an instance of PRBookTestResult with parameters depending of the type of the codeblock."


(strategies keys includes: aCodeBlock mainExtensionTag)
ifFalse: [ ^ self ].

Expand Down
60 changes: 52 additions & 8 deletions src/Microdown-Tests/MicCodeBlockTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -72,21 +72,25 @@ MicCodeBlockTest >> testCodeBlockWithNestedCodeBlock [
"This test shows that we can write a code block inside a code block but that the later is not interpreter."

| source root code textBody |
textBody := ' ```
my fancy code
is really cool
```'.
source := CodeblockMarkup, String cr, textBody, String cr, CodeblockMarkup.
source := '```
This is a first level code
```
this is one with tabs
```
```
this is one with space
```
``` '.

root := parser parse: source.

self
assert: root children size
equals: 1.
code := root children first.
self assert: code children isEmpty.
self
assert: code code
equals: textBody.
self assert: code class equals: MicCodeBlock

]

Expand Down Expand Up @@ -355,6 +359,30 @@ Color >> asMorph
self assert: code mainExtensionTag equals: #caption
]

{ #category : 'tests' }
MicCodeBlockTest >> testMainExtensionTag2 [
"
```example=true
3 + 7
>> 10
```
"

| source root code textBody argument |
textBody := '3 + 7
>>> 10'.
argument := 'example=true'.
source := CodeblockMarkup , argument , String cr , textBody
, String cr , CodeblockMarkup.
root := self parser parse: source.
self assert: root children size equals: 1.
code := root children first.
self assert: code code equals: textBody.
self assert: (code arguments at: #language) equals: 'Pharo'.
self assert: code mainExtensionTag equals: #example.

]

{ #category : 'tests - arguments' }
MicCodeBlockTest >> testMainExtensionTagForSync [

Expand Down Expand Up @@ -436,6 +464,22 @@ Color >> asMorph
self assert: code mainExtensionTag equals: #caption
]

{ #category : 'tests - code' }
MicCodeBlockTest >> testNestedCodeBlockOnlyProducesOneCodeBlock [

| doc |
doc := Microdown parse: '```
```example=true&expectedFailure=true
3 + 4
>>> 12
```
```'.

self assert: doc children size equals: 1.
self assert: doc children first class equals: MicCodeBlock.

]

{ #category : 'tests' }
MicCodeBlockTest >> testOpenCanConsumeLine [
| source root textBody argument line code |
Expand Down
7 changes: 7 additions & 0 deletions src/Microdown/MicAbstractBlock.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,13 @@ MicAbstractBlock >> listItemBlockClass [
^ MicListItemBlock
]

{ #category : 'hooks' }
MicAbstractBlock >> 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 environment 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."

^ self parent massageLine: aLine
]

{ #category : 'public' }
MicAbstractBlock >> nestedLevel [
"Return the nesting level of main blocks. Basically only list increases this."
Expand Down
9 changes: 9 additions & 0 deletions src/Microdown/MicEnvironmentBlock.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,13 @@ MicEnvironmentBlock >> addLineAndReturnNextNode: line [
"add line to this node.
Notice, the action is allowed to create new nodes in the block tree.
Returns the node to handle next line - typically self."
| withoutPreTabs |
isClosed
ifTrue: [ ^ self ].
withoutPreTabs := line withoutPreTabs.
"Here the withoutPreTabs is probably not necessary because handlingPrefixTabOfLine: should do its job."
(self doesLineStartWithStopMarkup: withoutPreTabs)
ifTrue: [ ^ self ].
firstLine
Expand Down Expand Up @@ -195,3 +198,9 @@ MicEnvironmentBlock >> lineStopMarkup [

^ EnvironmentClosingBlockMarkup
]

{ #category : 'handle' }
MicEnvironmentBlock >> massageLine: aLine [

^ aLine withoutPreTabs
]
7 changes: 7 additions & 0 deletions src/Microdown/MicRootBlock.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,13 @@ MicRootBlock >> indent [
^0
]

{ #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."

^ aLine
]

{ #category : 'testing' }
MicRootBlock >> metaDataElement [
"if self hasMetaDataElement then metaDataElement returns it.
Expand Down
2 changes: 1 addition & 1 deletion src/Microdown/MicStartStopMarkupBlock.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ MicStartStopMarkupBlock >> canConsumeLine: line [

{ #category : 'testing' }
MicStartStopMarkupBlock >> doesLineStartWithStopMarkup: line [

"return if the line starts with a stop markup"
^ line beginsWith: self lineStopMarkup
]
Expand Down
2 changes: 1 addition & 1 deletion src/Microdown/MicrodownParser.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ MicrodownParser >> handleLine: line [
-if the current block can consume the line, it manages it and this potentially creates a new block that becomes the current one.
When the line is not consumed, the current block is closed and its parent becomes the current one and the process is called back to treat the line."

(current canConsumeLine: (line withoutPreTabs))
(current canConsumeLine: (current massageLine: line))
ifTrue: [
current := current addLineAndReturnNextNode: line.
^ current ]
Expand Down

0 comments on commit 965856e

Please sign in to comment.