diff --git a/.github/workflows/tests-all.yml b/.github/workflows/tests-all.yml index a4f3a718..6aa0c34f 100644 --- a/.github/workflows/tests-all.yml +++ b/.github/workflows/tests-all.yml @@ -24,6 +24,8 @@ jobs: name: ${{ matrix.smalltalk }} on ${{ matrix.os }} steps: - uses: actions/checkout@v3 + with: + fetch-depth: '0' - name: Setup smalltalkCI uses: hpi-swa/setup-smalltalkCI@v1 with: diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index a14b2a3a..0f45df0b 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -22,6 +22,8 @@ jobs: runs-on: ${{ matrix.platform }} steps: - uses: actions/checkout@v3 + with: + fetch-depth: '0' - uses: hpi-swa/setup-smalltalkCI@v1 id: smalltalkci with: diff --git a/README.md b/README.md index e1c1764f..43349aa6 100644 --- a/README.md +++ b/README.md @@ -197,6 +197,10 @@ The following script loads all groups in the Baseline: unload; forget ] ]. +Smalltalk globals + at: #BaselineOfMicrodown + ifPresent: [ :c | c removeFromSystem ]. + Metacello new baseline: 'Microdown'; repository: 'github://pillar-markup/Microdown:dev/src'; diff --git a/src/BaselineOfMicrodown/BaselineOfMicrodown.class.st b/src/BaselineOfMicrodown/BaselineOfMicrodown.class.st index 7270c151..3657a7cc 100644 --- a/src/BaselineOfMicrodown/BaselineOfMicrodown.class.st +++ b/src/BaselineOfMicrodown/BaselineOfMicrodown.class.st @@ -15,8 +15,10 @@ BaselineOfMicrodown >> baseline: spec [ spec for: #common do: [ - self xmlParserHtml: spec. - self mustache: spec. + self + xmlParserHtml: spec; + mustache: spec; + gitBridge: spec. " I disable this because against all my best effort, I cannot avoid the fucking pop up to raise even if I unload all the packages. I get the Microdown-RichTextComposer in conflict." @@ -29,7 +31,7 @@ BaselineOfMicrodown >> baseline: spec [ spec postLoadDoIt: #'postload:package:'. spec - package: #Microdown; + package: #Microdown with: [ spec requires: #( #GitBridge ) ]; package: #'Microdown-Tests' with: [ spec requires: #( #Microdown ) ]; @@ -118,6 +120,12 @@ BaselineOfMicrodown >> baseline: spec [ group: 'All' with: #('Core' #'Microdown-BrowserExtensions' 'Tests' 'Extensions' 'Microdown-Pharo-Tools' 'RichText') ] ] +{ #category : 'baselines' } +BaselineOfMicrodown >> gitBridge: spec [ + + spec baseline: 'GitBridge' with: [ spec repository: 'github://jecisc/GitBridge:v1.x.x/src' ] +] + { #category : 'baselines' } BaselineOfMicrodown >> mustache: spec [ diff --git a/src/Microdown-HTMLExporter-Tests/MicHTMLExporterTest.class.st b/src/Microdown-HTMLExporter-Tests/MicHTMLExporterTest.class.st index 0ded3902..ad9cf2d4 100644 --- a/src/Microdown-HTMLExporter-Tests/MicHTMLExporterTest.class.st +++ b/src/Microdown-HTMLExporter-Tests/MicHTMLExporterTest.class.st @@ -25,6 +25,8 @@ MicHTMLExporterTest class >> testParameters [ { #category : 'accessing' } MicHTMLExporterTest >> factory: aFactory [ + self flag: #todo. + "This is horrible either factory: should be renamed factoryClass or we should remove the new." factory := aFactory new ] @@ -200,6 +202,19 @@ MicHTMLExporterTest >> testHeaderLevel2 [ andCheckWeGet: newLine , '

Foo

' ] +{ #category : 'tests - metadata' } +MicHTMLExporterTest >> testMetaDataIsIgnored [ + + self parse: factory metaDataSample andCheckWeGet: '' +] + +{ #category : 'tests - metadata' } +MicHTMLExporterTest >> testMetaDataIsNotIgnored [ + + writer doNotIgnoreMetaData. + self parse: factory metaDataSample andCheckWeGet: '' +] + { #category : 'tests - paragraph' } MicHTMLExporterTest >> testParagraph [ diff --git a/src/Microdown-HTMLExporter-Tests/MicHTMLVisitorTest.class.st b/src/Microdown-HTMLExporter-Tests/MicHTMLVisitorTest.class.st index 668f4ec0..197c869d 100644 --- a/src/Microdown-HTMLExporter-Tests/MicHTMLVisitorTest.class.st +++ b/src/Microdown-HTMLExporter-Tests/MicHTMLVisitorTest.class.st @@ -74,7 +74,7 @@ MicHTMLVisitorTest >> testCanvasClass [ self assert: writer canvasClass equals: MicHTMLCanvas ] -{ #category : 'test' } +{ #category : 'tests' } MicHTMLVisitorTest >> testConfiguration [ self assert: (writer configuration isKindOf: MicHTMLConfiguration). diff --git a/src/Microdown-HTMLExporter/MicHTMLVisitor.class.st b/src/Microdown-HTMLExporter/MicHTMLVisitor.class.st index 096c8a58..2270094f 100644 --- a/src/Microdown-HTMLExporter/MicHTMLVisitor.class.st +++ b/src/Microdown-HTMLExporter/MicHTMLVisitor.class.st @@ -7,7 +7,8 @@ Class { #superclass : 'MicrodownVisitor', #instVars : [ 'canvas', - 'configuration' + 'configuration', + 'ignoresMetaData' ], #category : 'Microdown-HTMLExporter-Visitor', #package : 'Microdown-HTMLExporter', @@ -158,13 +159,25 @@ MicHTMLVisitor >> crlfAsNewLine [ canvas crlfAsNewLine ] +{ #category : 'as yet unclassified' } +MicHTMLVisitor >> doNotIgnoreMetaData [ + ignoresMetaData := false +] + +{ #category : 'accessing' } +MicHTMLVisitor >> ignoreMetaData [ + ignoresMetaData := true +] + { #category : 'initialization' } -MicHTMLVisitor >> initialize [ +MicHTMLVisitor >> initialize [ + | stream | super initialize. - stream := MicOutputStream new setStream: (WriteStream on: String empty). + stream := MicOutputStream new setStream: + (WriteStream on: String empty). canvas := self canvasClass on: stream. - + ignoresMetaData := true. ] { #category : 'initialization' } @@ -188,6 +201,14 @@ MicHTMLVisitor >> minQuoteThreshold [ ^ 50 ] +{ #category : 'initialization' } +MicHTMLVisitor >> stream: aStream [ + + | stream | + stream := MicOutputStream new setStream: aStream. + canvas := self canvasClass on: stream +] + { #category : 'initialization' } MicHTMLVisitor >> usedNewLine [ "Return the encoded new line. Useful for tests." @@ -396,8 +417,9 @@ MicHTMLVisitor >> visitMath: anObject [ { #category : 'visiting' } MicHTMLVisitor >> visitMetaData: aMetaData [ + ignoresMetaData ifTrue: [ self metaDataFromAssociations: aMetaData body. - super visitMetaData: aMetaData. + super visitMetaData: aMetaData ] ] { #category : 'visiting - inline elements' } diff --git a/src/Microdown-LaTeXExporter-Tests/MicAbstractLaTexWriterTest.class.st b/src/Microdown-LaTeXExporter-Tests/MicAbstractLaTexWriterTest.class.st index f5aafd3d..877d8809 100644 --- a/src/Microdown-LaTeXExporter-Tests/MicAbstractLaTexWriterTest.class.st +++ b/src/Microdown-LaTeXExporter-Tests/MicAbstractLaTexWriterTest.class.st @@ -124,7 +124,7 @@ MicAbstractLaTexWriterTest >> testAnnotatedParagraph [ self writeFor: factory annotatedSample. self assert: writer contents equals: newLine , '\begin{note}', newLine , - 'label Foo \textit{bar}', newLine , + 'Foo \textit{bar}', newLine , '\end{note}' ] diff --git a/src/Microdown-Pillar/MicMicrodownObjectToPillarObjectConverter.class.st b/src/Microdown-Pillar/MicMicrodownObjectToPillarObjectConverter.class.st index d4c530ce..4e40de00 100644 --- a/src/Microdown-Pillar/MicMicrodownObjectToPillarObjectConverter.class.st +++ b/src/Microdown-Pillar/MicMicrodownObjectToPillarObjectConverter.class.st @@ -13,9 +13,7 @@ Class { { #category : 'formatting' } MicMicrodownObjectToPillarObjectConverter >> formatBlock: aMicFormatBlock [ | childrenAsPillar | - childrenAsPillar := aMicFormatBlock isOnlyChild - ifTrue: [ {(PRText new text: aMicFormatBlock substring )} ] - ifFalse: [ aMicFormatBlock children collect: [:e | e accept: self ] ]. + childrenAsPillar := aMicFormatBlock children collect: [:e | e accept: self ]. ^ aMicFormatBlock associatedPillarClass new setChildren: childrenAsPillar; yourself @@ -127,9 +125,9 @@ MicMicrodownObjectToPillarObjectConverter >> visitEnvironment: aMicEnvironmentBl MicMicrodownObjectToPillarObjectConverter >> visitFigure: aMicFigureBlock [ | aPRFigure | - aPRFigure := self urlBlock: aMicFigureBlock. + aPRFigure := aMicFigureBlock associatedPillarClass new. ^ aPRFigure - label: aMicFigureBlock substring; + label: aMicFigureBlock altText; parameters: aMicFigureBlock arguments; yourself ] @@ -169,8 +167,7 @@ MicMicrodownObjectToPillarObjectConverter >> visitLink: aMicLink [ ^ aMicLink associatedPillarClass new setChildren: - ((aMicLink inlineParse: aMicLink substring) collect: [ :n | - n accept: self ]); + (aMicLink children collect: [ :n | n accept: self ]); reference: aMicLink url asString; yourself ] @@ -276,8 +273,10 @@ MicMicrodownObjectToPillarObjectConverter >> visitTable: aTable [ { #category : 'visiting inline' } MicMicrodownObjectToPillarObjectConverter >> visitText: aMicTextBlock [ - - ^ PRText new text: aMicTextBlock substring ; yourself + + ^ PRText new + text: aMicTextBlock bodyString; + yourself ] { #category : 'visiting' } diff --git a/src/Microdown-PrettyPrinter-Tests/MicTextualMicrodownExporterTest.class.st b/src/Microdown-PrettyPrinter-Tests/MicTextualMicrodownExporterTest.class.st index 096c2c2a..0a0d1875 100644 --- a/src/Microdown-PrettyPrinter-Tests/MicTextualMicrodownExporterTest.class.st +++ b/src/Microdown-PrettyPrinter-Tests/MicTextualMicrodownExporterTest.class.st @@ -72,7 +72,7 @@ MicTextualMicrodownExporterTest >> testAnnotated [ | mic | mic := parser parse: factory annotatedSample. self assert: (mic accept: visitor) contents equals: '>[!note] -> label Foo _bar_ +> Foo _bar_ ' ] diff --git a/src/Microdown-RichTextComposer/Form.extension.st b/src/Microdown-RichTextComposer/Form.extension.st deleted file mode 100644 index d7fbbdbb..00000000 --- a/src/Microdown-RichTextComposer/Form.extension.st +++ /dev/null @@ -1,7 +0,0 @@ -Extension { #name : 'Form' } - -{ #category : '*Microdown-RichTextComposer' } -Form >> asText [ - "I return a text with myself embedded - Similar to Morph>>asText" - ^ (String value: 1) asText addAttribute: (TextAnchor new anchoredMorph: self) -] diff --git a/src/Microdown-RichTextComposer/MicDocumentHierarchyBuilder.class.st b/src/Microdown-RichTextComposer/MicDocumentHierarchyBuilder.class.st index 47c613c8..75839829 100644 --- a/src/Microdown-RichTextComposer/MicDocumentHierarchyBuilder.class.st +++ b/src/Microdown-RichTextComposer/MicDocumentHierarchyBuilder.class.st @@ -33,12 +33,10 @@ Class { { #category : 'private' } MicDocumentHierarchyBuilder >> addLevel: level from: aClass [ "'├ ─ ╰ │'" + | path | - path := (aClass allSuperclasses copyUpTo: self topClass) reversed. - builder monospace: ' '. - path do: [ :each | builder monospace: ((self isPassingThrough: aClass topLevel: each) ifTrue: [ '│ ' ] @@ -65,10 +63,9 @@ MicDocumentHierarchyBuilder >> addLevel: level from: aClass [ { #category : 'private' } MicDocumentHierarchyBuilder >> addLevel: level from: aClass to: stream [ "'├ ─ ╰ │'" + | path | - path := (aClass allSuperclasses copyUpTo: self topClass) reversed. - path do: [ :each | stream << ((self isPassingThrough: aClass topLevel: each) ifTrue: [ '│ ' ] @@ -145,8 +142,8 @@ MicDocumentHierarchyBuilder >> fillTreeWithSubclassesOf: aClass [ { #category : 'private' } MicDocumentHierarchyBuilder >> fillTreeWithSuperclassesOf: aClass [ - | superclasses | + | superclasses | superclasses := (aClass allSuperclasses copyUpTo: self topClass) reversed. superclasses do: [ :each | flattenTree @@ -166,7 +163,7 @@ MicDocumentHierarchyBuilder >> filter: aBlock [ { #category : 'accessing' } MicDocumentHierarchyBuilder >> fromClass [ - ^ fromClass ifNil: [ SpAbstractPresenter ] + ^ fromClass ifNil: [ SpAbstractPresenter ] ] { #category : 'accessing' } @@ -177,8 +174,8 @@ MicDocumentHierarchyBuilder >> fromClass: aClass [ { #category : 'testing' } MicDocumentHierarchyBuilder >> isPassingThrough: aClass topLevel: aTopClass [ - | superclasses | - + + | superclasses | superclasses := flattenTree at: aTopClass superclass ifAbsent: [ #() ]. superclasses size <= 1 ifFalse: [ ^ (superclasses indexOf: aTopClass) < superclasses size ]. diff --git a/src/Microdown-RichTextComposer/MicDynamicTextStyler.class.st b/src/Microdown-RichTextComposer/MicDynamicTextStyler.class.st index 1c0b7682..c5c2a7e1 100644 --- a/src/Microdown-RichTextComposer/MicDynamicTextStyler.class.st +++ b/src/Microdown-RichTextComposer/MicDynamicTextStyler.class.st @@ -81,6 +81,7 @@ MicDynamicTextStyler >> bodyFont: fontSpec [ { #category : 'initialization' } MicDynamicTextStyler >> bulletForLevel: level [ "outer level is 1, second level is 2, " + ^ ( bullets at: ( (level - 1) % bullets size ) +1 ) asText. ] @@ -92,6 +93,7 @@ MicDynamicTextStyler >> bullets: anObject [ { #category : 'composer styles' } MicDynamicTextStyler >> counterFor: counter atLevel: level [ + | kind | "outer level is 1, second level is 2, " kind := counters at: (level-1 % counters size)+1. @@ -106,6 +108,7 @@ MicDynamicTextStyler >> counterFor: counter atLevel: level [ { #category : 'accessing' } MicDynamicTextStyler >> counters: counterTypes [ "counter types are 1 (number), a (small letters), A (capital letters)" + counters := counterTypes ] @@ -113,7 +116,8 @@ MicDynamicTextStyler >> counters: counterTypes [ MicDynamicTextStyler >> crAfterHeader: spacingSpec [ "spacingSpec is a series of numbers 2;2;1;1 - which is the number of new lines to be added after headers of level1, level2 etc. 1's at the end can be omitted (2;2;1;1 is the same as 2;2)" - |spacings| + + | spacings | crAfterHeader := #(1 1 1 1 1 1) copy. "copy to get non-literal" spacings := ((spacingSpec splitOn: ';') truncateTo: 6) collect: [ :spec |spec asNumber ]. spacings doWithIndex: [ :elem :index |crAfterHeader at: index put: elem ] @@ -121,37 +125,42 @@ MicDynamicTextStyler >> crAfterHeader: spacingSpec [ { #category : 'initialization' } MicDynamicTextStyler >> crAfterHeaderLevel: level [ + ^ String cr repeat: (crAfterHeader at: level) ] { #category : 'initialization' } MicDynamicTextStyler >> crAfterHeaders [ + ^ crAfterHeader ] { #category : 'accessing' } MicDynamicTextStyler >> errors [ + ^ errors ] { #category : 'composer styles' } MicDynamicTextStyler >> headerFont: fontString forLevel: level [ - |list font| + + | list font | (level between: 1 and: 6) ifFalse: [ ^ self addError: 'Header levels are 1 to 6 - got: ', level printString ]. list := (fontString splitOn: $;). list size = 2 - ifFalse: [ ^ self addError: 'Font specs should be name;size - was: ',fontString ]. + ifFalse: [ ^ self addError: 'Font specs should be name;size - was: ', fontString ]. font := LogicalFont familyName: list first pointSize: list second asNumber. headerFonts at: level - put: (TextFontReference toFont:font) + put: (TextFontReference toFont: font) ] { #category : 'initialization' } MicDynamicTextStyler >> initialize [ + self computeHeaderFonts. "super rely on lazy initilization" errors := OrderedCollection new. bullets := '•-'. @@ -166,13 +175,15 @@ MicDynamicTextStyler >> initialize [ { #category : 'composer styles' } MicDynamicTextStyler >> interBlockSpacing [ + ^ interBlockSpacing ] { #category : 'accessing' } MicDynamicTextStyler >> interBlockSpacing: spacingSpec [ "I can put a number of cr between blocks. " - interBlockSpacing := ((String cr) repeat: (spacingSpec asNumber)) asText + + interBlockSpacing := (String cr repeat: (spacingSpec asNumber)) asText ] { #category : 'accessing' } @@ -183,6 +194,7 @@ MicDynamicTextStyler >> keepCRFromInput: aBooleanText [ { #category : 'composer styles' } MicDynamicTextStyler >> monospaceBackgroundColor [ + ^ monospaceBackgroundColor ] @@ -193,7 +205,8 @@ MicDynamicTextStyler >> monospaceBackgroundColor: colorString [ ] { #category : 'composer styles' } -MicDynamicTextStyler >> newLineIfNotAlready [ +MicDynamicTextStyler >> newLineIfNotAlready [ + ^ newLineIfNotAlready ] @@ -201,7 +214,8 @@ MicDynamicTextStyler >> newLineIfNotAlready [ MicDynamicTextStyler >> newLineIfNotAlready: spacingSpec [ "add extra newline or tab indentation of the following line" "spacingSpec is (cr|tab|space)* with ; as seperator - for example 'cr;tab'" - | commands spacing| + + | commands spacing | commands := { ''-> ''. 'cr'->String cr. 'tab'->String tab. 'space'->String space } asDictionary. spacing := ((spacingSpec splitOn: ';') collect: [ :spec | @@ -215,6 +229,7 @@ MicDynamicTextStyler >> newLineIfNotAlready: spacingSpec [ { #category : 'composer styles' } MicDynamicTextStyler >> postTextTreatment: aText [ "my primary purpose is to replace newLines with space in some styles" + keepCRFromInput ifTrue: [ ^ aText ]. ((1 to: aText size) select: [ :i | (aText at: i) = Character cr ]) diff --git a/src/Microdown-RichTextComposer/MicRichTextCanvas.class.st b/src/Microdown-RichTextComposer/MicRichTextCanvas.class.st index 58633b82..21080a31 100644 --- a/src/Microdown-RichTextComposer/MicRichTextCanvas.class.st +++ b/src/Microdown-RichTextComposer/MicRichTextCanvas.class.st @@ -20,36 +20,41 @@ Class { { #category : 'public' } MicRichTextCanvas >> << aText [ - |text| + + | text | aText ifEmpty: [ ^ self ]. text := aText asText. brushes do: [ :brush | brush paint: text ]. "If no font is already put, and a body font is defined, apply it" - ((self hasFontDefinitions: text) not and: [ self textStyler bodyFont isNotNil]) + ((self hasFontDefinitions: text) not and: [ self textStyler bodyFont isNotNil ]) ifTrue: [ text addAttribute: (TextFontReference toFont: self textStyler bodyFont)]. out << text. - text ifNotEmpty: [crAtEnd := text last = Character cr]. + text ifNotEmpty: [ crAtEnd := text last = Character cr ]. ] { #category : 'public' } MicRichTextCanvas >> contents [ + ^ out contents ] { #category : 'public' } MicRichTextCanvas >> cr [ + self newLine ] { #category : 'testing' } MicRichTextCanvas >> hasFontDefinitions: aText [ "Answer the fontfor characters in the run beginning at characterIndex." + ^ (aText runs flattened asSet select: [ :attr | attr isKindOf: TextFontReference ]) isNotEmpty. ] { #category : 'public' } MicRichTextCanvas >> includeAttribute: attr in: aBlock [ + brushes addLast: (MicRichTextBrush on: self attribute: attr). aBlock value. brushes removeLast @@ -58,22 +63,25 @@ MicRichTextCanvas >> includeAttribute: attr in: aBlock [ { #category : 'public' } MicRichTextCanvas >> includeBrush: aBrush in: aBlock [ "Add for the course of aBlock, a brush (aBrush) to the currently used brushes." + brushes addLast: aBrush. aBlock value. brushes removeLast ] { #category : 'public' } -MicRichTextCanvas >> indentIn: aBlock [ +MicRichTextCanvas >> indentIn: aBlock [ + nesting := nesting + 1. aBlock value. - nesting := nesting - 1. + nesting := nesting - 1 ] { #category : 'initialization' } MicRichTextCanvas >> initialize [ + super initialize. out := WriteStream on: '' asText. brushes := OrderedCollection with: (MicRichTextIndentBrush on: self). @@ -83,22 +91,26 @@ MicRichTextCanvas >> initialize [ { #category : 'accessing' } MicRichTextCanvas >> nesting [ + ^ nesting ] { #category : 'public' } MicRichTextCanvas >> newLine [ + self newLineBody. crAtEnd := true ] { #category : 'private' } MicRichTextCanvas >> newLineBody [ + self << self textStyler newLineBody ] { #category : 'public' } MicRichTextCanvas >> newLineIfNotAlready [ + crAtEnd ifFalse: [ self << self textStyler newLineIfNotAlready ]. crAtEnd := true @@ -106,6 +118,7 @@ MicRichTextCanvas >> newLineIfNotAlready [ { #category : 'private' } MicRichTextCanvas >> tab [ + self << String tab asText ] diff --git a/src/Microdown-RichTextComposer/MicRichTextCodeBlockStyler.class.st b/src/Microdown-RichTextComposer/MicRichTextCodeBlockStyler.class.st index bdee9b4a..8e51f320 100644 --- a/src/Microdown-RichTextComposer/MicRichTextCodeBlockStyler.class.st +++ b/src/Microdown-RichTextComposer/MicRichTextCodeBlockStyler.class.st @@ -47,6 +47,7 @@ MicRichTextCodeBlockStyler class >> stylerFor: languageName [ ] { #category : 'accessing' } -MicRichTextCodeBlockStyler >> style: sourceString [ +MicRichTextCodeBlockStyler >> style: sourceString [ + ^ self subclassResponsibility ] diff --git a/src/Microdown-RichTextComposer/MicRichTextComposer.class.st b/src/Microdown-RichTextComposer/MicRichTextComposer.class.st index d25b1627..b565b343 100644 --- a/src/Microdown-RichTextComposer/MicRichTextComposer.class.st +++ b/src/Microdown-RichTextComposer/MicRichTextComposer.class.st @@ -287,6 +287,7 @@ MicRichTextComposer >> doVisitCode: aCodeBlock code: aStringOrText [ { #category : 'initialization' } MicRichTextComposer >> initialize [ + super initialize. codeStylerClass := MicRichTextCodeBlockStyler. self textStyler: MicTextStyler new. @@ -294,7 +295,6 @@ MicRichTextComposer >> initialize [ { #category : 'private' } MicRichTextComposer >> latexFor: aString onError: aBlock [ - "Return a Text containing an image with the latex formula. If the latex formula cannot be built because of network or syntax errors, use the error block to build a text" @@ -313,12 +313,14 @@ MicRichTextComposer >> latexFor: aString onError: aBlock [ { #category : 'private' } MicRichTextComposer >> level [ "level is the logical indention level of lists. Outer list is indented 1, next is indented 3, etc." + ^(canvas nesting // 2) +1 ] { #category : 'private' } MicRichTextComposer >> renderTableCell: aCell [ "a cell is an array of nodes. Each element should be rendered and concatenated" + ^ aCell inject: Text new into: [ :txt :part | txt, (MicRichTextComposer new visit: part) ] @@ -358,6 +360,7 @@ MicRichTextComposer >> theme [ { #category : 'accessing' } MicRichTextComposer >> todo [ + ^ 'there is too much hspace after a section when it is followed by a paragraph. This also because people will not want to to not let a newline between the header and paragraph when writing the text.' ] @@ -375,6 +378,7 @@ MicRichTextComposer >> visit: aDocument [ { #category : 'visiting - document' } MicRichTextComposer >> visitAnnotatedParagraph: anAnnotatedParagraph [ "Do nothing - You are supposed to use specialized annotations" + self error: 'You are not supposed to be here - did you misspell an annotation type?' ] @@ -382,12 +386,14 @@ MicRichTextComposer >> visitAnnotatedParagraph: anAnnotatedParagraph [ { #category : 'visiting - document' } MicRichTextComposer >> visitAnnotation: aMicAnnotationBlock [ "Environment is an abstract class, and if we end here it is because of error" + canvas << ('>>> Annotation ''' , aMicAnnotationBlock name , ''' is not defined <<<') asText ] { #category : 'visiting - format' } MicRichTextComposer >> visitBold: anObject [ + canvas includeAttribute: TextEmphasis bold in: [ super visitBold: anObject ] @@ -395,10 +401,11 @@ MicRichTextComposer >> visitBold: anObject [ ] { #category : 'visiting - extensions' } -MicRichTextComposer >> visitCenter: aMicCenterBlock [ +MicRichTextComposer >> visitCenter: aMicCenterBlock [ + canvas includeAttribute: TextAlignment centered - in: [ super visitChildrenOf: aMicCenterBlock ] + in: [ super visitChildrenOf: aMicCenterBlock ] ] { #category : 'visiting' } @@ -418,6 +425,7 @@ MicRichTextComposer >> visitColumn: columnBlock [ { #category : 'visiting' } MicRichTextComposer >> visitColumns: columnsBlock [ "I render the using MicRichTable which is dedicated to this. I insert the table as an image (form)" + | columns columnsBlocks totalWidth| canvas newLineIfNotAlready. columnsBlocks := columnsBlock children select: [ :c | c isKindOf: MicColumnBlock]. @@ -444,6 +452,7 @@ MicRichTextComposer >> visitColumns: columnsBlock [ { #category : 'visiting - document' } MicRichTextComposer >> visitEnvironment: aMicEnvironmentBlock [ "Environment is an abstract class, and if we end here it is because of error" + canvas << ('>>> Environment ''' , aMicEnvironmentBlock environmentName , ''' is not defined <<<') asText ] @@ -466,6 +475,7 @@ MicRichTextComposer >> visitFigure: aFigure [ { #category : 'visiting' } MicRichTextComposer >> visitFootnote: aFootnote [ "Adds support for footnotes by use of BalloonMorph (because it is silly and retro)" + | popAction popText | popAction := TextAction new actOnClickBlock: [ (BalloonMorph @@ -478,6 +488,7 @@ MicRichTextComposer >> visitFootnote: aFootnote [ { #category : 'visiting - document' } MicRichTextComposer >> visitHeader: aHeader [ + | level | canvas newLineIfNotAlready. level := aHeader level min: 6. @@ -497,6 +508,7 @@ MicRichTextComposer >> visitHorizontalLine: anHorizontalLine [ { #category : 'visiting' } MicRichTextComposer >> visitInputFile: inputFileBloc [ + | inputRef includedText | inputRef := inputFileBloc reference. inputRef isRelative @@ -507,6 +519,7 @@ MicRichTextComposer >> visitInputFile: inputFileBloc [ { #category : 'visiting - format' } MicRichTextComposer >> visitItalic: anObject [ + canvas includeAttribute: TextEmphasis italic in: [ super visitItalic: anObject ] @@ -523,19 +536,9 @@ MicRichTextComposer >> visitLink: aLink [ canvas includeAttribute: attribute in: [ super visitLink: aLink ] ] -{ #category : 'visiting - document' } -MicRichTextComposer >> visitLink_old: aLink [ - - | attribute | - attribute := TextAction new - actOnClickBlock: [ - WebBrowser openOn: aLink url ]; - yourself. - canvas includeAttribute: attribute in: [ super visitLink: aLink ] -] - { #category : 'visiting - list' } MicRichTextComposer >> visitListItem: anItem [ + | bullet | "The depth counter and bullet type in `visitOrderedList` and `visitUnorderedList`" bullet := (anItem propertyAt: #kind) = #ordered @@ -563,13 +566,13 @@ MicRichTextComposer >> visitMathInline: aMicMathInline [ | aString | aString := aMicMathInline bodyString. aString ifEmpty: [ ^ self ]. - canvas - << (self latexFor: aString onError: [ '$ - LATEX ERROR - $' asText ]) + canvas << (self latexFor: aString onError: [ '$ - LATEX ERROR - $' asText ]) ] { #category : 'visiting - inline elements' } MicRichTextComposer >> visitMonospace: anObject [ "Notice - I add a highlight to the backgorund rather than mono-spaced." + | backgroundColor sem | backgroundColor := self textStyler monospaceBackgroundColor. self flag: #fixMe. @@ -588,6 +591,7 @@ MicRichTextComposer >> visitMonospace: anObject [ { #category : 'visiting - list' } MicRichTextComposer >> visitOrderedList: aList [ "here we annotate items with their kind and the depth" + | counter | canvas newLineIfNotAlready. canvas indentIn: [counter := 1. @@ -625,8 +629,8 @@ MicRichTextComposer >> visitPharoEvaluator: aScriptBlock [ Microdown tree - rendered to text then inserted verbatim String - Parsed, then rendered, then inserted. Other results - printString asText - then inserted verbatim" - | label script doitForm codeText oldCanvas | + | label script doitForm codeText oldCanvas | script := aScriptBlock body. label := aScriptBlock label ifNil: [ String value: 1 ]. @@ -658,6 +662,7 @@ MicRichTextComposer >> visitPharoEvaluator: aScriptBlock [ { #category : 'visiting' } MicRichTextComposer >> visitQuote: aQuote [ "I should have a fancier implementation, but for now this should work and be recognized as a quote" + canvas newLineIfNotAlready. canvas << ('>',String tab) asText.. canvas indentIn: [ super visitQuote: aQuote ]. @@ -672,6 +677,7 @@ MicRichTextComposer >> visitRaw: aRawFormat [ { #category : 'visiting' } MicRichTextComposer >> visitRichTextFormatConfiguration: config [ + self textStyler class = MicDynamicTextStyler ifFalse: [ self textStyler: MicDynamicTextStyler new ]. config adjustStyler: self textStyler. @@ -681,10 +687,11 @@ MicRichTextComposer >> visitRichTextFormatConfiguration: config [ ] { #category : 'visiting' } -MicRichTextComposer >> visitRightAlignment: aMicRightAlignmentBlock [ +MicRichTextComposer >> visitRightAlignment: aMicRightAlignmentBlock [ + canvas includeAttribute: TextAlignment rightFlush - in: [ self visitChildrenOf: aMicRightAlignmentBlock ] + in: [ self visitChildrenOf: aMicRightAlignmentBlock ] ] { #category : 'visiting - extensions' } @@ -695,6 +702,7 @@ MicRichTextComposer >> visitScript: aScriptBlock [ String - Parsed, then rendered, then inserted. Other results - printString asText - then inserted verbatim " + | script result resText | "There is a bit too much type testing here - double dispatch or different kinds of scripts, or..." script := aScriptBlock body. @@ -728,6 +736,7 @@ MicRichTextComposer >> visitStrike: anObject [ { #category : 'visiting - format' } MicRichTextComposer >> visitTable: tableBlock [ "I render the using MicRichTable which is dedicated to this. I insert the table as an image (form)" + | headers rows table anchoredTable renderedRows | renderedRows := tableBlock rows collect: [ :oneRow | oneRow collect: [ :cell | self renderTableCell: cell ]]. tableBlock hasHeader @@ -763,6 +772,7 @@ MicRichTextComposer >> visitText: anInlineBlock [ { #category : 'visiting - list' } MicRichTextComposer >> visitUnorderedList: aList [ + canvas newLineIfNotAlready. canvas indentIn: [ diff --git a/src/Microdown-RichTextComposer/MicRichTextFormatConfiguration.class.st b/src/Microdown-RichTextComposer/MicRichTextFormatConfiguration.class.st index a4b45adb..5d041b77 100644 --- a/src/Microdown-RichTextComposer/MicRichTextFormatConfiguration.class.st +++ b/src/Microdown-RichTextComposer/MicRichTextFormatConfiguration.class.st @@ -36,17 +36,18 @@ MicRichTextFormatConfiguration >> accept: visitor [ { #category : 'visiting' } MicRichTextFormatConfiguration >> adjustStyler: styler [ + | setters | setters := self setterDictionaryFor: styler. arguments justTheArguments keysAndValuesDo: [ :key :value | setters at: key ifPresent: [ :block | block value: value] - ifAbsent: [ styler addError: 'richtext annotation - unknown argument: ', key ] - ]. + ifAbsent: [ styler addError: 'richtext annotation - unknown argument: ', key ] ] ] { #category : 'private' } MicRichTextFormatConfiguration >> setterDictionaryFor: styler [ + ^ { 'bullets' -> [ :a | styler bullets: a]. 'counters' -> [ :a | styler counters: a]. diff --git a/src/Microdown-RichTextComposer/MicRichTextLinkPresenter.class.st b/src/Microdown-RichTextComposer/MicRichTextLinkPresenter.class.st index 5a2a1294..3c20fabd 100644 --- a/src/Microdown-RichTextComposer/MicRichTextLinkPresenter.class.st +++ b/src/Microdown-RichTextComposer/MicRichTextLinkPresenter.class.st @@ -27,7 +27,8 @@ Class { { #category : 'opening' } MicRichTextLinkPresenter >> guessKindOf: aMicAbsoluteResourceReference [ - |kind| + + | kind | kind := aMicAbsoluteResourceReference path copyAfterLast: $. . kind ifNotEmpty: [ ^ kind]. ((aMicAbsoluteResourceReference contents) asLowercase includesSubstring: '> guessKindOf: aMicAbsoluteResourceReference [ ] { #category : 'opening' } -MicRichTextLinkPresenter >> openFormOn: aMicResourceReference [ +MicRichTextLinkPresenter >> openFormOn: aMicResourceReference [ + |image window | image := aMicResourceReference loadImage. window := SpImagePresenter new @@ -52,6 +54,7 @@ MicRichTextLinkPresenter >> openFormOn: aMicResourceReference [ { #category : 'opening' } MicRichTextLinkPresenter >> openLink: anAbsoluteResourceReference [ + | kind | anAbsoluteResourceReference isRelative ifTrue: [ MicResourceReferenceError @@ -69,12 +72,14 @@ MicRichTextLinkPresenter >> openLink: anAbsoluteResourceReference [ { #category : 'opening' } MicRichTextLinkPresenter >> openWebLink: aHtmlResource [ + WebBrowser openOn: aHtmlResource uri ] { #category : 'opening' } MicRichTextLinkPresenter >> pragmaForKind: kind [ - | implementation | + + | implementation | implementation := (Pragma allNamed: #richtextlinkpresenter:) select: [ :pragma | pragma arguments first = kind ]. ^ implementation @@ -84,6 +89,7 @@ MicRichTextLinkPresenter >> pragmaForKind: kind [ MicRichTextLinkPresenter >> resolveKind: kind andOpen: aMicHTTPResourceReference [ "I will check if there is an implementation which would like to handle this kind. If so, handle it, if not return false" + | implementation implementerClass | implementation := self pragmaForKind: kind. implementation diff --git a/src/Microdown-RichTextComposer/MicRichTextTable.class.st b/src/Microdown-RichTextComposer/MicRichTextTable.class.st index 1e084bd8..146418f1 100644 --- a/src/Microdown-RichTextComposer/MicRichTextTable.class.st +++ b/src/Microdown-RichTextComposer/MicRichTextTable.class.st @@ -17,7 +17,8 @@ MicRichTextTable class >> headers: headers rows: rows [ { #category : 'adding' } MicRichTextTable >> addHeaders: headers with: renderedRows [ - |totalWidth totalHeight | + + | totalWidth totalHeight | totalWidth := 0. totalHeight := 0. 1 to: headers size do:[ :colIndex | |header colRows colWidth colHeight| @@ -36,6 +37,7 @@ MicRichTextTable >> addHeaders: headers with: renderedRows [ { #category : 'initialization' } MicRichTextTable >> headers: headers rows: rows [ + self addHeaders: headers with: rows ; dataSource: (MicRichTextTableDataSource headers: headers rows: rows); @@ -47,6 +49,7 @@ MicRichTextTable >> headers: headers rows: rows [ { #category : 'rendering' } MicRichTextTable >> renderCell: aCell [ "a cell is an array of nodes. Each element should be rendered and concatenated" + ^ aCell inject: Text new into: [ :txt :part | txt, (MicRichTextComposer new visit: part) ] @@ -55,6 +58,7 @@ MicRichTextTable >> renderCell: aCell [ { #category : 'private' } MicRichTextTable >> resizeAllSubviews [ "This method is just like its super, except it prevents the vertical scroll bar to appear" + self resizeContainer. self container setNeedsRefreshExposedRows. self container updateExposedRows. diff --git a/src/Microdown-RichTextComposer/MicRichTextTableDataSource.class.st b/src/Microdown-RichTextComposer/MicRichTextTableDataSource.class.st index 9541b53b..ae2abe36 100644 --- a/src/Microdown-RichTextComposer/MicRichTextTableDataSource.class.st +++ b/src/Microdown-RichTextComposer/MicRichTextTableDataSource.class.st @@ -21,6 +21,7 @@ MicRichTextTableDataSource class >> headers: headers rows: theRows [ { #category : 'accessing' } MicRichTextTableDataSource >> basicHeaderCellFor: column [ + | cell | column id ifNil: [ ^ nil ]. cell := FTHeaderColumnCellMorph new @@ -35,6 +36,7 @@ MicRichTextTableDataSource >> basicHeaderCellFor: column [ { #category : 'accessing' } MicRichTextTableDataSource >> cellColumn: column row: rowIndex [ "Answer a morph with the cell view. I will probably return a FTCellMorph." + | cell | cell := ((rows at: rowIndex )at: (colNames at: column id )). ^ FTCellMorph new @@ -46,11 +48,13 @@ MicRichTextTableDataSource >> cellColumn: column row: rowIndex [ MicRichTextTableDataSource >> elementAt: rowIndex [ "I am a really important method for a DataSource. I take an index and I return an object that should be displayed in the table for the index." + rows at: rowIndex ] { #category : 'initialization' } MicRichTextTableDataSource >> headers: headers rows: theRows [ + rows := theRows. colNames := Dictionary new. 1 to: headers size do: [ :index | colNames at: (headers at: index) put: index ] @@ -65,6 +69,7 @@ MicRichTextTableDataSource >> numberOfRows [ { #category : 'accessing' } MicRichTextTableDataSource >> rowHeight: rowIndex [ + ^ (rows at: rowIndex ) max: [ :cell | cell asTextMorph height ] ] @@ -84,13 +89,14 @@ MicRichTextTableDataSource >> unsortElements [ { #category : 'private' } MicRichTextTableDataSource >> widthOfText: txt [ - |width| + + | width | width := ((txt fontAt: 1) widthOfStringOrText: txt). 1 to: txt size do: [ :index | (txt at: index) = (Character value: 1) ifTrue: [ width := width + - ((txt attributesAt: index) detect: [:att| att class = TextAnchor]) anchoredMorph width. + ((txt attributesAt: index) detect: [:att| att class = TextAnchor ]) anchoredMorph width. ] ]. - ^width + ^ width ] diff --git a/src/Microdown-RichTextComposer/MicScalingTextAnchor.class.st b/src/Microdown-RichTextComposer/MicScalingTextAnchor.class.st index 6982bb74..223ae856 100644 --- a/src/Microdown-RichTextComposer/MicScalingTextAnchor.class.st +++ b/src/Microdown-RichTextComposer/MicScalingTextAnchor.class.st @@ -50,6 +50,7 @@ MicScalingTextAnchor >> original: aForm [ { #category : 'accessing' } MicScalingTextAnchor >> scale: percentOrNil [ + scale := percentOrNil ] diff --git a/src/Microdown-RichTextComposer/MicSemanticAction.class.st b/src/Microdown-RichTextComposer/MicSemanticAction.class.st index 8db6e33d..bf45f065 100644 --- a/src/Microdown-RichTextComposer/MicSemanticAction.class.st +++ b/src/Microdown-RichTextComposer/MicSemanticAction.class.st @@ -35,7 +35,7 @@ Class { MicSemanticAction class >> from: aString [ | contents | - contents := (RBScanner on: (ReadStream on: aString)) contents. + contents := (OCScanner on: (ReadStream on: aString)) contents. ^ self fromTokens: (contents collect: [ :e | e value ]) ] @@ -134,6 +134,7 @@ MicSemanticAction >> getMetaClassOrNil [ { #category : 'instance creation' } MicSemanticAction >> getPackageOrNil [ + entity := self class packageOrganizer packageNamed: tokens first asString ifAbsent: [ nil ]. ^ entity @@ -141,6 +142,7 @@ MicSemanticAction >> getPackageOrNil [ { #category : 'testing' } MicSemanticAction >> hasEntity [ + ^ entity isNotNil ] diff --git a/src/Microdown-RichTextComposer/MicSmalltalkTextStyler.class.st b/src/Microdown-RichTextComposer/MicSmalltalkTextStyler.class.st index df220d03..f4130e8c 100644 --- a/src/Microdown-RichTextComposer/MicSmalltalkTextStyler.class.st +++ b/src/Microdown-RichTextComposer/MicSmalltalkTextStyler.class.st @@ -44,6 +44,7 @@ MicSmalltalkTextStyler >> attributesFor: aSymbol [ { #category : 'private' } MicSmalltalkTextStyler >> resolveStyleFor: aVariableNode [ "This circumvent an error in my super" + aVariableNode isUndeclaredVariable ifTrue: [ ^#undefinedIdentifier ]. ^ super resolveStyleFor: aVariableNode ] diff --git a/src/Microdown-RichTextComposer/MicTextStyler.class.st b/src/Microdown-RichTextComposer/MicTextStyler.class.st index ce1de18b..55f71db1 100644 --- a/src/Microdown-RichTextComposer/MicTextStyler.class.st +++ b/src/Microdown-RichTextComposer/MicTextStyler.class.st @@ -24,6 +24,7 @@ MicTextStyler >> bodyFont [ { #category : 'composer styles' } MicTextStyler >> bulletForLevel: level [ "first level is 1, then 2, then 3..." + ^ ('•-' at: (level-1 % 2)+1) asText ] @@ -43,6 +44,7 @@ MicTextStyler >> computeHeaderFonts [ { #category : 'composer styles' } MicTextStyler >> counterFor: counter atLevel: level [ + | kind | "first level is 1" kind := level % 3. @@ -57,24 +59,28 @@ MicTextStyler >> counterFor: counter atLevel: level [ { #category : 'composer styles' } MicTextStyler >> crAfterHeaderLevel: level [ "I return Text to make space after a header" + ^ String cr asText ] { #category : 'public' } MicTextStyler >> headerFontSizes [ + ^ #(28 24 18 14 12 10) ] { #category : 'private' } MicTextStyler >> headerLevelFont: level [ "I return a font annotation to be used with Attributes" - headerFonts ifNil: [ self computeHeaderFonts ]. + + headerFonts ifNil: [ self computeHeaderFonts ]. ^ headerFonts at: (level min: 6) ] { #category : 'composer styles' } MicTextStyler >> interBlockSpacing [ "I return the space to be put between blocks, first cr to end block, second to make empty line" + ^ (String cr, String cr) asText ] @@ -87,6 +93,7 @@ MicTextStyler >> monospaceBackgroundColor [ { #category : 'canvas styles' } MicTextStyler >> newLineBody [ "return a newline" + ^ String cr asText ] @@ -94,6 +101,7 @@ MicTextStyler >> newLineBody [ MicTextStyler >> newLineIfNotAlready [ "return a newline if there is not already one" "Intended to be overridden to add extra newline or tab indentation of the following line" + ^ String cr asText ] @@ -103,6 +111,7 @@ MicTextStyler >> postTextTreatment: aText [ "((1 to: aText size) select: [ :i | (aText at: i) = Character cr ]) do: [ :i | aText at: i put: Character space ]." + ^ aText ] diff --git a/src/Microdown-RichTextComposer/OrderedCollection.extension.st b/src/Microdown-RichTextComposer/OrderedCollection.extension.st deleted file mode 100644 index a7b075d1..00000000 --- a/src/Microdown-RichTextComposer/OrderedCollection.extension.st +++ /dev/null @@ -1,10 +0,0 @@ -Extension { #name : 'OrderedCollection' } - -{ #category : '*Microdown-RichTextComposer' } -OrderedCollection >> truncateTo: smallSize [ - "return myself or a copy shortened to smallSize." - - ^ self size <= smallSize - ifTrue: [ self ] - ifFalse: [ self copyFrom: 1 to: smallSize ] -] diff --git a/src/Microdown-RichTextComposer/Text.extension.st b/src/Microdown-RichTextComposer/Text.extension.st deleted file mode 100644 index 78d9d514..00000000 --- a/src/Microdown-RichTextComposer/Text.extension.st +++ /dev/null @@ -1,16 +0,0 @@ -Extension { #name : 'Text' } - -{ #category : '*Microdown-RichTextComposer' } -Text >> trim [ - | left right | - left := 1. - right := self size. - - [ left <= right and: [ (self at: left) isSeparator ] ] - whileTrue: [ left := left + 1 ]. - - [ left <= right and: [ (self at: right) isSeparator ] ] - whileTrue: [ right := right - 1 ]. - - ^ self copyFrom: left to: right -] diff --git a/src/Microdown-Tests/MicAnnotatedParagraphBlockTest.class.st b/src/Microdown-Tests/MicAnnotatedParagraphBlockTest.class.st index e4aee452..e33378a4 100644 --- a/src/Microdown-Tests/MicAnnotatedParagraphBlockTest.class.st +++ b/src/Microdown-Tests/MicAnnotatedParagraphBlockTest.class.st @@ -11,6 +11,40 @@ MicAnnotatedParagraphBlockTest >> subjectClass [ ^ MicAnnotatedParagraphBlock ] +{ #category : 'tests' } +MicAnnotatedParagraphBlockTest >> testAnnotatedParagraphBreakingTheParser [ + + | root annotatedParagraph | + root := parser parse: ' + +>[! important] I would like a piece of code here ] +> This is an important information'. + self assert: root children size equals: 1. + annotatedParagraph := root children first. + self + assert: (annotatedParagraph isKindOf: MicAnnotatedParagraphBlock); + assert: annotatedParagraph label equals: 'important'; + assert: annotatedParagraph text + equals: 'This is an important information' +] + +{ #category : 'tests' } +MicAnnotatedParagraphBlockTest >> testAnnotatedParagraphBreakingTheParser2 [ + + | root annotatedParagraph | + root := parser parse: ' + +>[! SD] I would like a piece of code here +> This is an important information'. + self assert: root children size equals: 1. + annotatedParagraph := root children first. + self + assert: (annotatedParagraph isKindOf: MicAnnotatedParagraphBlock); + assert: annotatedParagraph label equals: 'note'; + assert: annotatedParagraph text + equals: 'This is an important information' +] + { #category : 'tests' } MicAnnotatedParagraphBlockTest >> testBasicAnnotetedParagraph [ @@ -30,7 +64,7 @@ MicAnnotatedParagraphBlockTest >> testBasicAnnotetedParagraph [ MicAnnotatedParagraphBlockTest >> testBasicAnnotetedParagraphIgnoreExtraTextInFirstLine [ | root annotatedParagraph | - root := parser parse: '>[! important ] This is an important information + root := parser parse: '>[! important ] Let us be less silly > This is an other information'. self assert: root children size equals: 1. annotatedParagraph := root children first. @@ -80,31 +114,16 @@ MicAnnotatedParagraphBlockTest >> testBasicAnnotetedParagraphWithANonSupportedLa assert: (annotatedParagraph isKindOf: MicAnnotatedParagraphBlock); assert: annotatedParagraph label equals: 'note'; assert: annotatedParagraph text - equals: 'test This is an important information' -] - -{ #category : 'tests' } -MicAnnotatedParagraphBlockTest >> testBasicAnnotetedParagraphWithANonSupportedLabelWithUpperCase [ - - | root annotatedParagraph | - root := parser parse: '>[! Test ] -> This is an important information'. - self assert: root children size equals: 1. - annotatedParagraph := root children first. - self - assert: (annotatedParagraph isKindOf: MicAnnotatedParagraphBlock); - assert: annotatedParagraph label equals: 'note'; - assert: annotatedParagraph text - equals: 'Test This is an important information' + equals: 'This is an important information' ] { #category : 'tests' } -MicAnnotatedParagraphBlockTest >> testBasicAnnotetedParagraphWithBlodText [ +MicAnnotatedParagraphBlockTest >> testBasicAnnotetedParagraphWithBoldText [ | root annotatedParagraph | root := parser parse: '>[! important ] -> This is an **important** information'. +> This is an **crucial** information'. self assert: root children size equals: 1. annotatedParagraph := root children first. self @@ -115,7 +134,7 @@ MicAnnotatedParagraphBlockTest >> testBasicAnnotetedParagraphWithBlodText [ (annotatedParagraph textElements second isKindOf: MicBoldFormatBlock); assert: annotatedParagraph textElements second plainText - equals: 'important' + equals: 'crucial' ] { #category : 'tests' } @@ -123,12 +142,12 @@ MicAnnotatedParagraphBlockTest >> testBasicAnnotetedParagraphWithLabelHavingUppe | root annotatedParagraph | root := parser parse: '>[! ImporTanT ] -> This is an important information'. +> This is a crucial information'. self assert: root children size equals: 1. annotatedParagraph := root children first. self assert: (annotatedParagraph isKindOf: MicAnnotatedParagraphBlock); assert: annotatedParagraph label equals: 'important'; assert: annotatedParagraph text - equals: 'This is an important information' + equals: 'This is a crucial information' ] diff --git a/src/Microdown-Tests/MicLinkBlockTest.class.st b/src/Microdown-Tests/MicLinkBlockTest.class.st index b3984624..6815d925 100644 --- a/src/Microdown-Tests/MicLinkBlockTest.class.st +++ b/src/Microdown-Tests/MicLinkBlockTest.class.st @@ -121,7 +121,8 @@ MicLinkBlockTest >> testLinkCreatesInnerText [ link := self parseLink: '[ab](https://ab.com)'. self assert: link class equals: MicLinkBlock. - self assert: link url equals: 'https://ab.com' + self assert: link url equals: 'https://ab.com'. + self assert: link children first parent equals: link ] { #category : 'tests - link' } diff --git a/src/Microdown-ToHelpMacrodownLoading/MicMicrodownObjectToPillarObjectConverter.class.st b/src/Microdown-ToHelpMacrodownLoading/MicMicrodownObjectToPillarObjectConverter.class.st index 78bc5c4a..7f31dd29 100644 --- a/src/Microdown-ToHelpMacrodownLoading/MicMicrodownObjectToPillarObjectConverter.class.st +++ b/src/Microdown-ToHelpMacrodownLoading/MicMicrodownObjectToPillarObjectConverter.class.st @@ -4,3 +4,298 @@ Class { #category : 'Microdown-ToHelpMacrodownLoading', #package : 'Microdown-ToHelpMacrodownLoading' } + +{ #category : 'formatting' } +MicMicrodownObjectToPillarObjectConverter >> formatBlock: aMicFormatBlock [ + | childrenAsPillar | + childrenAsPillar := aMicFormatBlock children collect: [:e | e accept: self ]. + ^ aMicFormatBlock associatedPillarClass new + setChildren: childrenAsPillar; + yourself +] + +{ #category : 'formatting' } +MicMicrodownObjectToPillarObjectConverter >> urlBlock: aMicUrlBlock [ + + | queries urlString | + queries := aMicUrlBlock reference uri query. + aMicUrlBlock reference uri query: nil. + "UGLY we remove the query dicrtionary just to print." + urlString := aMicUrlBlock reference uri asString. + "the following test is needed as reported in https://github.com/pillar-markup/Microdown/issues/527" + urlString first = $/ ifTrue: [ urlString := urlString allButFirst ]. + + aMicUrlBlock reference uri query: queries. + ^ aMicUrlBlock associatedPillarClass new + setChildren: + (aMicUrlBlock children collect: [ :n | + n accept: self ]); + reference: urlString; + yourself +] + +{ #category : 'visiting' } +MicMicrodownObjectToPillarObjectConverter >> visit: aNode [ + + aNode accept: self +] + +{ #category : 'visiting' } +MicMicrodownObjectToPillarObjectConverter >> visitAnchor: aMicAnchorBlock [ + ^ PRAnchor new name: aMicAnchorBlock label; yourself +] + +{ #category : 'visiting inline' } +MicMicrodownObjectToPillarObjectConverter >> visitAnchorReference: aMicAnchorReference [ + + ^ PRInternalLink new + anchor: aMicAnchorReference bodyString; + yourself +] + +{ #category : 'visiting' } +MicMicrodownObjectToPillarObjectConverter >> visitAnnotated: aMicAnnotatedBlock [ + ^ PRAnnotatedParagraph new + annotation: aMicAnnotatedBlock label; + setChildren: (aMicAnnotatedBlock pillarFrom: aMicAnnotatedBlock textElements); + yourself +] + +{ #category : 'visiting inline' } +MicMicrodownObjectToPillarObjectConverter >> visitAnnotation: aMicAnnotation [ + ^ aMicAnnotation associatedPillarClass new parameters: aMicAnnotation arguments +] + +{ #category : 'visiting inline' } +MicMicrodownObjectToPillarObjectConverter >> visitBold: aMicBold [ + ^ self formatBlock: aMicBold +] + +{ #category : 'visiting' } +MicMicrodownObjectToPillarObjectConverter >> visitCell: aCell [ + | cell | + cell := PRTableCell new. + aCell do: [ :each | cell add: (each accept: self) ]. + ^ cell +] + +{ #category : 'visiting' } +MicMicrodownObjectToPillarObjectConverter >> visitCode: aMicCodeBlock [ + + | prBlock par pillars | + prBlock := PRCodeblock new. + prBlock text: aMicCodeBlock code. + + aMicCodeBlock arguments keysAndValuesDo: [ :k :v | + (aMicCodeBlock arguments includesKey: #language) + ifFalse: [ + (aMicCodeBlock arguments keys first = k and: v isEmptyOrNil) + ifTrue: [ prBlock parameterAt: 'language' put: k ] + ifFalse: [ prBlock parameterAt: k put: v ] ] + ifTrue: [ prBlock parameterAt: k put: v ] ]. + + aMicCodeBlock hasCaption + ifTrue: [ + prBlock parameters removeKey: #caption. + par := PRParagraph new. + pillars := aMicCodeBlock captionElements collect: [ :each | + each accept: MicMicrodownObjectToPillarObjectConverter new ]. + pillars do: [ :each | par add: each ]. + prBlock setCaption: par ] + ifFalse: [ + prBlock caption "Yes this is not an accessor but something with side effect" ]. + ^ prBlock +] + +{ #category : 'visiting' } +MicMicrodownObjectToPillarObjectConverter >> visitComment: aMicCommentBlock [ + ^ PRCommentedLine new + text: aMicCommentBlock text ; + yourself +] + +{ #category : 'visiting' } +MicMicrodownObjectToPillarObjectConverter >> visitEnvironment: aMicEnvironmentBlock [ + + | env | + env := PREnvironment new + name: aMicEnvironmentBlock environmentName; + parameters: aMicEnvironmentBlock arguments; yourself. + env add: (PRParagraph withAll: (aMicEnvironmentBlock pillarFrom: aMicEnvironmentBlock bodyElements)). + ^ env +] + +{ #category : 'visiting inline' } +MicMicrodownObjectToPillarObjectConverter >> visitFigure: aMicFigureBlock [ + + | aPRFigure | + aPRFigure := self urlBlock: aMicFigureBlock. + ^ aPRFigure + label: (aMicFigureBlock children collect: [:each | self visit: each ]); + parameters: aMicFigureBlock arguments; + yourself +] + +{ #category : 'visiting' } +MicMicrodownObjectToPillarObjectConverter >> visitFormatBlock: aMicFormatBlock [ + | childrenAsPillar | + childrenAsPillar := aMicFormatBlock isOnlyChild + ifTrue: [ {(PRText new text: aMicFormatBlock substring )} ] + ifFalse: [ aMicFormatBlock children collect: [:e | e accept: self ] ]. + ^ aMicFormatBlock associatedPillarClass new + setChildren: childrenAsPillar; + yourself +] + +{ #category : 'visiting' } +MicMicrodownObjectToPillarObjectConverter >> visitHeader: aMicHeaderBlock [ + + ^ PRHeader new + level: aMicHeaderBlock level; + setChildren: (aMicHeaderBlock children collect: [:each | each accept: self ]); + yourself +] + +{ #category : 'visiting' } +MicMicrodownObjectToPillarObjectConverter >> visitHorizontalLine: anHorizontalLineBlock [ + ^ PRHorizontalRule new +] + +{ #category : 'visiting inline' } +MicMicrodownObjectToPillarObjectConverter >> visitItalic: aMicItalic [ + ^ self formatBlock: aMicItalic +] + +{ #category : 'visiting inline' } +MicMicrodownObjectToPillarObjectConverter >> visitLink: aMicLink [ + + ^ aMicLink associatedPillarClass new + setChildren: + (aMicLink children collect: [ :n | + n accept: self ]); + reference: aMicLink url asString; + yourself +] + +{ #category : 'visiting' } +MicMicrodownObjectToPillarObjectConverter >> visitListItem: aMicListItemBlock [ + + ^ PRListItem new + setChildren: "(aMicListItemBlock pillarFrom: aMicListItemBlock textElements)," (aMicListItemBlock children collect: [:child| child accept: self]); + yourself; + yourself + +] + +{ #category : 'visiting' } +MicMicrodownObjectToPillarObjectConverter >> visitMath: aMicMathBlock [ + | captionElements | + captionElements := aMicMathBlock arguments at: 'caption' ifAbsent: [ nil ]. + captionElements isNotNil + ifTrue: [ aMicMathBlock arguments at: 'caption' put: (aMicMathBlock pillarFrom: captionElements) ]. + ^ PRMathEnvironment new + parameters: aMicMathBlock arguments; + add: (PRText content: aMicMathBlock body); + yourself +] + +{ #category : 'visiting inline' } +MicMicrodownObjectToPillarObjectConverter >> visitMathInline: aMicMathInline [ + ^ self formatBlock: aMicMathInline +] + +{ #category : 'visiting inline' } +MicMicrodownObjectToPillarObjectConverter >> visitMetaData: aMicMetaData [ + ^ PRMetadata new + metadata: aMicMetaData body; yourself +] + +{ #category : 'visiting inline' } +MicMicrodownObjectToPillarObjectConverter >> visitMonospace: aMicMonospace [ + ^ self formatBlock: aMicMonospace +] + +{ #category : 'visiting' } +MicMicrodownObjectToPillarObjectConverter >> visitOrderedList: aMicOrderedListBlock [ + ^ PROrderedList new + setChildren: (aMicOrderedListBlock children collect: [ :child | child accept: self ]); + counter: aMicOrderedListBlock startIndex; + yourself +] + +{ #category : 'visiting' } +MicMicrodownObjectToPillarObjectConverter >> visitParagraph: aMicParagraphBlock [ + ^ PRParagraph new + setChildren: (aMicParagraphBlock pillarFromString: aMicParagraphBlock text); + yourself +] + +{ #category : 'visiting' } +MicMicrodownObjectToPillarObjectConverter >> visitQuote: aMicQuoteBlock [ + ^ PRPreformatted new + setChildren: (aMicQuoteBlock pillarFromString: aMicQuoteBlock text); + yourself +] + +{ #category : 'visiting inline' } +MicMicrodownObjectToPillarObjectConverter >> visitRaw: aMicRaw [ + + ^ PRRaw new + text: aMicRaw bodyString; + yourself +] + +{ #category : 'visiting' } +MicMicrodownObjectToPillarObjectConverter >> visitRawParagraph: aMicParagraphBlock [ + ^ PRParagraph new + setChildren: (aMicParagraphBlock pillarFromString: aMicParagraphBlock text); + yourself +] + +{ #category : 'visiting' } +MicMicrodownObjectToPillarObjectConverter >> visitRoot: aMicRootBlock [ + ^ PRDocument new + setChildren: (aMicRootBlock children collect: [ :child | child accept: self ]); + yourself + +] + +{ #category : 'visiting' } +MicMicrodownObjectToPillarObjectConverter >> visitRow: aRow in: aTable at: i [ + + | row | + row := PRTableRow new. + i = 1 + ifTrue: [ aRow do: [ :cell | row add: ((self visitCell: cell) heading: true) ] ] + ifFalse: [ aRow do: [ :cell | row add: (self visitCell: cell) ] ]. + ^ row +] + +{ #category : 'visiting inline' } +MicMicrodownObjectToPillarObjectConverter >> visitStrike: aMicStrike [ + ^ self formatBlock: aMicStrike +] + +{ #category : 'visiting' } +MicMicrodownObjectToPillarObjectConverter >> visitTable: aTable [ + | table | + table := PRTable new. + aTable rows doWithIndex: [ :row : i | + table add: (self visitRow: row in: aTable at: i)]. + ^ table +] + +{ #category : 'visiting inline' } +MicMicrodownObjectToPillarObjectConverter >> visitText: aMicTextBlock [ + + ^ PRText new + text: aMicTextBlock bodyString; + yourself +] + +{ #category : 'visiting' } +MicMicrodownObjectToPillarObjectConverter >> visitUnorderedList: aMicUnorderedListBlock [ + ^ PRUnorderedList new + setChildren: (aMicUnorderedListBlock children collect:[:child| child accept: self]); + yourself +] diff --git a/src/Microdown/MicAnnotatedParagraphBlock.class.st b/src/Microdown/MicAnnotatedParagraphBlock.class.st index ca64cea1..2fb3ec0e 100644 --- a/src/Microdown/MicAnnotatedParagraphBlock.class.st +++ b/src/Microdown/MicAnnotatedParagraphBlock.class.st @@ -45,14 +45,14 @@ MicAnnotatedParagraphBlock >> closeMe [ { #category : 'accessing' } MicAnnotatedParagraphBlock >> defaultLabel [ - ^ #note + ^ 'note' ] { #category : 'initialization' } MicAnnotatedParagraphBlock >> initialize [ super initialize. - validLabels := { #note. #important. #todo } + validLabels := { 'note' . 'important' . 'todo' } ] { #category : 'accessing' } @@ -81,7 +81,5 @@ MicAnnotatedParagraphBlock >> verifyLabel [ isValid := validLabels includes: label asLowercase. isValid ifTrue: [ label := label asLowercase ] - ifFalse: [ - body := label , String space , body. - label := self defaultLabel ] + ifFalse: [ label := self defaultLabel ] ] diff --git a/src/Microdown/MicBridge.class.st b/src/Microdown/MicBridge.class.st new file mode 100644 index 00000000..3fe766d8 --- /dev/null +++ b/src/Microdown/MicBridge.class.st @@ -0,0 +1,15 @@ +" +I am a bridge to access resources from Microdown clone +" +Class { + #name : 'MicBridge', + #superclass : 'GitBridge', + #category : 'Microdown-Utils', + #package : 'Microdown', + #tag : 'Utils' +} + +{ #category : 'accessing' } +MicBridge class >> resources [ + ^ self root / 'ressource' +]