Skip to content

Commit

Permalink
Merge pull request #889 from pillar-markup/IntroduceRawParagraph
Browse files Browse the repository at this point in the history
Introduce raw paragraph
  • Loading branch information
Ducasse authored Sep 30, 2024
2 parents c4534dc + 3040a84 commit 6d4364a
Show file tree
Hide file tree
Showing 30 changed files with 215 additions and 59 deletions.
14 changes: 2 additions & 12 deletions src/Microdown-BrowserExtensions/Class.extension.st
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,8 @@ Class >> addDocumentSectionTo: aBuilder label: label methods: methods [
{ #category : '*Microdown-BrowserExtensions' }
Class >> buildMicroDownUsing: aBuilder withComment: aString [

aBuilder
header: [ aBuilder text: 'Class: '.
aBuilder text: self name ] withLevel: 1;
horizontalLine;
text: aString.

self addDocumentSectionExampleCodeTo: aBuilder.

self
addDocumentSectionTo: aBuilder
label: 'Examples'
methods: (self class methods select: [ :each | each protocol = self documentExamplesProtocol ])
aString.

]

{ #category : '*Microdown-BrowserExtensions' }
Expand Down
2 changes: 1 addition & 1 deletion src/Microdown-Tests/MicElementTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Class {
'parser'
],
#pools : [
'MicMicrodownSharedPool'
'MicSharedPool'
],
#category : 'Microdown-Tests-Parser',
#package : 'Microdown-Tests',
Expand Down
2 changes: 1 addition & 1 deletion src/Microdown-Tests/MicInlineBlockTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Class {
#name : 'MicInlineBlockTest',
#superclass : 'TestCase',
#pools : [
'MicMicrodownSharedPool'
'MicSharedPool'
],
#category : 'Microdown-Tests-InlineParser',
#package : 'Microdown-Tests',
Expand Down
2 changes: 1 addition & 1 deletion src/Microdown-Tests/MicInlineParserTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Class {
#name : 'MicInlineParserTest',
#superclass : 'TestCase',
#pools : [
'MicMicrodownSharedPool'
'MicSharedPool'
],
#category : 'Microdown-Tests-InlineParser',
#package : 'Microdown-Tests',
Expand Down
2 changes: 1 addition & 1 deletion src/Microdown-Tests/MicInlineTokenStreamTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Class {
#name : 'MicInlineTokenStreamTest',
#superclass : 'TestCase',
#pools : [
'MicMicrodownSharedPool'
'MicSharedPool'
],
#category : 'Microdown-Tests-InlineParser',
#package : 'Microdown-Tests',
Expand Down
2 changes: 1 addition & 1 deletion src/Microdown-Tests/MicMicrodownSnippetFactory.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Class {
'parserClass'
],
#pools : [
'MicMicrodownSharedPool'
'MicSharedPool'
],
#category : 'Microdown-Tests-Snippets',
#package : 'Microdown-Tests',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Class {
'builder'
],
#pools : [
'MicMicrodownSharedPool'
'MicSharedPool'
],
#category : 'Microdown-Tests-Builder',
#package : 'Microdown-Tests',
Expand Down
2 changes: 1 addition & 1 deletion src/Microdown-Tests/MicParserTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Class {
'parser'
],
#pools : [
'MicMicrodownSharedPool'
'MicSharedPool'
],
#category : 'Microdown-Tests-Parser',
#package : 'Microdown-Tests',
Expand Down
11 changes: 11 additions & 0 deletions src/Microdown-Tests/MicRawBlockTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,17 @@ MicRawBlockTest >> subjectClass [
^ MicRawBlock
]

{ #category : 'tests' }
MicRawBlockTest >> testASimpleRawParagaaph [
| mic |
mic := (parser parse: '<title>
No idea what it is :)
</title>') children first.
self assert: mic class equals: MicRawParagraphBlock.
self assert: mic label equals: 'title'.

]

{ #category : 'tests' }
MicRawBlockTest >> testRaw [

Expand Down
74 changes: 74 additions & 0 deletions src/Microdown-Tests/MicRawParagraphBlockTest.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
Class {
#name : 'MicRawParagraphBlockTest',
#superclass : 'MicBlockTest',
#category : 'Microdown-Tests',
#package : 'Microdown-Tests'
}

{ #category : 'tests' }
MicRawParagraphBlockTest >> subjectClass [
^ MicRawParagraphBlock
]

{ #category : 'tests' }
MicRawParagraphBlockTest >> testASimpleRawParagraph [
| mic |
mic := (parser parse: '<title>
No idea what it is :)
</title>') children first.
self assert: mic class equals: MicRawParagraphBlock.
self assert: mic label equals: 'title'.

]

{ #category : 'tests' }
MicRawParagraphBlockTest >> testNotASimpleRawParagraph [
| mic |
mic := (parser parse: '<toto>
No idea what it is :)
</toto>') children first.
self assert: mic class equals: MicParagraphBlock.

]

{ #category : 'tests' }
MicRawParagraphBlockTest >> testNotASimpleRawParagraphNoSpaceInFrontToClose [
| children |
children := (parser parse: '<title>
No idea what it is :)
</title>
And after we get a paragraph') children.
self assert: children size equals: 1.
"so far we eat as much as we can and put everything in the raw"


self assert: children first class equals: MicRawParagraphBlock.

]

{ #category : 'tests' }
MicRawParagraphBlockTest >> testRawParagraphCannotBeNested [
| children |
children := (parser parse: '<title>
No idea what it is :)
<button>
hkhkjhkj
</button>
</title>') children.
self assert: children size equals: 1.
self assert: children first class equals: MicRawParagraphBlock.
self assert: children first label equals: 'title'.

]

{ #category : 'tests' }
MicRawParagraphBlockTest >> testThereIsNoValidationIfThetagStartWithAKnowHtml [
| mic |
mic := (parser parse: '<titleunkniw>
No idea what it is :)
</titleunkniw>') children first.
self assert: mic class equals: MicRawParagraphBlock.

]
2 changes: 1 addition & 1 deletion src/Microdown-Tests/MicScriptBlockExtensionTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Class {
#name : 'MicScriptBlockExtensionTest',
#superclass : 'TestCase',
#pools : [
'MicMicrodownSharedPool'
'MicSharedPool'
],
#category : 'Microdown-Tests-Extensions',
#package : 'Microdown-Tests',
Expand Down
2 changes: 1 addition & 1 deletion src/Microdown-Tests/MicrodownParserTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Class {
'parser'
],
#pools : [
'MicMicrodownSharedPool'
'MicSharedPool'
],
#category : 'Microdown-Tests-Parser',
#package : 'Microdown-Tests',
Expand Down
10 changes: 8 additions & 2 deletions src/Microdown/MicAbstractBlock.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ Class {
{ #category : 'public' }
MicAbstractBlock class >> alternateBlockClassFor: line [
"This hook supports extensions of environments.
we get <?slide ... and we do not create an environment but a slideBlock"
we get <!slide ... and we do not create an environment but a slideBlock"

^ self
]

Expand Down Expand Up @@ -53,7 +54,12 @@ MicAbstractBlock >> blockExtensionStarterClassFrom: line [

{ #category : 'public' }
MicAbstractBlock >> blockStarterClassFrom: line [
"return the class of a block which can start with line, or nil if none"
"Return the class of a block which can start with line, or nil if none.
The principle is the following
- first we get a class
- then such class as environment are asked since they can act as factory
and return other classes.
For example <!citation does not return an environment but a MicCitationBlock"

^ (self parser blockStarterClassFrom: line) ifNotNil: [ :c | c alternateBlockClassFor: line ]
]
Expand Down
2 changes: 1 addition & 1 deletion src/Microdown/MicAbstractMicrodownTextualBuilder.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Class {
'newLineCharacterString'
],
#pools : [
'MicMicrodownSharedPool'
'MicSharedPool'
],
#category : 'Microdown-Parser',
#package : 'Microdown',
Expand Down
2 changes: 1 addition & 1 deletion src/Microdown/MicElement.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Class {
'properties'
],
#pools : [
'MicMicrodownSharedPool'
'MicSharedPool'
],
#category : 'Microdown-Model',
#package : 'Microdown',
Expand Down
4 changes: 2 additions & 2 deletions src/Microdown/MicEnvironmentBlock.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ MicEnvironmentBlock class >> addDocumentDefinedEnvironments: aBuilder [
{ #category : 'public' }
MicEnvironmentBlock class >> alternateBlockClassFor: line [

"If there is one subclass with the corresponding tag, returns it, else resturn the current class."
"If there is one subclass with the corresponding tag, returns it, else return the current class."
"line is of the form <!slide|title=Schedule"
"We know that the two first characters are <? else we would be invoked"
"We know that the two first characters are <! else we would not be invoked"
| tag |
tag := ((line allButFirst: EnvironmentOpeningBlockMarkup size)
Expand Down
2 changes: 1 addition & 1 deletion src/Microdown/MicInlineAlternativesDelimiter.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Class {
#name : 'MicInlineAlternativesDelimiter',
#superclass : 'MicInlineStandardDelimiter',
#pools : [
'MicMicrodownSharedPool'
'MicSharedPool'
],
#category : 'Microdown-InlineParser',
#package : 'Microdown',
Expand Down
2 changes: 1 addition & 1 deletion src/Microdown/MicInlineDelimiter.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Class {
'Regex'
],
#pools : [
'MicMicrodownSharedPool'
'MicSharedPool'
],
#category : 'Microdown-InlineParser',
#package : 'Microdown',
Expand Down
2 changes: 1 addition & 1 deletion src/Microdown/MicInlineHttpDelimiter.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Class {
#name : 'MicInlineHttpDelimiter',
#superclass : 'MicInlineDelimiter',
#pools : [
'MicMicrodownSharedPool'
'MicSharedPool'
],
#category : 'Microdown-InlineParser',
#package : 'Microdown',
Expand Down
2 changes: 1 addition & 1 deletion src/Microdown/MicInlineParser.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Class {
#name : 'MicInlineParser',
#superclass : 'Object',
#pools : [
'MicMicrodownSharedPool'
'MicSharedPool'
],
#category : 'Microdown-InlineParser',
#package : 'Microdown',
Expand Down
2 changes: 1 addition & 1 deletion src/Microdown/MicInlineStandardDelimiter.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Class {
'blockClass'
],
#pools : [
'MicMicrodownSharedPool'
'MicSharedPool'
],
#category : 'Microdown-InlineParser',
#package : 'Microdown',
Expand Down
2 changes: 1 addition & 1 deletion src/Microdown/MicInlineToken.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Class {
'string'
],
#pools : [
'MicMicrodownSharedPool'
'MicSharedPool'
],
#category : 'Microdown-InlineParser',
#package : 'Microdown',
Expand Down
2 changes: 1 addition & 1 deletion src/Microdown/MicInlineTokenStream.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Class {
'tokens'
],
#pools : [
'MicMicrodownSharedPool'
'MicSharedPool'
],
#category : 'Microdown-InlineParser',
#package : 'Microdown',
Expand Down
12 changes: 12 additions & 0 deletions src/Microdown/MicMailtoResourceReference.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Class {
#name : 'MicMailtoResourceReference',
#superclass : 'MicAbsoluteResourceReference',
#category : 'Microdown-Core',
#package : 'Microdown',
#tag : 'Core'
}

{ #category : 'instance creation' }
MicMailtoResourceReference class >> handlesUriScheme: scheme [
^ scheme beginsWith: 'mailto'
]
4 changes: 2 additions & 2 deletions src/Microdown/MicMetaDataBlock.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ Class {
#instVars : [
'bogusParsing'
],
#category : 'Microdown-BookRelated',
#category : 'Microdown-Extensions',
#package : 'Microdown',
#tag : 'BookRelated'
#tag : 'Extensions'
}

{ #category : 'markups' }
Expand Down
37 changes: 37 additions & 0 deletions src/Microdown/MicRawParagraphBlock.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
Class {
#name : 'MicRawParagraphBlock',
#superclass : 'MicStartStopMarkupBlock',
#instVars : [
'label'
],
#category : 'Microdown-Extensions',
#package : 'Microdown',
#tag : 'Extensions'
}

{ #category : 'handle' }
MicRawParagraphBlock >> bodyFromLine: line [

(self doesLineStartWithStopMarkup: line)
ifTrue: [ isClosed := true ]
ifFalse: [ body := body ifNil: [ line ] ifNotNil: [ body , String cr , line ] ]
]

{ #category : 'handle' }
MicRawParagraphBlock >> extractFirstLineFrom: line [
"we cannot know in advance the markup so we have to guess and store it for closing."

label := line allButFirst copyUpToSubstring: '>'

]

{ #category : 'accessing' }
MicRawParagraphBlock >> label [
^ label
]

{ #category : 'markups' }
MicRawParagraphBlock >> lineStopMarkup [

^ '</', label, '>'
]
Loading

0 comments on commit 6d4364a

Please sign in to comment.