|
12 | 12 | use Djot\Node\Block\ListBlock; |
13 | 13 | use Djot\Node\Block\Paragraph; |
14 | 14 | use Djot\Node\Block\Table; |
| 15 | +use Djot\Node\Block\TableCell; |
| 16 | +use Djot\Node\Block\TableRow; |
15 | 17 | use Djot\Node\Block\ThematicBreak; |
16 | 18 | use Djot\Node\Document; |
17 | 19 | use Djot\Parser\BlockParser; |
@@ -204,6 +206,84 @@ public function testParseTable(): void |
204 | 206 | $this->assertInstanceOf(Table::class, $doc->getChildren()[0]); |
205 | 207 | } |
206 | 208 |
|
| 209 | + public function testParseTableWithEqualsHeaderSyntax(): void |
| 210 | + { |
| 211 | + // Creole-style |= header syntax (no separator row needed) |
| 212 | + $doc = $this->parser->parse("|= Name |= Age |\n| Alice | 28 |"); |
| 213 | + |
| 214 | + $this->assertCount(1, $doc->getChildren()); |
| 215 | + $table = $doc->getChildren()[0]; |
| 216 | + $this->assertInstanceOf(Table::class, $table); |
| 217 | + |
| 218 | + $rows = $table->getChildren(); |
| 219 | + $this->assertCount(2, $rows); |
| 220 | + |
| 221 | + // First row should be a header row |
| 222 | + $headerRow = $rows[0]; |
| 223 | + $this->assertInstanceOf(TableRow::class, $headerRow); |
| 224 | + $this->assertTrue($headerRow->isHeader()); |
| 225 | + |
| 226 | + // Header cells should be marked as headers |
| 227 | + $headerCells = $headerRow->getChildren(); |
| 228 | + $this->assertCount(2, $headerCells); |
| 229 | + $this->assertInstanceOf(TableCell::class, $headerCells[0]); |
| 230 | + $this->assertTrue($headerCells[0]->isHeader()); |
| 231 | + $this->assertTrue($headerCells[1]->isHeader()); |
| 232 | + |
| 233 | + // Second row should be a data row |
| 234 | + $dataRow = $rows[1]; |
| 235 | + $this->assertInstanceOf(TableRow::class, $dataRow); |
| 236 | + $this->assertFalse($dataRow->isHeader()); |
| 237 | + } |
| 238 | + |
| 239 | + public function testParseTableWithEqualsHeaderAlignment(): void |
| 240 | + { |
| 241 | + // |=< left, |=> right, |=~ center |
| 242 | + $doc = $this->parser->parse("|=< Left |=> Right |=~ Center |\n| A | B | C |"); |
| 243 | + |
| 244 | + $table = $doc->getChildren()[0]; |
| 245 | + $this->assertInstanceOf(Table::class, $table); |
| 246 | + |
| 247 | + $headerRow = $table->getChildren()[0]; |
| 248 | + $cells = $headerRow->getChildren(); |
| 249 | + |
| 250 | + $this->assertSame(TableCell::ALIGN_LEFT, $cells[0]->getAlignment()); |
| 251 | + $this->assertSame(TableCell::ALIGN_RIGHT, $cells[1]->getAlignment()); |
| 252 | + $this->assertSame(TableCell::ALIGN_CENTER, $cells[2]->getAlignment()); |
| 253 | + } |
| 254 | + |
| 255 | + public function testParseTableWithMixedHeaderCells(): void |
| 256 | + { |
| 257 | + // Mix of header and regular cells in a row |
| 258 | + $doc = $this->parser->parse("|= Header | Regular |\n| Data | Data |"); |
| 259 | + |
| 260 | + $table = $doc->getChildren()[0]; |
| 261 | + $rows = $table->getChildren(); |
| 262 | + |
| 263 | + // Row with any header cell is marked as header row |
| 264 | + $firstRow = $rows[0]; |
| 265 | + $this->assertTrue($firstRow->isHeader()); |
| 266 | + |
| 267 | + $cells = $firstRow->getChildren(); |
| 268 | + $this->assertTrue($cells[0]->isHeader()); |
| 269 | + $this->assertFalse($cells[1]->isHeader()); |
| 270 | + } |
| 271 | + |
| 272 | + public function testParseTableWithEqualsHeaderNoSeparatorNeeded(): void |
| 273 | + { |
| 274 | + // Unlike traditional tables, |= syntax doesn't need separator row |
| 275 | + $doc = $this->parser->parse("|= A |= B |\n| 1 | 2 |\n| 3 | 4 |"); |
| 276 | + |
| 277 | + $table = $doc->getChildren()[0]; |
| 278 | + $rows = $table->getChildren(); |
| 279 | + |
| 280 | + // Should have 3 rows (1 header + 2 data), no separator consumed |
| 281 | + $this->assertCount(3, $rows); |
| 282 | + $this->assertTrue($rows[0]->isHeader()); |
| 283 | + $this->assertFalse($rows[1]->isHeader()); |
| 284 | + $this->assertFalse($rows[2]->isHeader()); |
| 285 | + } |
| 286 | + |
207 | 287 | public function testParseBlockAttributes(): void |
208 | 288 | { |
209 | 289 | $doc = $this->parser->parse("{.highlight}\n# Heading"); |
|
0 commit comments