Skip to content

Commit 6ffed95

Browse files
committed
Fix Parser: add prefix for any class name. Add alt for Image tool
1 parent 31c7187 commit 6ffed95

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

src/Parser.php

+14-7
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,10 @@ private function addClass($type, $alignment = false, $style = false)
122122
}
123123

124124
if ($style) {
125-
$class[] = $this->prefix.'_'.$style;
125+
$styles = explode(' ', $style);
126+
foreach ($styles as $v) {
127+
$class[] = $this->prefix.'_'.$v;
128+
}
126129
}
127130

128131
return implode(' ', $class);
@@ -327,6 +330,8 @@ private function parseImage($block)
327330

328331
$attrs = [];
329332

333+
$caption = (!empty($block->data->caption)) ? $block->data->caption : '';
334+
330335
if ($block->data->withBorder) $attrs[] = "withborder";
331336
if ($block->data->withBackground) $attrs[] = "withbackground";
332337
if ($block->data->stretched) $attrs[] = "stretched";
@@ -340,13 +345,13 @@ private function parseImage($block)
340345
$img = $this->dom->createElement('img');
341346

342347
$img->setAttribute('src', $block->data->url);
343-
$img->setAttribute('alt', '');
348+
$img->setAttribute('alt', $caption);
344349

345350
$figure->appendChild($img);
346351

347-
if (!empty($block->data->caption)) {
352+
if (!empty($caption)) {
348353
$figCaption = $this->dom->createElement('figcaption');
349-
$figCaption->appendChild($this->html5->loadHTMLFragment($block->data->caption));
354+
$figCaption->appendChild($this->html5->loadHTMLFragment($caption));
350355
$figure->appendChild($figCaption);
351356
}
352357

@@ -359,6 +364,8 @@ private function parseStandardImage($block)
359364

360365
$attrs = [];
361366

367+
$caption = (!empty($block->data->caption)) ? $block->data->caption : '';
368+
362369
if ($block->data->withBorder) $attrs[] = "withborder";
363370
if ($block->data->withBackground) $attrs[] = "withbackground";
364371
if ($block->data->stretched) $attrs[] = "stretched";
@@ -372,13 +379,13 @@ private function parseStandardImage($block)
372379
$img = $this->dom->createElement('img');
373380

374381
$img->setAttribute('src', $block->data->url);
375-
$img->setAttribute('alt', '');
382+
$img->setAttribute('alt', $caption);
376383

377384
$figure->appendChild($img);
378385

379-
if (!empty($block->data->caption)) {
386+
if (!empty($caption)) {
380387
$figCaption = $this->dom->createElement('figcaption');
381-
$figCaption->appendChild($this->html5->loadHTMLFragment($block->data->caption));
388+
$figCaption->appendChild($this->html5->loadHTMLFragment($caption));
382389
$figure->appendChild($figCaption);
383390
}
384391

0 commit comments

Comments
 (0)