-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #451 from estebanlm/fixes-to-act-as-markdown
add hooks for extensibility and add "Microdown-Macrodown"
- Loading branch information
Showing
33 changed files
with
713 additions
and
123 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
src/Microdown-Macrodown-Pillar/MacLineBreakBlock.extension.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
Extension { #name : #MacLineBreakBlock } | ||
|
||
{ #category : #'*Microdown-Macrodown-Pillar' } | ||
MacLineBreakBlock >> associatedPillarClass [ | ||
|
||
^ PRLineBreak | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Package { #name : #'Microdown-Macrodown-Pillar' } |
35 changes: 35 additions & 0 deletions
35
src/Microdown-Macrodown-Tests/MacInlineParserTest.class.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
27
src/Microdown-Macrodown-Tests/MacParagraphBlockTest.class.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Package { #name : #'Microdown-Macrodown-Tests' } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 := ' ' | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
19
src/Microdown-Macrodown/MacMailtoResourceReference.class.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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?' | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
] |
Oops, something went wrong.