Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 846 better syntax for annotated paragraph #865

Merged
7 changes: 5 additions & 2 deletions src/Microdown-HTMLExporter-Tests/MicHTMLVisitorTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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_
'
]

Expand Down
46 changes: 39 additions & 7 deletions src/Microdown-Tests/MicAnnotatedParagraphTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -25,12 +26,39 @@ MicAnnotatedParagraphTest >> testBasicAnnotetedParagraph [
equals: 'This is an important information'
]

{ #category : 'tests' }
MicAnnotatedParagraphTest >> testBasicAnnotetedParagraphIgnoreExtraTextInFirstLine [
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Super nice test :)


| 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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion src/Microdown-Tests/MicMicrodownSnippetFactory.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ MicMicrodownSnippetFactory >> anchorWithSpaceInsideSample [

{ #category : 'anchor' }
MicMicrodownSnippetFactory >> annotatedSample [
^ '!!label Foo _bar_
^ '>[!label]
> Foo _bar_
'
]

Expand Down
3 changes: 2 additions & 1 deletion src/Microdown-Tests/MicMicrodownTextualBuilderTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -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' }
Expand Down
43 changes: 31 additions & 12 deletions src/Microdown-Tests/MicrodownParserTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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: ''.
Expand All @@ -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.
Expand All @@ -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.
Expand All @@ -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.
Expand All @@ -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.
Expand All @@ -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.
Expand All @@ -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.
Expand Down
36 changes: 28 additions & 8 deletions src/Microdown/MicAbstractAnnotatedBlock.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -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: $].
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder what is the impact if the line does not contain ]

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After getting the index of the first ], I test if he egal to 0.
If true, I removed the AnnotatedParagraphe to MicRootBlock, and I replace by a MicBlockQuoteBlock

indexOfFirstClosingBracket = 0
ifTrue: [ parent children removeLast. ^ self createMicBlockQuoteBlock: line ]

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' }
Expand All @@ -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 [

Expand Down
2 changes: 1 addition & 1 deletion src/Microdown/MicMicrodownSharedPool.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ MicMicrodownSharedPool class >> initialize [
"self initialize"

AnchorMarkup := '@'.
AnnotatedParagraphMarkup := '!!'.
AnnotatedParagraphMarkup := '>[!'.
CodeblockMarkup := '```'.
CommentedLineMarkup := '%'.
EnvironmentClosingBlockMarkup := '!>'.
Expand Down
5 changes: 4 additions & 1 deletion src/Microdown/MicMicrodownTextualBuilder.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Loading