Skip to content

Commit

Permalink
Fix Parser: add prefix for any class name. Add alt for Image tool
Browse files Browse the repository at this point in the history
  • Loading branch information
Edd-G committed Jan 6, 2024
1 parent 31c7187 commit 6ffed95
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions src/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,10 @@ private function addClass($type, $alignment = false, $style = false)
}

if ($style) {
$class[] = $this->prefix.'_'.$style;
$styles = explode(' ', $style);
foreach ($styles as $v) {
$class[] = $this->prefix.'_'.$v;
}
}

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

$attrs = [];

$caption = (!empty($block->data->caption)) ? $block->data->caption : '';

if ($block->data->withBorder) $attrs[] = "withborder";
if ($block->data->withBackground) $attrs[] = "withbackground";
if ($block->data->stretched) $attrs[] = "stretched";
Expand All @@ -340,13 +345,13 @@ private function parseImage($block)
$img = $this->dom->createElement('img');

$img->setAttribute('src', $block->data->url);
$img->setAttribute('alt', '');
$img->setAttribute('alt', $caption);

$figure->appendChild($img);

if (!empty($block->data->caption)) {
if (!empty($caption)) {
$figCaption = $this->dom->createElement('figcaption');
$figCaption->appendChild($this->html5->loadHTMLFragment($block->data->caption));
$figCaption->appendChild($this->html5->loadHTMLFragment($caption));
$figure->appendChild($figCaption);
}

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

$attrs = [];

$caption = (!empty($block->data->caption)) ? $block->data->caption : '';

if ($block->data->withBorder) $attrs[] = "withborder";
if ($block->data->withBackground) $attrs[] = "withbackground";
if ($block->data->stretched) $attrs[] = "stretched";
Expand All @@ -372,13 +379,13 @@ private function parseStandardImage($block)
$img = $this->dom->createElement('img');

$img->setAttribute('src', $block->data->url);
$img->setAttribute('alt', '');
$img->setAttribute('alt', $caption);

$figure->appendChild($img);

if (!empty($block->data->caption)) {
if (!empty($caption)) {
$figCaption = $this->dom->createElement('figcaption');
$figCaption->appendChild($this->html5->loadHTMLFragment($block->data->caption));
$figCaption->appendChild($this->html5->loadHTMLFragment($caption));
$figure->appendChild($figCaption);
}

Expand Down

0 comments on commit 6ffed95

Please sign in to comment.