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 new file mode 100644 index 00000000..36813a83 --- /dev/null +++ b/src/Microdown-Tests/MicAnnotatedParagraphTest.class.st @@ -0,0 +1,34 @@ +Class { + #name : 'MicAnnotatedParagraphTest', + #superclass : 'MicBlockTest', + #category : 'Microdown-Tests-Parser', + #package : 'Microdown-Tests', + #tag : 'Parser' +} + +{ #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) +] 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