Skip to content

Commit

Permalink
Fix #920
Browse files Browse the repository at this point in the history
In fact the label was concatenated with the body and it was a mistake (at the minimum the label should have been turned into a Text object). I removed the idea that faulty labels are kept around and placed in a body.
Now faulty labels are just turned into a note.
Simple.
  • Loading branch information
Ducasse committed Dec 1, 2024
1 parent 897fb80 commit 3641d42
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ MicAbstractLaTexWriterTest >> testAnnotatedParagraph [
self writeFor: factory annotatedSample.
self assert: writer contents equals: newLine ,
'\begin{note}', newLine ,
'label Foo \textit{bar}', newLine ,
'Foo \textit{bar}', newLine ,
'\end{note}'
]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ MicTextualMicrodownExporterTest >> testAnnotated [
| mic |
mic := parser parse: factory annotatedSample.
self assert: (mic accept: visitor) contents equals: '>[!note]
> label Foo _bar_
> Foo _bar_

'
]
Expand Down
63 changes: 41 additions & 22 deletions src/Microdown-Tests/MicAnnotatedParagraphBlockTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,40 @@ MicAnnotatedParagraphBlockTest >> subjectClass [
^ MicAnnotatedParagraphBlock
]

{ #category : 'tests' }
MicAnnotatedParagraphBlockTest >> testAnnotatedParagraphBreakingTheParser [

| root annotatedParagraph |
root := parser parse: '
>[! important] I would like a piece of code here ]
> This is an important information'.
self assert: root children size equals: 1.
annotatedParagraph := root children first.
self
assert: (annotatedParagraph isKindOf: MicAnnotatedParagraphBlock);
assert: annotatedParagraph label equals: 'important';
assert: annotatedParagraph text
equals: 'This is an important information'
]

{ #category : 'tests' }
MicAnnotatedParagraphBlockTest >> testAnnotatedParagraphBreakingTheParser2 [

| root annotatedParagraph |
root := parser parse: '
>[! SD] I would like a piece of code here
> This is an important information'.
self assert: root children size equals: 1.
annotatedParagraph := root children first.
self
assert: (annotatedParagraph isKindOf: MicAnnotatedParagraphBlock);
assert: annotatedParagraph label equals: 'note';
assert: annotatedParagraph text
equals: 'This is an important information'
]

{ #category : 'tests' }
MicAnnotatedParagraphBlockTest >> testBasicAnnotetedParagraph [

Expand All @@ -30,7 +64,7 @@ MicAnnotatedParagraphBlockTest >> testBasicAnnotetedParagraph [
MicAnnotatedParagraphBlockTest >> testBasicAnnotetedParagraphIgnoreExtraTextInFirstLine [

| root annotatedParagraph |
root := parser parse: '>[! important ] This is an important information
root := parser parse: '>[! important ] Let us be less silly
> This is an other information'.
self assert: root children size equals: 1.
annotatedParagraph := root children first.
Expand Down Expand Up @@ -80,31 +114,16 @@ MicAnnotatedParagraphBlockTest >> testBasicAnnotetedParagraphWithANonSupportedLa
assert: (annotatedParagraph isKindOf: MicAnnotatedParagraphBlock);
assert: annotatedParagraph label equals: 'note';
assert: annotatedParagraph text
equals: 'test This is an important information'
]

{ #category : 'tests' }
MicAnnotatedParagraphBlockTest >> testBasicAnnotetedParagraphWithANonSupportedLabelWithUpperCase [

| root annotatedParagraph |
root := parser parse: '>[! Test ]
> This is an important information'.
self assert: root children size equals: 1.
annotatedParagraph := root children first.
self
assert: (annotatedParagraph isKindOf: MicAnnotatedParagraphBlock);
assert: annotatedParagraph label equals: 'note';
assert: annotatedParagraph text
equals: 'Test This is an important information'
equals: 'This is an important information'
]

{ #category : 'tests' }
MicAnnotatedParagraphBlockTest >> testBasicAnnotetedParagraphWithBlodText [
MicAnnotatedParagraphBlockTest >> testBasicAnnotetedParagraphWithBoldText [

| root annotatedParagraph |
root := parser parse:
'>[! important ]
> This is an **important** information'.
> This is an **crucial** information'.
self assert: root children size equals: 1.
annotatedParagraph := root children first.
self
Expand All @@ -115,20 +134,20 @@ MicAnnotatedParagraphBlockTest >> testBasicAnnotetedParagraphWithBlodText [
(annotatedParagraph textElements second isKindOf:
MicBoldFormatBlock);
assert: annotatedParagraph textElements second plainText
equals: 'important'
equals: 'crucial'
]

{ #category : 'tests' }
MicAnnotatedParagraphBlockTest >> testBasicAnnotetedParagraphWithLabelHavingUpperCase [

| root annotatedParagraph |
root := parser parse: '>[! ImporTanT ]
> This is an important information'.
> This is a crucial information'.
self assert: root children size equals: 1.
annotatedParagraph := root children first.
self
assert: (annotatedParagraph isKindOf: MicAnnotatedParagraphBlock);
assert: annotatedParagraph label equals: 'important';
assert: annotatedParagraph text
equals: 'This is an important information'
equals: 'This is a crucial information'
]
8 changes: 3 additions & 5 deletions src/Microdown/MicAnnotatedParagraphBlock.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,14 @@ MicAnnotatedParagraphBlock >> closeMe [
{ #category : 'accessing' }
MicAnnotatedParagraphBlock >> defaultLabel [

^ #note
^ 'note'
]

{ #category : 'initialization' }
MicAnnotatedParagraphBlock >> initialize [

super initialize.
validLabels := { #note. #important. #todo }
validLabels := { 'note' . 'important' . 'todo' }
]

{ #category : 'accessing' }
Expand Down Expand Up @@ -81,7 +81,5 @@ MicAnnotatedParagraphBlock >> verifyLabel [
isValid := validLabels includes: label asLowercase.
isValid
ifTrue: [ label := label asLowercase ]
ifFalse: [
body := label , String space , body.
label := self defaultLabel ]
ifFalse: [ label := self defaultLabel ]
]

0 comments on commit 3641d42

Please sign in to comment.