Skip to content

Commit

Permalink
Trim whitespace between dynamically rendered field html elements.
Browse files Browse the repository at this point in the history
  • Loading branch information
jesseleite committed Dec 21, 2021
1 parent 3360583 commit 9ba5e2d
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/Tags/Concerns/RendersForms.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ protected function getRenderableField($field, $errorBag = 'default', $alpine = f
$data['alpine_data_key'] = $this->getAlpineXDataKey($data['handle'], $alpine);
}

$data['field'] = view($field->fieldtype()->view(), $data);
$data['field'] = $this->minifyFieldHtml(view($field->fieldtype()->view(), $data)->render());

return $data;
}
Expand Down Expand Up @@ -128,4 +128,18 @@ protected function getAlpineXDataKey($fieldHandle, $alpineScope)
? "{$alpineScope}.{$fieldHandle}"
: $fieldHandle;
}

/**
* Minify field html.
*
* @param string $html
* @return string
*/
protected function minifyFieldHtml($html)
{
// Trim whitespace between elements.
$html = preg_replace('/>\s*([^<>]*)\s*</', '>$1<', $html);

return $html;
}
}

0 comments on commit 9ba5e2d

Please sign in to comment.