protected static function extractSnippetsFromMarkup($markup, $theme)
{
$map = [];
$matches = [];
if (preg_match_all('/\\<figure\\s+[^\\>]+\\>[^\\<]*\\<\\/figure\\>/i', $markup, $matches)) {
foreach ($matches[0] as $snippetDeclaration) {
$nameMatch = [];
if (!preg_match('/data\\-snippet\\s*=\\s*"([^"]+)"/', $snippetDeclaration, $nameMatch)) {
continue;
}
$snippetCode = $nameMatch[1];
$properties = [];
$propertyMatches = [];
if (preg_match_all('/data\\-property-(?<property>[^=]+)\\s*=\\s*\\"(?<value>[^\\"]+)\\"/i', $snippetDeclaration, $propertyMatches)) {
foreach ($propertyMatches['property'] as $index => $propertyName) {
$properties[$propertyName] = $propertyMatches['value'][$index];
}
}
$componentMatch = [];
$componentClass = null;
if (preg_match('/data\\-component\\s*=\\s*"([^"]+)"/', $snippetDeclaration, $componentMatch)) {
$componentClass = $componentMatch[1];
}
// Apply default values for properties not defined in the markup
// and normalize property code names.
$properties = self::preprocessPropertyValues($theme, $snippetCode, $componentClass, $properties);
$map[$snippetDeclaration] = ['code' => $snippetCode, 'component' => $componentClass, 'properties' => $properties];
}
}
return $map;
}