Skip to content

Commit b7bfaa7

Browse files
author
Mohamed jinas
committed
fixed error while rendering image without caption
1 parent 6a5b89e commit b7bfaa7

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

src/Parser.php

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ private function init()
131131
break;
132132
case 'table':
133133
$this->parseTable($block);
134-
break;
134+
break;
135135
default:
136136
break;
137137
}
@@ -404,13 +404,14 @@ private function parseStandardImage($block)
404404
$img->setAttribute('src', $block->data->file->url);
405405
$img->setAttribute('class', implode(' ', $imgAttrs));
406406

407-
$figCaption = $this->dom->createElement('figcaption');
408-
409-
$figCaption->appendChild($this->html5->loadHTMLFragment($block->data->caption));
410-
411407
$figure->appendChild($img);
412408

413-
$figure->appendChild($figCaption);
409+
if ($block->data->caption) {
410+
411+
$figCaption = $this->dom->createElement('figcaption');
412+
$figCaption->appendChild($this->html5->loadHTMLFragment($block->data->caption));
413+
$figure->appendChild($figCaption);
414+
}
414415

415416
$this->dom->appendChild($figure);
416417
}
@@ -439,33 +440,33 @@ private function parseTable($block)
439440
{
440441
$table = $this->dom->createElement('table');
441442
$table->setAttribute('class', "{$this->prefix}-table");
442-
443+
443444
$tr_top = $this->dom->createElement('tr');
444445
$thead = $this->dom->createElement('thead');
445446
$tbody = $this->dom->createElement('tbody');
446447
$thead->appendChild($tr_top);
447448
$table->appendChild($thead);
448449
$table->appendChild($tbody);
449450

450-
451451

452-
foreach($block->data->content[0] as $head){
452+
453+
foreach ($block->data->content[0] as $head) {
453454
$th = $this->dom->createElement('th', $head);
454455
$tr_top->appendChild($th);
455456
}
456457

457458
$dataset = $block->data->content;
458459
unset($dataset[0]);
459460

460-
foreach($dataset as $data) {
461+
foreach ($dataset as $data) {
461462
$tr = $this->dom->createElement('tr');
462-
foreach($data as $item){
463+
foreach ($data as $item) {
463464
$td = $this->dom->createElement('td', $item);
464465
$tr->appendChild($td);
465466
}
466467
$tbody->appendChild($tr);
467468
}
468-
469+
469470

470471
$this->dom->appendChild($table);
471472
}

0 commit comments

Comments
 (0)