Skip to content

Commit

Permalink
Merge pull request #451 from estebanlm/fixes-to-act-as-markdown
Browse files Browse the repository at this point in the history
add hooks for extensibility and add "Microdown-Macrodown"
  • Loading branch information
Ducasse authored Jun 1, 2022
2 parents 76425b3 + 5dfbe1c commit 5d32bbb
Show file tree
Hide file tree
Showing 33 changed files with 713 additions and 123 deletions.
51 changes: 36 additions & 15 deletions src/BaselineOfMicrodown/BaselineOfMicrodown.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,8 @@ BaselineOfMicrodown >> baseline: spec [

<baseline>
spec for: #common do: [
spec
baseline: 'PillarCore'
with: [
spec
loads: #('Pillar-Core');
repository: 'github://pillar-markup/pillar:dev-8' ].

spec
baseline: 'XMLParserHTML'
with: [
spec
loads: #('Core');
repository: 'github://pharo-contributions/XML-XMLParserHTML/src' ].
self pillar: spec.
self xmlParserHtml: spec.

spec
package: #Microdown;
Expand Down Expand Up @@ -91,7 +80,16 @@ BaselineOfMicrodown >> baseline: spec [
with: [ spec requires: #( #'Microdown-Pillar' ) ];

package: #'Microdown-PrettyPrinter-Tests'
with: [ spec requires: #( #'Microdown-PrettyPrinter' #'Microdown-Tests') ].
with: [ spec requires: #( #'Microdown-PrettyPrinter' #'Microdown-Tests') ];

package: 'Microdown-Macrodown'
with: [ spec requires: #( 'Microdown') ];
package: #'Microdown-Macrodown-Pillar'
with: [ spec requires: #( 'Microdown-Macrodown' 'PillarCore') ];
package: 'Microdown-Macrodown-Tests'
with: [ spec requires: #( 'Microdown-Macrodown' 'Microdown-Tests') ].



"I do not want group without tests for now"
spec
Expand All @@ -113,5 +111,28 @@ BaselineOfMicrodown >> baseline: spec [
#'Microdown-LaTeXExporter-Tests'
#'Microdown-Transformer'
#'Microdown-Transformer-Tests');
group: 'All' with: #('Core' 'Tests' 'Extensions' #'Microdown-Pharo-Tools' 'RichText') ]
group: 'Macrodown' with: #('Microdown-Macrodown' 'Microdown-Macrodown-Tests');
group: 'All' with: #('Core' 'Tests' 'Extensions' 'Macrodown' 'Microdown-Pharo-Tools' 'RichText') ]
]

{ #category : #'external projects' }
BaselineOfMicrodown >> pillar: spec [

spec
baseline: 'PillarCore'
with: [
spec
loads: #('Pillar-Core');
repository: 'github://pillar-markup/pillar:dev-8' ]
]

{ #category : #'external projects' }
BaselineOfMicrodown >> xmlParserHtml: spec [

spec
baseline: 'XMLParserHTML'
with: [
spec
loads: #('Core');
repository: 'github://pharo-contributions/XML-XMLParserHTML/src' ]
]
7 changes: 7 additions & 0 deletions src/Microdown-Macrodown-Pillar/MacLineBreakBlock.extension.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Extension { #name : #MacLineBreakBlock }

{ #category : #'*Microdown-Macrodown-Pillar' }
MacLineBreakBlock >> associatedPillarClass [

^ PRLineBreak
]
1 change: 1 addition & 0 deletions src/Microdown-Macrodown-Pillar/package.st
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Package { #name : #'Microdown-Macrodown-Pillar' }
35 changes: 35 additions & 0 deletions src/Microdown-Macrodown-Tests/MacInlineParserTest.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
Class {
#name : #MacInlineParserTest,
#superclass : #MicInlineParserTest,
#category : #'Microdown-Macrodown-Tests'
}

{ #category : #accessing }
MacInlineParserTest >> splitter [

^ MacInlineParser new
]

{ #category : #tests }
MacInlineParserTest >> testParseLineBreak [
| blocks |

blocks := self splitter parse: 'x1
x2
'.

self assert: blocks size equals: 3.
self assert: blocks second class equals: MacLineBreakBlock
]

{ #category : #tests }
MacInlineParserTest >> testParseLineBreakManySpaces [
| blocks |

blocks := self splitter parse: 'a
b
'.

self assert: blocks size equals: 3.
self assert: blocks second class equals: MacLineBreakBlock
]
27 changes: 27 additions & 0 deletions src/Microdown-Macrodown-Tests/MacParagraphBlockTest.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
Class {
#name : #MacParagraphBlockTest,
#superclass : #MicParagraphBlockTest,
#category : #'Microdown-Macrodown-Tests'
}

{ #category : #accessing }
MacParagraphBlockTest >> parserClass [

^ MacrodownParser
]

{ #category : #tests }
MacParagraphBlockTest >> testTwoSingleLinesWithSpaces [
| root paragraph |

root := parser parse: 'This is
a paragraph on two lines, separated by two spaces'.
self assert: root children size equals: 1.
paragraph := root children first.

self assert: paragraph children first text equals: 'This is'.
self assert: paragraph children second class equals: MacLineBreakBlock.
self assert: paragraph children third text equals: 'a paragraph on two lines, separated by two spaces'.
self assert: paragraph text equals: 'This is
a paragraph on two lines, separated by two spaces'
]
1 change: 1 addition & 0 deletions src/Microdown-Macrodown-Tests/package.st
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Package { #name : #'Microdown-Macrodown-Tests' }
17 changes: 17 additions & 0 deletions src/Microdown-Macrodown/MacConstants.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
"
Constants to be used on the extended parser.
"
Class {
#name : #MacConstants,
#superclass : #SharedPool,
#classVars : [
'InlineParagraphDelimiter'
],
#category : #'Microdown-Macrodown'
}

{ #category : #initialization }
MacConstants class >> initialize [

InlineParagraphDelimiter := ' '
]
54 changes: 54 additions & 0 deletions src/Microdown-Macrodown/MacInlineParser.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
"
Inline parser to detect and parse extended parse functionality.
- line break with two (or more) spaces.
"
Class {
#name : #MacInlineParser,
#superclass : #MicInlineParser,
#pools : [
'MacConstants'
],
#category : #'Microdown-Macrodown'
}

{ #category : #adding }
MacInlineParser >> addLineBreakInlineBlock: indexOfAssociateOpener [
| startIndex endIndex |

startIndex := opener index + opener size.
endIndex := string indexOf: Character cr startingAt: startIndex.
(endIndex = 0
or: [ (endIndex - startIndex) = 0 ])
ifTrue: [ ^ self ].

self
addInlineBlock: indexOfAssociateOpener
from: startIndex
to: endIndex
]

{ #category : #private }
MacInlineParser >> extentedDelimiters [

^ { MacLineBreakDelimiter }
]

{ #category : #actions }
MacInlineParser >> identifyMarkupFor: aString [

^ self extentedDelimiters
detect: [ :each | each matches: aString ]
ifFound: [ :aDelimiterClass |
delimiterClass := aDelimiterClass.
aDelimiterClass applyOn: self ]
ifNone: [ super identifyMarkupFor: aString ]
]

{ #category : #applying }
MacInlineParser >> processLineBreak [

self delimiterFoundProcess.
self addInlineBlock: (self findType: delimiterClass type).
^ result last text size
]
32 changes: 32 additions & 0 deletions src/Microdown-Macrodown/MacLineBreakBlock.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
"
Block to process line breaks.
"
Class {
#name : #MacLineBreakBlock,
#superclass : #MicInlineElement,
#category : #'Microdown-Macrodown'
}

{ #category : #visiting }
MacLineBreakBlock >> accept: aVisitor [

^ aVisitor visitLineBreak: self
]

{ #category : #accessing }
MacLineBreakBlock >> kind [

^ #lineBreak
]

{ #category : #accessing }
MacLineBreakBlock >> openingDelimiter [

^ nil
]

{ #category : #accessing }
MacLineBreakBlock >> openingDelimiterSize [

^ 0
]
75 changes: 75 additions & 0 deletions src/Microdown-Macrodown/MacLineBreakDelimiter.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
"
Delimiter definition for line break.
"
Class {
#name : #MacLineBreakDelimiter,
#superclass : #MicAbstractDelimiter,
#category : #'Microdown-Macrodown'
}

{ #category : #applying }
MacLineBreakDelimiter class >> applyOn: inlineParser [

^ inlineParser processLineBreak
]

{ #category : #accessing }
MacLineBreakDelimiter class >> associatedInlineBlock [

^ MacLineBreakBlock
]

{ #category : #accessing }
MacLineBreakDelimiter class >> isCloser [

^ true
]

{ #category : #accessing }
MacLineBreakDelimiter class >> isOpener [

^ true
]

{ #category : #accessing }
MacLineBreakDelimiter class >> markup [

^ #lineBreak
]

{ #category : #testing }
MacLineBreakDelimiter class >> matches: aString [
| indexOfCr |

(aString size >= 3) ifFalse: [ ^ false ].

indexOfCr := (aString indexOf: Character cr) - 1.
indexOfCr < 2 ifTrue: [ ^ false ].

^ (aString first: indexOfCr) allSatisfy: [ :each | each = Character space ]
]

{ #category : #accessing }
MacLineBreakDelimiter class >> size [

^ 1
]

{ #category : #accessing }
MacLineBreakDelimiter class >> type [

^ #lineBreak
]

{ #category : #adding }
MacLineBreakDelimiter >> addInlineBlock: anIndex to: inlineParser [

inlineParser addLineBreakInlineBlock: anIndex

]

{ #category : #accessing }
MacLineBreakDelimiter >> endIndex [

^ self index + self size
]
19 changes: 19 additions & 0 deletions src/Microdown-Macrodown/MacMailtoResourceReference.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
"
Definition of ""mailto"" scheme (to let the links recognise it).
"
Class {
#name : #MacMailtoResourceReference,
#superclass : #MicAbsoluteResourceReference,
#category : #'Microdown-Macrodown'
}

{ #category : #'instance creation' }
MacMailtoResourceReference class >> handlesUriScheme: scheme [
^ scheme beginsWith: 'mailto'
]

{ #category : #accessing }
MacMailtoResourceReference >> contents [

^ self error: 'Should not arrive here?'
]
34 changes: 34 additions & 0 deletions src/Microdown-Macrodown/MacParagraphBlock.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
"
Paragraph extension to process the extended inlines.
"
Class {
#name : #MacParagraphBlock,
#superclass : #MicParagraphBlock,
#instVars : [
'textWithoutBreak'
],
#pools : [
'MacConstants'
],
#category : #'Microdown-Macrodown'
}

{ #category : #parising }
MacParagraphBlock >> addLineAndReturnNextNode: line [

super addLineAndReturnNextNode: line.
textWithoutBreak := self appendLine: line to: textWithoutBreak.

(line endsWith: InlineParagraphDelimiter) ifFalse: [ ^ self ].
"add nodes up to now, then insert break and continue"
children addAll: (self inlineParse: textWithoutBreak).
children add: (MacLineBreakBlock new).
textWithoutBreak := nil
]

{ #category : #visiting }
MacParagraphBlock >> closeMe [

self children: self children, (self inlineParse: textWithoutBreak).
textWithoutBreak := nil
]
Loading

0 comments on commit 5d32bbb

Please sign in to comment.