From 3641d42cfbad47d3aa46c3d16a1a35df37bf7ff8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phaneDucasse?= Date: Sun, 1 Dec 2024 16:09:40 +0100 Subject: [PATCH] Fix #920 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. --- .../MicAbstractLaTexWriterTest.class.st | 2 +- .../MicTextualMicrodownExporterTest.class.st | 2 +- .../MicAnnotatedParagraphBlockTest.class.st | 63 ++++++++++++------- .../MicAnnotatedParagraphBlock.class.st | 8 +-- 4 files changed, 46 insertions(+), 29 deletions(-) diff --git a/src/Microdown-LaTeXExporter-Tests/MicAbstractLaTexWriterTest.class.st b/src/Microdown-LaTeXExporter-Tests/MicAbstractLaTexWriterTest.class.st index f5aafd3d..877d8809 100644 --- a/src/Microdown-LaTeXExporter-Tests/MicAbstractLaTexWriterTest.class.st +++ b/src/Microdown-LaTeXExporter-Tests/MicAbstractLaTexWriterTest.class.st @@ -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}' ] diff --git a/src/Microdown-PrettyPrinter-Tests/MicTextualMicrodownExporterTest.class.st b/src/Microdown-PrettyPrinter-Tests/MicTextualMicrodownExporterTest.class.st index 096c2c2a..0a0d1875 100644 --- a/src/Microdown-PrettyPrinter-Tests/MicTextualMicrodownExporterTest.class.st +++ b/src/Microdown-PrettyPrinter-Tests/MicTextualMicrodownExporterTest.class.st @@ -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_ ' ] diff --git a/src/Microdown-Tests/MicAnnotatedParagraphBlockTest.class.st b/src/Microdown-Tests/MicAnnotatedParagraphBlockTest.class.st index e4aee452..e33378a4 100644 --- a/src/Microdown-Tests/MicAnnotatedParagraphBlockTest.class.st +++ b/src/Microdown-Tests/MicAnnotatedParagraphBlockTest.class.st @@ -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 [ @@ -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. @@ -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 @@ -115,7 +134,7 @@ MicAnnotatedParagraphBlockTest >> testBasicAnnotetedParagraphWithBlodText [ (annotatedParagraph textElements second isKindOf: MicBoldFormatBlock); assert: annotatedParagraph textElements second plainText - equals: 'important' + equals: 'crucial' ] { #category : 'tests' } @@ -123,12 +142,12 @@ MicAnnotatedParagraphBlockTest >> testBasicAnnotetedParagraphWithLabelHavingUppe | 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' ] diff --git a/src/Microdown/MicAnnotatedParagraphBlock.class.st b/src/Microdown/MicAnnotatedParagraphBlock.class.st index ca64cea1..2fb3ec0e 100644 --- a/src/Microdown/MicAnnotatedParagraphBlock.class.st +++ b/src/Microdown/MicAnnotatedParagraphBlock.class.st @@ -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' } @@ -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 ] ]