diff --git a/src/View/Parsers/ShortcodeParser.php b/src/View/Parsers/ShortcodeParser.php
index a000f1145..37be5c631 100644
--- a/src/View/Parsers/ShortcodeParser.php
+++ b/src/View/Parsers/ShortcodeParser.php
@@ -726,7 +726,7 @@ class ShortcodeParser
$content = preg_replace_callback(
// Not a general-case parser; assumes that the HTML generated in replaceElementTagsWithMarkers()
// hasn't been heavily modified
- '/]+class="' . preg_quote(self::$marker_class) . '"[^>]+data-tagid="([^"]+)"[^>]+>/i',
+ '/
]+class="' . preg_quote(self::$marker_class) . '"[^>]+data-tagid="([^"]+)"[^>]*>/i',
function ($matches) use ($tags, $parser) {
$tag = $tags[$matches[1]];
return $parser->getShortcodeReplacementText($tag);
diff --git a/tests/php/View/Parsers/ShortcodeParserTest.php b/tests/php/View/Parsers/ShortcodeParserTest.php
index 5abbadb36..614d920b6 100644
--- a/tests/php/View/Parsers/ShortcodeParserTest.php
+++ b/tests/php/View/Parsers/ShortcodeParserTest.php
@@ -328,6 +328,17 @@ class ShortcodeParserTest extends SapphireTest
$stub->parse('
test
'); } + public function testSelfClosingHtmlTags() + { + $this->parser->register('img', function () { + return '