Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proposing a simple workaround that add empty columns for short rows #927

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 74 additions & 0 deletions src/Microdown-RichTextComposer-Tests/MicRichTextTableTest.class.st
Original file line number Diff line number Diff line change
@@ -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
]
5 changes: 4 additions & 1 deletion src/Microdown-RichTextComposer/MicRichTextTable.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
@@ -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)
]