diff --git a/src/Microdown-RichTextComposer-Tests/MicRichTextTableTest.class.st b/src/Microdown-RichTextComposer-Tests/MicRichTextTableTest.class.st new file mode 100644 index 00000000..40ab3ef1 --- /dev/null +++ b/src/Microdown-RichTextComposer-Tests/MicRichTextTableTest.class.st @@ -0,0 +1,74 @@ +" +A MicRichTextTableTest is a test class for testing the behavior of MicRichTextTable +" +Class { + #name : 'MicRichTextTableTest', + #superclass : 'TestCase', + #instVars : [ + 'tableBlock', + 'header', + 'rowShort', + 'row3' + ], + #category : 'Microdown-RichTextComposer-Tests-Table-Support', + #package : 'Microdown-RichTextComposer-Tests', + #tag : 'Table-Support' +} + +{ #category : 'running' } +MicRichTextTableTest >> setUp [ + + super setUp. + + tableBlock := MicTableBlock new. + + header := { 'Header' asText . 'with' asText . '3 columns' asText }. + rowShort := OrderedCollection withAll: { 'Row' asText . 'with 2 columns' asText }. + row3 := { 'Row' asText . 'with' asText . '3 columns' asText }. + +] + +{ #category : 'tests' } +MicRichTextTableTest >> testRowWith2Columns [ + "if one row is shorter (less columns) than the header, add columns to it" + | table | + + table := MicRichTextTable headers: header rows: { rowShort }. + + self assert: table columns size equals: 3. + self assert: table container exposedRows anyOne submorphs size equals: 3 +] + +{ #category : 'tests' } +MicRichTextTableTest >> testRowWith3Columns [ + + | table | + + table := MicRichTextTable headers: header rows: { row3 }. + + self assert: table columns size equals: 3 +] + +{ #category : 'tests' } +MicRichTextTableTest >> testTableHeader [ + + | table | + + table := MicRichTextTable headers: header rows: { row3 }. + + self assert: table columns size equals: 3. + + table columns do: [ :aFTColumn | + self assert: aFTColumn id isNotNil + ] +] + +{ #category : 'tests' } +MicRichTextTableTest >> testTableRows [ + + | table | + + table := MicRichTextTable headers: header rows: { row3 . row3 }. + + self assert: table container exposedRows size equals: 2 +] diff --git a/src/Microdown-RichTextComposer/MicRichTextTable.class.st b/src/Microdown-RichTextComposer/MicRichTextTable.class.st index 1e084bd8..21bb2912 100644 --- a/src/Microdown-RichTextComposer/MicRichTextTable.class.st +++ b/src/Microdown-RichTextComposer/MicRichTextTable.class.st @@ -22,7 +22,10 @@ MicRichTextTable >> addHeaders: headers with: renderedRows [ totalHeight := 0. 1 to: headers size do:[ :colIndex | |header colRows colWidth colHeight| header := headers at: colIndex. - colRows := renderedRows collect: [ :row | row at: colIndex ]. + colRows := renderedRows collect: [ :row | + (row size >= colIndex) + ifFalse: [ row add: '' asText ]. + row at: colIndex ]. colWidth := (header asTextMorph width) max: (colRows collect: [:cell| cell asTextMorph width]) max. totalWidth := totalWidth + colWidth. diff --git a/src/Microdown-RichTextComposer/MicrodownParser.extension.st b/src/Microdown-RichTextComposer/MicrodownParser.extension.st index 40f674c8..ca23a5a9 100644 --- a/src/Microdown-RichTextComposer/MicrodownParser.extension.st +++ b/src/Microdown-RichTextComposer/MicrodownParser.extension.st @@ -1,6 +1,6 @@ Extension { #name : 'MicrodownParser' } { #category : '*Microdown-RichTextComposer' } -MicrodownParser classSide >> convertToRichText: aString [ +MicrodownParser class >> convertToRichText: aString [ ^ MicRichTextComposer new visit: (self new parse: aString) ]