From 2d7eeec25e45b8097276a035cd8b9567a748c3a8 Mon Sep 17 00:00:00 2001 From: anquetil Date: Thu, 2 Jan 2025 12:12:04 +0100 Subject: [PATCH 1/2] Proposing a simple workaround that add empty columns for short rows --- src/Microdown-RichTextComposer/MicRichTextTable.class.st | 5 ++++- src/Microdown-RichTextComposer/MicrodownParser.extension.st | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) 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) ] From fef9aac190da8ee5132b0edeeec6bbd1192b423b Mon Sep 17 00:00:00 2001 From: anquetil Date: Tue, 14 Jan 2025 11:59:02 +0100 Subject: [PATCH 2/2] Added tests on the table generated by MicRichTextTable --- .../MicRichTextTableTest.class.st | 74 +++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 src/Microdown-RichTextComposer-Tests/MicRichTextTableTest.class.st 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 +]