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
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
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 : 'as yet unclassified' }
Copy link
Contributor

Choose a reason for hiding this comment

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

could categorize the method.

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
Loading