diff --git a/src/Microdown-HTMLExporter-Tests/MicHTMLVisitorTest.class.st b/src/Microdown-HTMLExporter-Tests/MicHTMLVisitorTest.class.st index 81fb1012..668f4ec0 100644 --- a/src/Microdown-HTMLExporter-Tests/MicHTMLVisitorTest.class.st +++ b/src/Microdown-HTMLExporter-Tests/MicHTMLVisitorTest.class.st @@ -148,7 +148,9 @@ MicHTMLVisitorTest >> testCreateAnnotationCompound [ | result | result := writer convertMicString: '# This is a title -!!note Body of annotated block +>[!note] +> Body of annotated block + this is another string'. self @@ -166,7 +168,8 @@ MicHTMLVisitorTest >> testCreateAnnotationSimple [ self assert: writer contents equals: String empty. result := writer convertMicString: - '!!note Body of annotated block'. + '>[!note] +> Body of annotated block'. self assert: result trimBoth equals: diff --git a/src/Microdown-PrettyPrinter-Tests/MicTextualMicrodownExporterTest.class.st b/src/Microdown-PrettyPrinter-Tests/MicTextualMicrodownExporterTest.class.st index 972e43b5..5a1456af 100644 --- a/src/Microdown-PrettyPrinter-Tests/MicTextualMicrodownExporterTest.class.st +++ b/src/Microdown-PrettyPrinter-Tests/MicTextualMicrodownExporterTest.class.st @@ -71,7 +71,8 @@ MicTextualMicrodownExporterTest >> testAnnotated [ | mic | mic := parser parse: factory annotatedSample. - self assert: (mic accept: visitor) contents equals: '!!note label Foo _bar_ + self assert: (mic accept: visitor) contents equals: '>[!note] +> label Foo _bar_ ' ] diff --git a/src/Microdown-Tests/MicAnnotatedParagraphTest.class.st b/src/Microdown-Tests/MicAnnotatedParagraphTest.class.st index 84ccee7f..aa9975ae 100644 --- a/src/Microdown-Tests/MicAnnotatedParagraphTest.class.st +++ b/src/Microdown-Tests/MicAnnotatedParagraphTest.class.st @@ -15,7 +15,8 @@ MicAnnotatedParagraphTest >> subjectClass [ MicAnnotatedParagraphTest >> testBasicAnnotetedParagraph [ | root annotatedParagraph | - root := parser parse: '!!important This is an important information'. + root := parser parse: '>[! important ] +> This is an important information'. self assert: root children size equals: 1. annotatedParagraph := root children first. self @@ -25,12 +26,39 @@ MicAnnotatedParagraphTest >> testBasicAnnotetedParagraph [ equals: 'This is an important information' ] +{ #category : 'tests' } +MicAnnotatedParagraphTest >> testBasicAnnotetedParagraphIgnoreExtraTextInFirstLine [ + + | root annotatedParagraph | + root := parser parse: '>[! important ] This is an important information +> This is an other information'. + self assert: root children size equals: 1. + annotatedParagraph := root children first. + self + assert: (annotatedParagraph isKindOf: MicAnnotatedParagraph); + assert: annotatedParagraph label equals: 'important'; + assert: annotatedParagraph text + equals: 'This is an other information' +] + +{ #category : 'tests' } +MicAnnotatedParagraphTest >> testBasicAnnotetedParagraphWhitoutClosingBracket [ + + | root annotatedParagraph | + root := parser parse: '>[! important +> This is an important information'. + self assert: root children size equals: 1. + annotatedParagraph := root children first. + self + assert: (annotatedParagraph isKindOf: MicBlockQuoteBlock) +] + { #category : 'tests' } MicAnnotatedParagraphTest >> testBasicAnnotetedParagraphWithALineBreak [ | root annotatedParagraph | - root := parser parse: '!!important -This is an important information'. + root := parser parse: '>[! important ] +> This is an important information'. self assert: root children size equals: 1. annotatedParagraph := root children first. self @@ -44,7 +72,8 @@ This is an important information'. MicAnnotatedParagraphTest >> testBasicAnnotetedParagraphWithANonSupportedLabel [ | root annotatedParagraph | - root := parser parse: '!!test This is an important information'. + root := parser parse: '>[! test ] +> This is an important information'. self assert: root children size equals: 1. annotatedParagraph := root children first. self @@ -58,7 +87,8 @@ MicAnnotatedParagraphTest >> testBasicAnnotetedParagraphWithANonSupportedLabel [ MicAnnotatedParagraphTest >> testBasicAnnotetedParagraphWithANonSupportedLabelWithUpperCase [ | root annotatedParagraph | - root := parser parse: '!!Test This is an important information'. + root := parser parse: '>[! Test ] +> This is an important information'. self assert: root children size equals: 1. annotatedParagraph := root children first. self @@ -73,7 +103,8 @@ MicAnnotatedParagraphTest >> testBasicAnnotetedParagraphWithBlodText [ | root annotatedParagraph | root := parser parse: - '!!important This is an **important** information'. + '>[! important ] +> This is an **important** information'. self assert: root children size equals: 1. annotatedParagraph := root children first. self @@ -91,7 +122,8 @@ MicAnnotatedParagraphTest >> testBasicAnnotetedParagraphWithBlodText [ MicAnnotatedParagraphTest >> testBasicAnnotetedParagraphWithLabelHavingUpperCase [ | root annotatedParagraph | - root := parser parse: '!!ImporTanT This is an important information'. + root := parser parse: '>[! ImporTanT ] +> This is an important information'. self assert: root children size equals: 1. annotatedParagraph := root children first. self diff --git a/src/Microdown-Tests/MicMicrodownSnippetFactory.class.st b/src/Microdown-Tests/MicMicrodownSnippetFactory.class.st index 750acbf2..aa8937d8 100644 --- a/src/Microdown-Tests/MicMicrodownSnippetFactory.class.st +++ b/src/Microdown-Tests/MicMicrodownSnippetFactory.class.st @@ -87,7 +87,8 @@ MicMicrodownSnippetFactory >> anchorWithSpaceInsideSample [ { #category : 'anchor' } MicMicrodownSnippetFactory >> annotatedSample [ - ^ '!!label Foo _bar_ + ^ '>[!label] +> Foo _bar_ ' ] diff --git a/src/Microdown-Tests/MicMicrodownTextualBuilderTest.class.st b/src/Microdown-Tests/MicMicrodownTextualBuilderTest.class.st index 16a8b8ef..1ea8e30b 100644 --- a/src/Microdown-Tests/MicMicrodownTextualBuilderTest.class.st +++ b/src/Microdown-Tests/MicMicrodownTextualBuilderTest.class.st @@ -52,7 +52,8 @@ MicMicrodownTextualBuilderTest >> testAnchorReference [ { #category : 'tests - anchor' } MicMicrodownTextualBuilderTest >> testAnnotated [ - self assert: (builder annotated: 'anAnnotation' paragraph: [ builder text: 'anAnnotatedParagraph' ]) contents equals: '!!anAnnotation anAnnotatedParagraph', String cr + self assert: (builder annotated: 'anAnnotation' paragraph: [ builder text: 'anAnnotatedParagraph' ]) contents equals: '>[!anAnnotation] +> anAnnotatedParagraph', String cr ] { #category : 'tests - anchor' } diff --git a/src/Microdown-Tests/MicrodownParserTest.class.st b/src/Microdown-Tests/MicrodownParserTest.class.st index eb8a61ec..284a6892 100644 --- a/src/Microdown-Tests/MicrodownParserTest.class.st +++ b/src/Microdown-Tests/MicrodownParserTest.class.st @@ -88,7 +88,8 @@ MicrodownParserTest >> testAnchorMarkupInsideLine [ MicrodownParserTest >> testAnnotatedBlock [ | source root annotated | - source := AnnotatedParagraphMarkup , 'important this is an important paragraph on one line.'. + source := AnnotatedParagraphMarkup , 'important] +> this is an important paragraph on one line.'. root := parser parse: source. self assert: root children size equals: 1. annotated := root children first. @@ -102,8 +103,9 @@ MicrodownParserTest >> testAnnotatedBlock [ MicrodownParserTest >> testAnnotatedBlockOnMultipleLinesParserLogic [ | source root annotated line | - source := (AnnotatedParagraphMarkup , 'important this is an -important point because...!') readStream. + source := (AnnotatedParagraphMarkup , 'important] +> this is an +> important point because...!') readStream. "first the root block" root := parser parse: ''. @@ -115,9 +117,15 @@ important point because...!') readStream. self assert: annotated parent equals: root. self assert: annotated label equals: 'important'. - self assert: (annotated instVarNamed: 'body') equals: 'this is an'. "third the second line" + line := source nextLine. + self assert: (annotated canConsumeLine: line). + annotated := parser handleLine: line. + self assert: parser current equals: annotated. + self assert: (annotated instVarNamed: 'body') equals: 'this is an'. + +"fourth the third line" line := source nextLine. self assert: (annotated canConsumeLine: line). annotated := parser handleLine: line. @@ -130,8 +138,9 @@ important point because...!'. { #category : 'tests - annotated-paragraph' } MicrodownParserTest >> testAnnotatedBlockOnTwoLines [ | source root annotated | - source := AnnotatedParagraphMarkup , 'important this is an important -paragraph on two lines.'. + source := AnnotatedParagraphMarkup , 'important] +> this is an important +> paragraph on two lines.'. root := parser parse: source. self assert: root children size equals: 1. annotated := root children first. @@ -144,8 +153,9 @@ paragraph on two lines.' { #category : 'tests - annotated-paragraph' } MicrodownParserTest >> testAnnotatedBlockOnTwoLinesWithFormatting [ | source root annotated | - source := AnnotatedParagraphMarkup , 'important **this** is an _important_ -paragraph on two lines.'. + source := AnnotatedParagraphMarkup , 'important] +> **this** is an _important_ +> paragraph on two lines.'. root := parser parse: source. self assert: root children size equals: 1. annotated := root children first. @@ -160,7 +170,8 @@ paragraph on two lines.))' MicrodownParserTest >> testAnnotatedBlockTextElements [ | source root annotated | - source := AnnotatedParagraphMarkup , 'important this is an **important** paragraph on one line.'. + source := AnnotatedParagraphMarkup , 'important] +> this is an **important** paragraph on one line.'. root := parser parse: source. self assert: root children size equals: 1. annotated := root children first. @@ -176,8 +187,9 @@ MicrodownParserTest >> testAnnotatedBlockWithListParserLogic [ "The test does not test what we want. We want a listblock inside the annotatedBlock" | source root annotated line | self flag: #fixme. - source := (AnnotatedParagraphMarkup , 'important this is a point -- one + source := (AnnotatedParagraphMarkup , 'important] +> this is a point +> - one * two ' ) readStream. parser := self parser. @@ -192,11 +204,18 @@ MicrodownParserTest >> testAnnotatedBlockWithListParserLogic [ self assert: annotated parent equals: root. self assert: annotated label equals: 'important'. - self assert: (annotated instVarNamed: 'body') equals: 'this is a point'. "third the second line" line := source nextLine. + self assert: (annotated canConsumeLine: line). + annotated := parser handleLine: line. + self assert: parser current equals: annotated. + self assert: (annotated instVarNamed: 'body') equals: 'this is a point'. + + "fourth the third line" + line := source nextLine. + self assert: (annotated canConsumeLine: line). annotated := parser handleLine: line. self assert: parser current equals: annotated. diff --git a/src/Microdown/MicAbstractAnnotatedBlock.class.st b/src/Microdown/MicAbstractAnnotatedBlock.class.st index 26fd2bb7..60d27d54 100644 --- a/src/Microdown/MicAbstractAnnotatedBlock.class.st +++ b/src/Microdown/MicAbstractAnnotatedBlock.class.st @@ -18,14 +18,18 @@ MicAbstractAnnotatedBlock >> addLineAndReturnNextNode: line [ ifTrue: [ ^ self ]. label ifNil: [ - | indexOfFirstSpace | - indexOfFirstSpace := line indexOf: Character space. - label := indexOfFirstSpace = 0 - ifTrue: [ '' ] - ifFalse: [line copyFrom: self lineMarkup size + 1 to: indexOfFirstSpace - 1.]. - body := (line copyFrom: indexOfFirstSpace + 1 to: line size) trim.] - ifNotNil: [ body = '' ifTrue: [ body := body , line ] - ifFalse: [ body := body , String cr , line ]] + | indexOfFirstClosingBracket | + indexOfFirstClosingBracket := line indexOf: $]. + label := indexOfFirstClosingBracket = 0 + ifTrue: [ parent children removeLast. ^ self createMicBlockQuoteBlock: line ] + ifFalse: [line copyFrom: self lineMarkup size + 1 to: indexOfFirstClosingBracket - 1. + ]. + label := label trim] + ifNotNil: [ | treatedLine | + treatedLine := self extractLine: line. + body := body + ifNil: [ treatedLine ] + ifNotNil: [ body , String cr , treatedLine ]] ] { #category : 'accessing' } @@ -41,6 +45,22 @@ MicAbstractAnnotatedBlock >> canConsumeLine: line [ ^ line isNotEmpty ] +{ #category : 'creating classes' } +MicAbstractAnnotatedBlock >> createMicBlockQuoteBlock: line [ + +^ MicBlockQuoteBlock new + setParser: parser; + parent: parent; + addLineAndReturnNextNode: line + + +] + +{ #category : 'actions' } +MicAbstractAnnotatedBlock >> extractLine: line [ + ^ (line copyFrom: 2 to: line size) trim +] + { #category : 'initialization' } MicAbstractAnnotatedBlock >> initialize [ diff --git a/src/Microdown/MicMicrodownSharedPool.class.st b/src/Microdown/MicMicrodownSharedPool.class.st index cd24cad4..bf63619d 100644 --- a/src/Microdown/MicMicrodownSharedPool.class.st +++ b/src/Microdown/MicMicrodownSharedPool.class.st @@ -57,7 +57,7 @@ MicMicrodownSharedPool class >> initialize [ "self initialize" AnchorMarkup := '@'. - AnnotatedParagraphMarkup := '!!'. + AnnotatedParagraphMarkup := '>[!'. CodeblockMarkup := '```'. CommentedLineMarkup := '%'. EnvironmentClosingBlockMarkup := '!>'. diff --git a/src/Microdown/MicMicrodownTextualBuilder.class.st b/src/Microdown/MicMicrodownTextualBuilder.class.st index 6c1d4b1b..bebfc7a5 100644 --- a/src/Microdown/MicMicrodownTextualBuilder.class.st +++ b/src/Microdown/MicMicrodownTextualBuilder.class.st @@ -524,7 +524,10 @@ MicMicrodownTextualBuilder >> rawAnnotated: annotation paragraph: aBlock [ attention there is not space between the !! and the label (annotation in pillar) or we should improve the microdown parser" self raw: AnnotatedParagraphMarkup; - raw: annotation; + raw: annotation; + raw: $]; + raw: Character cr; + raw: $>; raw: String space; rawParagraph: aBlock